-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove duplicate react-i18next mocks
- Loading branch information
Showing
8 changed files
with
64 additions
and
136 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
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
34 changes: 13 additions & 21 deletions
34
frontend/packages/ux-editor-v3/src/hooks/useComponentTypeName.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 |
---|---|---|
@@ -1,34 +1,26 @@ | ||
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs'; | ||
import { ComponentTypeV3 } from 'app-shared/types/ComponentTypeV3'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useComponentTypeName } from './useComponentTypeName'; | ||
|
||
// Test data: | ||
const inputText = 'input'; | ||
const paragraphText = 'paragraph'; | ||
const texts: KeyValuePairs<string> = { | ||
[`ux_editor.component_title.${ComponentTypeV3.Input}`]: inputText, | ||
[`ux_editor.component_title.${ComponentTypeV3.Paragraph}`]: paragraphText, | ||
}; | ||
|
||
// Mocks: | ||
jest.mock('react-i18next', () => ({ | ||
...jest.requireActual('react-i18next'), | ||
useTranslation: () => ({ | ||
t: (key: string) => texts?.[key] ?? key, | ||
}), | ||
})); | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
|
||
describe('useComponentTypeName', () => { | ||
const { result } = renderHook(useComponentTypeName); | ||
|
||
it('Returns the correct text if it exists', () => { | ||
expect(result.current(ComponentTypeV3.Input)).toBe(inputText); | ||
expect(result.current(ComponentTypeV3.Paragraph)).toBe(paragraphText); | ||
expect(result.current(ComponentTypeV3.Input)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentTypeV3.Input}`), | ||
); | ||
expect(result.current(ComponentTypeV3.Paragraph)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentTypeV3.Paragraph}`), | ||
); | ||
}); | ||
|
||
it('Returns the component type if the text does not exist', () => { | ||
expect(result.current(ComponentTypeV3.Header)).toBe(ComponentTypeV3.Header); | ||
expect(result.current(ComponentTypeV3.Checkboxes)).toBe(ComponentTypeV3.Checkboxes); | ||
expect(result.current(ComponentTypeV3.Header)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentTypeV3.Header}`), | ||
); | ||
expect(result.current(ComponentTypeV3.Checkboxes)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentTypeV3.Checkboxes}`), | ||
); | ||
}); | ||
}); |
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
34 changes: 13 additions & 21 deletions
34
frontend/packages/ux-editor/src/hooks/useComponentTypeName.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 |
---|---|---|
@@ -1,34 +1,26 @@ | ||
import type { KeyValuePairs } from 'app-shared/types/KeyValuePairs'; | ||
import { ComponentType } from 'app-shared/types/ComponentType'; | ||
import { renderHook } from '@testing-library/react'; | ||
import { useComponentTypeName } from './useComponentTypeName'; | ||
|
||
// Test data: | ||
const inputText = 'input'; | ||
const paragraphText = 'paragraph'; | ||
const texts: KeyValuePairs<string> = { | ||
[`ux_editor.component_title.${ComponentType.Input}`]: inputText, | ||
[`ux_editor.component_title.${ComponentType.Paragraph}`]: paragraphText, | ||
}; | ||
|
||
// Mocks: | ||
jest.mock('react-i18next', () => ({ | ||
...jest.requireActual('react-i18next'), | ||
useTranslation: () => ({ | ||
t: (key: string) => texts?.[key] ?? key, | ||
}), | ||
})); | ||
import { textMock } from '@studio/testing/mocks/i18nMock'; | ||
|
||
describe('useComponentTypeName', () => { | ||
const { result } = renderHook(useComponentTypeName); | ||
|
||
it('Returns the correct text if it exists', () => { | ||
expect(result.current(ComponentType.Input)).toBe(inputText); | ||
expect(result.current(ComponentType.Paragraph)).toBe(paragraphText); | ||
expect(result.current(ComponentType.Input)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentType.Input}`), | ||
); | ||
expect(result.current(ComponentType.Paragraph)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentType.Paragraph}`), | ||
); | ||
}); | ||
|
||
it('Returns the component type if the text does not exist', () => { | ||
expect(result.current(ComponentType.Header)).toBe(ComponentType.Header); | ||
expect(result.current(ComponentType.Checkboxes)).toBe(ComponentType.Checkboxes); | ||
expect(result.current(ComponentType.Header)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentType.Header}`), | ||
); | ||
expect(result.current(ComponentType.Checkboxes)).toBe( | ||
textMock(`ux_editor.component_title.${ComponentType.Checkboxes}`), | ||
); | ||
}); | ||
}); |
Oops, something went wrong.