From 6f0ec19512b9e4fff10491b9f8fa76514ea27879 Mon Sep 17 00:00:00 2001 From: Tomas Engebretsen Date: Wed, 26 Feb 2025 07:41:24 +0100 Subject: [PATCH 1/2] feat: Add required prop to text resource picker (#14803) --- .../StudioTextResourcePicker.stories.tsx | 11 ++++++++++ .../StudioTextResourcePicker.test.tsx | 13 ++++++++++++ .../StudioTextResourcePicker.tsx | 21 ++++++++++++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx index 8dbbec68fac..4adf77a0762 100644 --- a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx +++ b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.stories.tsx @@ -12,10 +12,21 @@ export default meta; export const Preview: Story = { args: { + emptyLabel: 'Ingen mulige alternativer', label: 'Velg tekst', textResources: textResourcesMock, onValueChange: (id: string) => console.log(id), noTextResourceOptionLabel: 'Ikke oppgitt', + required: false, value: 'land.NO', }, }; + +export const Empty: Story = { + args: { + ...Preview.args, + value: undefined, + required: true, + textResources: [], + }, +}; diff --git a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx index 6afe8d07541..1175588b16e 100644 --- a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx +++ b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.test.tsx @@ -74,6 +74,14 @@ describe('StudioTextResourcePicker', () => { expect(screen.getByRole('option', { name: noTextResourceOptionLabel })).toBeInTheDocument(); }); + it('Does not display the no text resource option when the user clicks and the text resource is required', async () => { + const user = userEvent.setup(); + renderTextResourcePicker({ required: true }); + await user.click(getCombobox()); + const noTextResourceOption = screen.queryByRole('option', { name: noTextResourceOptionLabel }); + expect(noTextResourceOption).not.toBeInTheDocument(); + }); + it('Renders with the no text resource option selected by default', () => { renderTextResourcePicker(); expect(getCombobox()).toHaveValue(''); @@ -100,6 +108,11 @@ describe('StudioTextResourcePicker', () => { expect(combobox).toHaveValue(newExpectedValue); }); + it('Renders without error when the text props are undefined', () => { + renderTextResourcePicker({ emptyLabel: undefined, noTextResourceOptionLabel: undefined }); + expect(getCombobox()).toBeInTheDocument(); + }); + it('Forwards the ref', () => { testRefForwarding((ref) => renderTextResourcePicker({}, ref), getCombobox); }); diff --git a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx index 3629fe9669b..95c08e2e3ab 100644 --- a/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx +++ b/frontend/libs/studio-components/src/components/StudioTextResourcePicker/StudioTextResourcePicker.tsx @@ -8,16 +8,30 @@ import classes from './StudioTextResourcePicker.module.css'; export type StudioTextResourcePickerProps = Override< { + emptyLabel?: string; + noTextResourceOptionLabel?: string; onValueChange: (id: string | null) => void; + required?: boolean; textResources: TextResource[]; - noTextResourceOptionLabel: string; value?: string; }, StudioComboboxProps >; export const StudioTextResourcePicker = forwardRef( - ({ textResources, onSelect, onValueChange, noTextResourceOptionLabel, value, ...rest }, ref) => { + ( + { + emptyLabel = '', + noTextResourceOptionLabel = '', + onSelect, + onValueChange, + required, + textResources, + value, + ...rest + }, + ref, + ) => { const handleValueChange = useCallback( ([id]: string[]) => onValueChange(id || null), [onValueChange], @@ -31,7 +45,8 @@ export const StudioTextResourcePicker = forwardRef - {renderNoTextResourceOption(noTextResourceOptionLabel)} + {emptyLabel} + {!required && renderNoTextResourceOption(noTextResourceOptionLabel)} {renderTextResourceOptions(textResources)} ); From e36cb7993991b45d5ac2b98cb5b339959ee249dc Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 08:56:14 +0100 Subject: [PATCH 2/2] chore(deps): update dependency cypress to v14 (#14676) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- frontend/testing/cypress/package.json | 2 +- yarn.lock | 31 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/frontend/testing/cypress/package.json b/frontend/testing/cypress/package.json index ccdec326fc9..2b197b4e362 100644 --- a/frontend/testing/cypress/package.json +++ b/frontend/testing/cypress/package.json @@ -5,7 +5,7 @@ "devDependencies": { "@testing-library/cypress": "10.0.3", "axe-core": "4.10.2", - "cypress": "13.17.0", + "cypress": "14.0.3", "cypress-axe": "1.6.0", "cypress-plugin-tab": "1.0.5", "eslint": "8.57.1" diff --git a/yarn.lock b/yarn.lock index 5fe59a85666..aa16c208886 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1993,9 +1993,9 @@ __metadata: languageName: node linkType: hard -"@cypress/request@npm:^3.0.6": - version: 3.0.6 - resolution: "@cypress/request@npm:3.0.6" +"@cypress/request@npm:^3.0.7": + version: 3.0.7 + resolution: "@cypress/request@npm:3.0.7" dependencies: aws-sign2: "npm:~0.7.0" aws4: "npm:^1.8.0" @@ -2010,12 +2010,12 @@ __metadata: json-stringify-safe: "npm:~5.0.1" mime-types: "npm:~2.1.19" performance-now: "npm:^2.1.0" - qs: "npm:6.13.0" + qs: "npm:6.13.1" safe-buffer: "npm:^5.1.2" tough-cookie: "npm:^5.0.0" tunnel-agent: "npm:^0.6.0" uuid: "npm:^8.3.2" - checksum: 10/ac1782111d93e0dbee2d2b2f35d9acf6821ef36eef9f4c3991e5903138fe2b8394a207c8c6e50a2b6cb2057e0ee5ebfc37cb7571c460c9685e80c948c25f6972 + checksum: 10/fdd674caaa0942c8bb9bc90d862932dfccae6a7d63bacb13850b11668274c382356f5649d9264948015727b2362012b3c0c5105a67e107196d8b8c3b3d673fec languageName: node linkType: hard @@ -8474,18 +8474,18 @@ __metadata: dependencies: "@testing-library/cypress": "npm:10.0.3" axe-core: "npm:4.10.2" - cypress: "npm:13.17.0" + cypress: "npm:14.0.3" cypress-axe: "npm:1.6.0" cypress-plugin-tab: "npm:1.0.5" eslint: "npm:8.57.1" languageName: unknown linkType: soft -"cypress@npm:13.17.0": - version: 13.17.0 - resolution: "cypress@npm:13.17.0" +"cypress@npm:14.0.3": + version: 14.0.3 + resolution: "cypress@npm:14.0.3" dependencies: - "@cypress/request": "npm:^3.0.6" + "@cypress/request": "npm:^3.0.7" "@cypress/xvfb": "npm:^1.2.4" "@types/sinonjs__fake-timers": "npm:8.1.1" "@types/sizzle": "npm:^2.3.2" @@ -8530,7 +8530,7 @@ __metadata: yauzl: "npm:^2.10.0" bin: cypress: bin/cypress - checksum: 10/6c548e2adf7ae127365570680aa32015dbeb94cad30ce4f8a92e2e58d8ef7033b7f0ece50579a0a13eb07061feede0c813ff8d1e50e0feb87520dece5be4ba95 + checksum: 10/a3ce943f21dd3e3a0a138dbb6789ed1228c8fe81ad8c98d37c362414c37b64d2ab3de23cc31e1c4cc52fbfd1f941a481ece6d157c2736798a428a309778aeded languageName: node linkType: hard @@ -15973,6 +15973,15 @@ __metadata: languageName: node linkType: hard +"qs@npm:6.13.1": + version: 6.13.1 + resolution: "qs@npm:6.13.1" + dependencies: + side-channel: "npm:^1.0.6" + checksum: 10/53cf5fdc5f342a9ffd3968f20c8c61624924cf928d86fff525240620faba8ca5cfd6c3f12718cc755561bfc3dc9721bc8924e38f53d8925b03940f0b8a902212 + languageName: node + linkType: hard + "qs@npm:6.14.0": version: 6.14.0 resolution: "qs@npm:6.14.0"