Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use latest action #86

Merged
merged 1 commit into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions app/components/atoms/LanguageProvider/tests/action.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { changeLocale } from '../actions';
import { CHANGE_LOCALE } from '../constants';

describe('changeLocale action creator', () => {
it('should create an action to change the locale', () => {
const languageLocale = 'en';
const expectedAction = {
type: CHANGE_LOCALE,
locale: languageLocale
};
const action = changeLocale(languageLocale);
expect(action).toEqual(expectedAction);
});
});
19 changes: 8 additions & 11 deletions app/components/atoms/LanguageProvider/tests/index.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import React from 'react';
import 'react-native';
import { render } from '@testing-library/react-native';
import { Provider } from 'react-redux';
import T from '@atoms/T';
import createStore from 'app/rootReducer';
import { translationMessages } from 'app/i18n';
import { renderWithIntl } from '@utils/testUtils';
import { Text } from 'react-native';
import ConnectedLanguageProvider, { LanguageProvider } from '../index';

describe('<LanguageProvider /> container tests', () => {
it('should render its children', () => {
const children = <h1>Test</h1>;
const children = (
<h1>
<Text>Test</Text>
</h1>
);
const container = renderWithIntl(
<LanguageProvider messages={translationMessages} locale="en">
{children}
Expand All @@ -19,16 +22,10 @@ describe('<LanguageProvider /> container tests', () => {
expect(container.firstChild).not.toBeNull();
});
});

const setupReduxStore = () => ({ reduxStore: createStore().store });
describe('<ConnectedLanguageProvider /> container tests', () => {
let reduxStore;

beforeAll(() => {
const { store } = createStore();
reduxStore = store;
});

it('should render the default language messages', () => {
const { reduxStore } = setupReduxStore();
const { queryByText } = render(
<Provider store={reduxStore}>
<ConnectedLanguageProvider messages={translationMessages}>
Expand Down
12 changes: 5 additions & 7 deletions app/components/atoms/LanguageProvider/tests/reducer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@ import {
languageProviderTypes,
languageProviderReducer
} from '../reducer';

const setupMockedState = state => ({ mockedState: state });
/* eslint-disable default-case, no-param-reassign */
describe('Tests for LanguageProvider actions', () => {
let mockedState;
beforeEach(() => {
mockedState = initialState;
});

it('returns the initial state', () => {
const { mockedState } = setupMockedState(initialState);
expect(languageProviderReducer(undefined, {})).toEqual(mockedState);
});

it('changes the locale', () => {
const locale = 'de';
mockedState = mockedState.set('locale', locale);
const { mockedState } = setupMockedState(
initialState.set('locale', locale)
);
expect(
languageProviderReducer(undefined, {
type: languageProviderTypes.CHANGE_LOCALE,
Expand Down