Skip to content

Commit

Permalink
Added validation for the number of characters in the name of the rece…
Browse files Browse the repository at this point in the history
…ipt (#13294)

* Added validation for the number of characters in the name of the receipt
  • Loading branch information
JamalAlabdullah authored Aug 16, 2024
1 parent eece61b commit 094f359
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@
"process_editor.configuration_panel_custom_receipt_heading": "Opprett din egen kvittering",
"process_editor.configuration_panel_custom_receipt_info": "Hvis du heller vil lage din egen kvittering, kan du opprette den her. Kvitteringen du lager selv vil overstyre standardkvitteringen.",
"process_editor.configuration_panel_custom_receipt_layout_set_name": "Navn på sidegruppe: ",
"process_editor.configuration_panel_custom_receipt_layout_set_name_validation": "Navnet må ha minst 2 tegn",
"process_editor.configuration_panel_custom_receipt_navigate_to_lage_button": "Gå til Lage",
"process_editor.configuration_panel_custom_receipt_navigate_to_lage_title": "Gå til Lage for å utforme kvitteringen din",
"process_editor.configuration_panel_custom_receipt_select_data_model_label": "Datamodellknytning",
Expand Down
19 changes: 18 additions & 1 deletion frontend/packages/shared/src/utils/layoutSetsUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { getLayoutSetNameForCustomReceipt } from 'app-shared/utils/layoutSetsUtils';
import {
getLayoutSetIdValidationErrorKey,
getLayoutSetNameForCustomReceipt,
} from 'app-shared/utils/layoutSetsUtils';
import type { LayoutSets } from 'app-shared/types/api/LayoutSetsResponse';

// Test data
Expand Down Expand Up @@ -44,6 +47,20 @@ describe('getLayoutSetNameForCustomReceipt', () => {
expect(getLayoutSetNameForCustomReceipt(layoutSetsWithEmptySets)).toBeUndefined();
});

it('should return error message when the user types just one character', () => {
const newLayoutSetId = 'a';
expect(getLayoutSetIdValidationErrorKey({ sets: [] }, layoutSetName, newLayoutSetId)).toBe(
'process_editor.configuration_panel_custom_receipt_layout_set_name_validation',
);
});

it('should return error message when the user types whitespace', () => {
const newLayoutSetId = ' ';
expect(getLayoutSetIdValidationErrorKey({ sets: [] }, layoutSetName, newLayoutSetId)).toBe(
'validation_errors.required',
);
});

it('should return undefined if layoutSets has a set with no task ids', () => {
const layoutSetsWithUndefinedTasks: LayoutSets = {
sets: [
Expand Down
4 changes: 3 additions & 1 deletion frontend/packages/shared/src/utils/layoutSetsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export const getLayoutSetIdValidationErrorKey = (
newLayoutSetId: string,
): string => {
if (oldLayoutSetId === newLayoutSetId) return null;
if (!newLayoutSetId || newLayoutSetId.trim() === '') return 'validation_errors.required';
if (!validateLayoutNameAndLayoutSetName(newLayoutSetId)) return 'ux_editor.pages_error_format';
if (!newLayoutSetId) return 'validation_errors.required';
if (newLayoutSetId.length === 1)
return 'process_editor.configuration_panel_custom_receipt_layout_set_name_validation';
if (layoutSets.sets.some((set) => set.id === newLayoutSetId))
return 'process_editor.configuration_panel_layout_set_id_not_unique';
return null;
Expand Down

0 comments on commit 094f359

Please sign in to comment.