Add tests for LoginForm
This commit is contained in:
parent
bacc34f872
commit
c465e68f67
|
@ -1,31 +1,41 @@
|
||||||
import { Map as ImmutableMap } from 'immutable';
|
import { Map as ImmutableMap } from 'immutable';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { render, screen } from '../../../../jest/test-helpers';
|
import { fireEvent, render, screen } from '../../../../jest/test-helpers';
|
||||||
import LoginForm from '../login_form';
|
import LoginForm from '../login_form';
|
||||||
|
|
||||||
describe('<LoginForm />', () => {
|
describe('<LoginForm />', () => {
|
||||||
it('renders for Pleroma', () => {
|
it('renders for Pleroma', () => {
|
||||||
|
const mockFn = jest.fn();
|
||||||
const store = {
|
const store = {
|
||||||
instance: ImmutableMap({
|
instance: ImmutableMap({
|
||||||
version: '2.7.2 (compatible; Pleroma 2.3.0)',
|
version: '2.7.2 (compatible; Pleroma 2.3.0)',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
render(<LoginForm />, null, store);
|
render(<LoginForm handleSubmit={mockFn} isLoading={false} />, null, store);
|
||||||
|
|
||||||
expect(screen.getByRole('heading')).toHaveTextContent('Sign In');
|
expect(screen.getByRole('heading')).toHaveTextContent(/sign in/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders for Mastodon', () => {
|
it('renders for Mastodon', () => {
|
||||||
|
const mockFn = jest.fn();
|
||||||
const store = {
|
const store = {
|
||||||
instance: ImmutableMap({
|
instance: ImmutableMap({
|
||||||
version: '3.0.0',
|
version: '3.0.0',
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
render(<LoginForm />, null, store);
|
render(<LoginForm handleSubmit={mockFn} isLoading={false} />, null, store);
|
||||||
|
|
||||||
expect(screen.getByRole('heading')).toHaveTextContent('Sign In');
|
expect(screen.getByRole('heading')).toHaveTextContent(/sign in/i);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('responds to the handleSubmit prop', () => {
|
||||||
|
const mockFn = jest.fn();
|
||||||
|
render(<LoginForm handleSubmit={mockFn} isLoading={false} />);
|
||||||
|
fireEvent.submit(screen.getByTestId(/button/i));
|
||||||
|
|
||||||
|
expect(mockFn).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -66,6 +66,7 @@ const LoginForm = ({ isLoading, handleSubmit }) => {
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
|
|
||||||
<FormActions>
|
<FormActions>
|
||||||
<Button
|
<Button
|
||||||
theme='primary'
|
theme='primary'
|
||||||
|
|
|
@ -29,6 +29,7 @@ module.exports = {
|
||||||
'<rootDir>/node_modules',
|
'<rootDir>/node_modules',
|
||||||
'<rootDir>/app',
|
'<rootDir>/app',
|
||||||
],
|
],
|
||||||
|
'testMatch': ['**/*/__tests__/**/?(*.|*-)+(test).(ts|js)?(x)'],
|
||||||
'testEnvironment': 'jsdom',
|
'testEnvironment': 'jsdom',
|
||||||
'moduleNameMapper': {
|
'moduleNameMapper': {
|
||||||
'^.+.(css|styl|less|sass|scss|png|jpg|svg|ttf|woff|woff2)$': 'jest-transform-stub',
|
'^.+.(css|styl|less|sass|scss|png|jpg|svg|ttf|woff|woff2)$': 'jest-transform-stub',
|
||||||
|
|
Loading…
Reference in New Issue