Skip to content

Commit

Permalink
Merge pull request #1342 from Guryanov-Maksim/settings-updating-fix
Browse files Browse the repository at this point in the history
Fix game creating with ts and golang languages
  • Loading branch information
ReDBrother committed Mar 3, 2023
2 parents b32ee14 + a3f1755 commit ca086a7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Expand Up @@ -5,16 +5,21 @@ import {
} from '@testing-library/react';
import { configureStore, combineReducers } from '@reduxjs/toolkit';
import { Provider } from 'react-redux';
import axios from 'axios';

import reducers from '../widgets/slices';
import UserSettings from '../widgets/containers/UserSettings';
import UserSettingsForm from '../widgets/components/User/UserSettingsForm';
import languages from '../widgets/config/languages';

jest.mock('@fortawesome/react-fontawesome', () => ({
FontAwesomeIcon: 'img',
}));

jest.mock('axios');

jest.useFakeTimers();

const reducer = combineReducers(reducers);

const preloadedState = {
Expand All @@ -25,7 +30,7 @@ const preloadedState = {
},
id: 11,
name: 'Diman',
lang: 'typescript',
lang: 'ts',
avatar_url: '/assets/images/logo.svg',
discord_name: null,
discord_id: null,
Expand All @@ -49,6 +54,8 @@ jest.mock(
{ virtual: true },
);

const settings = Object.keys(languages);

const vdom = () => render(
<Provider store={store}>
<UserSettings />
Expand All @@ -60,16 +67,25 @@ describe('UserSettings test cases', () => {
expect(getByText(/settings/i)).toBeInTheDocument();
});
it('show success notification', async () => {
const settingUpdaterSpy = jest.spyOn(axios, 'patch').mockResolvedValueOnce({ data: {} });
const {
getByRole,
} = vdom();
const save = getByRole('button', { name: /save/i });
const alert = getByRole('alert');

fireEvent.change(screen.getByLabelText(/your name/i), {
target: { value: 'Dmitry' },
});
fireEvent.click(save);

setTimeout(() => expect(alert).toHaveClass('editSuccess'), 300);
await waitFor(() => {
expect(settingUpdaterSpy).toHaveBeenCalled();
expect(alert).toHaveClass('alert-success');
});
});
it('editing profile test', async () => {

test.each(settings)('editing profile test with lang %s', async lang => {
const handleSubmit = jest.fn();
render(
<UserSettingsForm
Expand All @@ -81,15 +97,15 @@ describe('UserSettings test cases', () => {
target: { value: 'Dmitry' },
});
fireEvent.change(screen.getByTestId('langSelect'), {
target: { value: 'java' },
target: { value: lang },
});
const saveBtn = screen.getByRole('button', { name: /save/i });
fireEvent.click(saveBtn);
await waitFor(() => {
expect(handleSubmit).toHaveBeenCalled();
expect(handleSubmit).toHaveBeenCalledWith({
name: 'Dmitry',
lang: 'java',
lang,
sound_settings: {
level: 6,
type: 'standart',
Expand Down
Expand Up @@ -34,7 +34,7 @@ const TextInput = ({ label, ...props }) => {

export default ({ onSubmit, settings }) => {
const renderLanguages = langs => langs.map(([slug, lang]) => (
<option key={slug} value={lang}>
<option key={slug} value={slug}>
{_.capitalize(lang)}
</option>
));
Expand Down

0 comments on commit ca086a7

Please sign in to comment.