Skip to content

Commit

Permalink
fix: remove current code list name from list before passing to findFi…
Browse files Browse the repository at this point in the history
…leNameError (#14310)

Co-authored-by: Tomas Engebretsen <[email protected]>
  • Loading branch information
standeren and TomasEng authored Dec 20, 2024
1 parent a578aab commit d3590da
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ describe('CodeLists', () => {
expect(errorMessage).toBeInTheDocument();
});

it('does not show error message when reassigning the original name ', async () => {
const user = userEvent.setup();
renderCodeLists({ codeListNames: [codeListName] });
await changeCodeListId(user, codeListName, codeListName);
const errorMessage = screen.queryByText(textMock('validation_errors.file_name_occupied'));
expect(errorMessage).not.toBeInTheDocument();
});

it('does not call onUpdateCodeListId when assigning an invalid id to the code list', async () => {
const user = userEvent.setup();
const invalidCodeListName = 'invalidCodeListName';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { CodeListWithMetadata } from '../../CodeListPage';
import { useOptionListEditorTexts } from '../../hooks/useCodeListEditorTexts';
import { KeyVerticalIcon } from '@studio/icons';
import { updateCodeListWithMetadata } from '../CodeLists';
import { FileNameUtils } from '@studio/pure-functions';
import { ArrayUtils, FileNameUtils } from '@studio/pure-functions';
import { useInputCodeListNameErrorMessage } from '../../hooks/useInputCodeListNameErrorMessage';
import classes from './EditCodeList.module.css';

Expand Down Expand Up @@ -37,7 +37,8 @@ export function EditCodeList({
};

const handleValidateCodeListId = (newCodeListId: string) => {
const fileNameError = FileNameUtils.findFileNameError(newCodeListId, codeListNames);
const invalidCodeListNames = ArrayUtils.removeItemByValue(codeListNames, codeList.title);
const fileNameError = FileNameUtils.findFileNameError(newCodeListId, invalidCodeListNames);
return getInvalidInputFileNameErrorMessage(fileNameError);
};

Expand Down

0 comments on commit d3590da

Please sign in to comment.