Skip to content

Commit

Permalink
Merge branch 'main' into restructure-top-of-mainconfig-when-subform
Browse files Browse the repository at this point in the history
  • Loading branch information
lassopicasso committed Feb 26, 2025
2 parents ad03373 + e36cb79 commit c18577f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -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('');
Expand All @@ -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<HTMLInputElement>((ref) => renderTextResourcePicker({}, ref), getCombobox);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLInputElement, StudioTextResourcePickerProps>(
({ 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],
Expand All @@ -31,7 +45,8 @@ export const StudioTextResourcePicker = forwardRef<HTMLInputElement, StudioTextR
{...rest}
ref={ref}
>
{renderNoTextResourceOption(noTextResourceOptionLabel)}
<StudioCombobox.Empty>{emptyLabel}</StudioCombobox.Empty>
{!required && renderNoTextResourceOption(noTextResourceOptionLabel)}
{renderTextResourceOptions(textResources)}
</StudioCombobox>
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/testing/cypress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 20 additions & 11 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -8530,7 +8530,7 @@ __metadata:
yauzl: "npm:^2.10.0"
bin:
cypress: bin/cypress
checksum: 10/6c548e2adf7ae127365570680aa32015dbeb94cad30ce4f8a92e2e58d8ef7033b7f0ece50579a0a13eb07061feede0c813ff8d1e50e0feb87520dece5be4ba95
checksum: 10/a3ce943f21dd3e3a0a138dbb6789ed1228c8fe81ad8c98d37c362414c37b64d2ab3de23cc31e1c4cc52fbfd1f941a481ece6d157c2736798a428a309778aeded
languageName: node
linkType: hard

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit c18577f

Please sign in to comment.