Skip to content

Commit

Permalink
TASK: Jest tests by faking new translate() method correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mhsdesign committed Jan 27, 2025
1 parent 0686a81 commit 82553f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 5 additions & 0 deletions packages/neos-ui-editors/src/Editors/SelectBox/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import TestBackend from 'react-dnd-test-backend';
import {DndProvider as DragDropContextProvider} from 'react-dnd';
import SelectBoxEditor from './index.js';
import {WrapWithMockGlobalRegistry, MockDataSourceDataLoader} from '../../_lib/testUtils';
import {setupI18n} from "@neos-project/neos-ui-i18n";

const optionValues = {
foo: {
Expand Down Expand Up @@ -41,6 +42,10 @@ const multiselectLabels = component =>

const commit = () => {};

beforeAll(() => {
setupI18n('en-US', 'one,other', {});
});

test(`SelectBox > single, no dataSource, no preselected value`, () => {
const expectedDropdownElementLabels = ['fooLabel', 'barLabel'];
const component = mount(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import {processSelectBoxOptions} from './selectBoxHelpers';
import {I18nRegistry} from '@neos-project/neos-ts-interfaces';
import {setupI18n} from "@neos-project/neos-ui-i18n";

const fakeI18NRegistry = {
translate: (id) => id ?? ''
} as I18nRegistry;

beforeAll(() => {
setupI18n('en-US', 'one,other', {});
});

describe('processSelectBoxOptions', () => {
it('transforms an associative array with labels to list of objects', () => {
const processOptions = processSelectBoxOptions(fakeI18NRegistry, {
Expand Down Expand Up @@ -78,15 +83,15 @@ describe('processSelectBoxOptions', () => {
'key1': {label: 'Key 1'}
}, 'oldValue');

expect(processOptions).toEqual([{value: 'key1', label: 'Key 1'}, {value: 'oldValue', label: 'Neos.Neos.Ui:Main:invalidValue: "oldValue"', icon: 'exclamation-triangle'}]);
expect(processOptions).toEqual([{value: 'key1', label: 'Key 1'}, {value: 'oldValue', label: 'Invalid value: "oldValue"', icon: 'exclamation-triangle'}]);
});

it('creates missing options for unmatched additional array value', () => {
const processOptions = processSelectBoxOptions(fakeI18NRegistry, {
'key1': {label: 'Key 1'}
}, ['oldValue', 'key1']);

expect(processOptions).toEqual([{value: 'key1', label: 'Key 1'}, {value: 'oldValue', label: 'Neos.Neos.Ui:Main:invalidValue: "oldValue"', icon: 'exclamation-triangle'}]);
expect(processOptions).toEqual([{value: 'key1', label: 'Key 1'}, {value: 'oldValue', label: 'Invalid value: "oldValue"', icon: 'exclamation-triangle'}]);
});

it('creates missing options for unmatched additional multiple array values', () => {
Expand All @@ -100,8 +105,8 @@ describe('processSelectBoxOptions', () => {
{value: 'key1', label: 'Key 1'},
{value: 'key2', label: 'Key 2'},
{value: 'key3', label: 'Key 3'},
{value: 'oldValue', label: 'Neos.Neos.Ui:Main:invalidValue: "oldValue"', icon: 'exclamation-triangle'},
{value: 'oldValue2', label: 'Neos.Neos.Ui:Main:invalidValue: "oldValue2"', icon: 'exclamation-triangle'}
{value: 'oldValue', label: 'Invalid value: "oldValue"', icon: 'exclamation-triangle'},
{value: 'oldValue2', label: 'Invalid value: "oldValue2"', icon: 'exclamation-triangle'}
]);
});

Expand Down

0 comments on commit 82553f1

Please sign in to comment.