-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Account for invalid text resource ids in code list editor (#14797)
Co-authored-by: William Thorenfeldt <[email protected]>
- Loading branch information
Showing
4 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { textResourcesMock } from '../../test-data/textResourcesMock'; | ||
import { retrieveSelectedValues } from './utils'; | ||
|
||
describe('utils', () => { | ||
describe('retrieveSelectedValues', () => { | ||
it('Returns an array with the value when the text resource exists', () => { | ||
const textResources = textResourcesMock; | ||
const arbitraryTextResourceIndex = 129; | ||
const textResource = textResources[arbitraryTextResourceIndex]; | ||
expect(retrieveSelectedValues(textResources, textResource.id)).toEqual([textResource.id]); | ||
}); | ||
|
||
it('Returns an empty array when the text resource does not exist', () => { | ||
const textResources = textResourcesMock; | ||
const idThatDoesNotExist = 'does-not-exist'; | ||
expect(retrieveSelectedValues(textResources, idThatDoesNotExist)).toEqual([]); | ||
}); | ||
|
||
it.each([null, undefined])('Returns an empty array when the value is %s', (value) => { | ||
expect(retrieveSelectedValues(textResourcesMock, value)).toEqual([]); | ||
}); | ||
}); | ||
}); |
9 changes: 9 additions & 0 deletions
9
frontend/libs/studio-components/src/components/StudioTextResourcePicker/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { TextResource } from '../../types/TextResource'; | ||
|
||
export function retrieveSelectedValues(textResources: TextResource[], id?: string): string[] { | ||
return doesTextResourceExist(textResources, id) ? [id] : []; | ||
} | ||
|
||
function doesTextResourceExist(textResources: TextResource[], id?: string): boolean { | ||
return textResources.some((textResource) => textResource.id === id); | ||
} |