Skip to content

Commit

Permalink
fixup! Split RUIProvider into two
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohal committed Dec 20, 2024
1 parent ff97cc3 commit 2b0daaa
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/providers/translations/TranslationsProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ const TranslationsProvider = ({
children,
translations,
}) => {
const context = useContext(TranslationsContext);
const contextTranslations = useContext(TranslationsContext);

return (
<TranslationsContext.Provider
value={mergeDeep(context?.translations, translations)}
value={mergeDeep(contextTranslations, translations)}
>
{children}
</TranslationsContext.Provider>
Expand Down
48 changes: 34 additions & 14 deletions src/providers/translations/__tests__/TranslationsProvider.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,47 @@ import {
within,
} from '@testing-library/react';
import { Alert } from '../../../components/Alert';
import { ScrollView } from '../../../components/ScrollView';
import TranslationsProvider from '../TranslationsProvider';

describe('rendering', () => {
it.each([
[
{
children: <Alert onClose={() => {}}>alert text</Alert>,
translations: {
it('renders with translations', () => {
const dom = render((
<TranslationsProvider
translations={{
Alert: { close: 'Zavřít' },
},
},
(rootElement) => expect(within(rootElement).getByTitle('Zavřít')),
],
])('renders with props: "%s"', (testedProps, assert) => {
}}
>
<Alert onClose={() => {}}>alert text</Alert>
</TranslationsProvider>

));

expect(within(dom.container.firstChild).getByTitle('Zavřít'));
});

it('renders with nested translations', () => {
const dom = render((
<TranslationsProvider
{...testedProps}
/>
translations={{
ScrollView: {
next: 'Další',
previous: 'Předchozí',
},
}}
>
<TranslationsProvider
translations={{
ScrollView: { next: 'Sigiente' },
}}
>
<ScrollView arrows>some scrolable text</ScrollView>
</TranslationsProvider>
</TranslationsProvider>

));

assert(dom.container.firstChild);
expect(within(dom.container.firstChild).getByTitle('Předchozí'));
expect(within(dom.container.firstChild).getByTitle('Sigiente'));
});
});

0 comments on commit 2b0daaa

Please sign in to comment.