Skip to content

Commit

Permalink
fix: 14472 should show the value of selector in properties config (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
JamalAlabdullah authored Feb 20, 2025
1 parent 41c86ad commit 0df8045
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 155 deletions.
2 changes: 1 addition & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -1456,7 +1456,7 @@
"ux_editor.component_properties.showIcon": "Vis ikon",
"ux_editor.component_properties.showLabelsInTable": "Alternativene skal alltid vises i tabeller",
"ux_editor.component_properties.showPageInAccordion": "Vis side i trekkspilliste",
"ux_editor.component_properties.showValidations": "Vis valideringstyper",
"ux_editor.component_properties.showValidations": "Valideringstyper",
"ux_editor.component_properties.simplified": "Forenklet visning",
"ux_editor.component_properties.size": "Størrelse",
"ux_editor.component_properties.sortOrder": "Sorteringsrekkefølge",
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

.gridButton {
padding: 0;
margin-bottom: var(--fds-spacing-0);
}

.gridHeader {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { componentMocks } from '../../testing/componentMocks';
import InputSchema from '../../testing/schemas/json/component/Input.schema.v1.json';
import DatepickerSchema from '../../testing/schemas/json/component/Datepicker.schema.v1.json';
import type { ServicesContextProps } from 'app-shared/contexts/ServicesContext';
import { screen } from '@testing-library/react';
import { screen, waitFor } from '@testing-library/react';
import { textMock } from '@studio/testing/mocks/i18nMock';
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs';
import userEvent from '@testing-library/user-event';
Expand Down Expand Up @@ -160,7 +160,7 @@ describe('FormComponentConfig', () => {
expect(screen.queryByText('unsupportedProperty')).not.toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for the "sortOrder" property', async () => {
it('should render property text for the "sortOrder" property', async () => {
const user = userEvent.setup();
render({
props: {
Expand All @@ -187,7 +187,7 @@ describe('FormComponentConfig', () => {
).toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for the "showValidations" property and EditStringValue for other properties', () => {
it('should render property text for the "showValidations" property', () => {
render({
props: {
schema: {
Expand Down Expand Up @@ -217,7 +217,7 @@ describe('FormComponentConfig', () => {
).toBeInTheDocument();
});

it('should render CollapsiblePropertyEditor for "preselectedOptionIndex" and EditNumberValue for other properties', () => {
it('should render property text for "preselectedOptionIndex" and EditNumberValue for other properties', () => {
render({
props: {
schema: {
Expand Down Expand Up @@ -281,15 +281,56 @@ describe('FormComponentConfig', () => {
).not.toBeInTheDocument();
});

it('should show description text for objects if key is defined', () => {
render({
props: {
schema: InputSchema,
},
it('should call handleComponentUpdate and setSelectedValue when array property is updated', async () => {
const user = userEvent.setup();
const handleComponentUpdateMock = jest.fn();
const propertyKey = 'supportedArrayProperty';
renderWithProviders(
<FormComponentConfig
schema={{
properties: {
[propertyKey]: {
type: 'array',
items: {
type: 'string',
enum: ['option1', 'option2'],
},
},
},
}}
editFormId=''
component={componentMocks.Input}
handleComponentUpdate={handleComponentUpdateMock}
hideUnsupported={false}
/>,
);
const arrayPropertyButton = screen.getByRole('button', {
name: textMock(`ux_editor.component_properties.${propertyKey}`),
});
expect(
screen.getByText(textMock('ux_editor.component_properties_description.pageBreak')),
).toBeInTheDocument();
await user.click(arrayPropertyButton);

const combobox = screen.getByRole('combobox', {
name: textMock(`ux_editor.component_properties.${propertyKey}`),
});
await user.click(combobox);

const option1 = screen.getByRole('option', {
name: textMock('ux_editor.component_properties.enum_option1'),
});
await user.click(option1);

await waitFor(() => {
expect(handleComponentUpdateMock).toHaveBeenCalledWith(
expect.objectContaining({
[propertyKey]: ['option1'],
}),
);
});

const selectedValueDisplay = screen.getByRole('option', {
name: textMock('ux_editor.component_properties.enum_option1'),
});
expect(selectedValueDisplay).toBeInTheDocument();
});

it('should render default boolean values if defined', async () => {
Expand Down Expand Up @@ -442,6 +483,40 @@ describe('FormComponentConfig', () => {
);
});

it('should render array properties with enum values correctly', async () => {
const user = userEvent.setup();
const propertyKey = 'supportedArrayProperty';
const enumValues = ['option1', 'option2'];
render({
props: {
schema: {
properties: {
[propertyKey]: {
type: 'array',
items: {
type: 'string',
enum: enumValues,
},
},
},
},
component: {
...componentMocks.Input,
[propertyKey]: enumValues,
},
},
});
const arrayPropertyButton = screen.getByRole('button', {
name: textMock(`ux_editor.component_properties.${propertyKey}`),
});
await user.click(arrayPropertyButton);
for (const dataType of enumValues) {
expect(
screen.getByText(textMock(`ux_editor.component_properties.enum_${dataType}`)),
).toBeInTheDocument();
}
});

it('should call handleComponentUpdate with updated component when hasCustomFileEndings is true', async () => {
const handleComponentUpdateMock = jest.fn();
render({
Expand Down
Loading

0 comments on commit 0df8045

Please sign in to comment.