diff --git a/frontend/language/src/nb.json b/frontend/language/src/nb.json index 9c4615a9deb..0c33415b101 100644 --- a/frontend/language/src/nb.json +++ b/frontend/language/src/nb.json @@ -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", diff --git a/frontend/packages/shared/src/utils/layoutSetsUtils.test.ts b/frontend/packages/shared/src/utils/layoutSetsUtils.test.ts index 4dd9a2d1bb8..770bc9acf62 100644 --- a/frontend/packages/shared/src/utils/layoutSetsUtils.test.ts +++ b/frontend/packages/shared/src/utils/layoutSetsUtils.test.ts @@ -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 @@ -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: [ diff --git a/frontend/packages/shared/src/utils/layoutSetsUtils.ts b/frontend/packages/shared/src/utils/layoutSetsUtils.ts index eece4a95710..e29d5a28f4f 100644 --- a/frontend/packages/shared/src/utils/layoutSetsUtils.ts +++ b/frontend/packages/shared/src/utils/layoutSetsUtils.ts @@ -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;