kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
				
				
				
			Add tests for LoginForm
							rodzic
							
								
									bacc34f872
								
							
						
					
					
						commit
						c465e68f67
					
				| 
						 | 
				
			
			@ -1,31 +1,41 @@
 | 
			
		|||
import { Map as ImmutableMap } from 'immutable';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
 | 
			
		||||
import { render, screen } from '../../../../jest/test-helpers';
 | 
			
		||||
import { fireEvent, render, screen } from '../../../../jest/test-helpers';
 | 
			
		||||
import LoginForm from '../login_form';
 | 
			
		||||
 | 
			
		||||
describe('<LoginForm />', () => {
 | 
			
		||||
  it('renders for Pleroma', () => {
 | 
			
		||||
    const mockFn = jest.fn();
 | 
			
		||||
    const store = {
 | 
			
		||||
      instance: ImmutableMap({
 | 
			
		||||
        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', () => {
 | 
			
		||||
    const mockFn = jest.fn();
 | 
			
		||||
    const store = {
 | 
			
		||||
      instance: ImmutableMap({
 | 
			
		||||
        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
 | 
			
		||||
            />
 | 
			
		||||
          </FormGroup>
 | 
			
		||||
 | 
			
		||||
          <FormActions>
 | 
			
		||||
            <Button
 | 
			
		||||
              theme='primary'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,6 +29,7 @@ module.exports = {
 | 
			
		|||
    '<rootDir>/node_modules',
 | 
			
		||||
    '<rootDir>/app',
 | 
			
		||||
  ],
 | 
			
		||||
  'testMatch': ['**/*/__tests__/**/?(*.|*-)+(test).(ts|js)?(x)'],
 | 
			
		||||
  'testEnvironment': 'jsdom',
 | 
			
		||||
  'moduleNameMapper': {
 | 
			
		||||
    '^.+.(css|styl|less|sass|scss|png|jpg|svg|ttf|woff|woff2)$': 'jest-transform-stub',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue