Added action tests for Account Page

Adds signout button test for account page
This commit is contained in:
Rish 2020-04-16 14:20:04 +05:30
parent 22bee293bc
commit 4789f473e3
2 changed files with 28 additions and 8 deletions

View File

@ -144,7 +144,7 @@ export default class SignedInPage extends React.Component {
renderLogoutButton() {
return (
<div style={{paddingLeft: '16px', paddingRight: '16px', paddingTop: '12px', borderTop: '1px solid #EFEFEF', cursor: 'pointer'}}>
<div onClick={(e) => {
<div role="button" onClick={(e) => {
this.handleSignout(e);
}} style={{fontWeight: 'bold'}}> Logout </div>
</div>

View File

@ -1,18 +1,38 @@
import React from 'react';
import {render} from '@testing-library/react';
import {render, fireEvent} from '@testing-library/react';
import SignedInPage from './SignedInPage';
import {site, member} from '../test/fixtures/data';
const setup = (overrides) => {
const mockOnActionFn = jest.fn();
const mockSwitchPageFn = jest.fn();
const utils = render(
<SignedInPage data={{site, member}} onAction={mockOnActionFn} switchPage={mockSwitchPageFn} />
);
const memberEmail = utils.getByText(member.email);
const logoutButton = utils.queryByRole('button', {name: 'Logout'});
return {
memberEmail,
logoutButton,
mockOnActionFn,
mockSwitchPageFn,
...utils
};
};
describe('SignedInPage', () => {
test('renders', () => {
const {getByText} = render(
<SignedInPage data={{site, member}} onAction={() => {}} switchPage={() => {}} />
);
const memberEmail = getByText(member.email);
const logoutButton = getByText(/logout/i);
const {memberEmail, logoutButton} = setup();
expect(memberEmail).toBeInTheDocument();
expect(logoutButton).toBeInTheDocument();
});
test('can call signout', () => {
const {mockOnActionFn, logoutButton} = setup();
fireEvent.click(logoutButton);
expect(mockOnActionFn).toHaveBeenCalledWith('signout');
});
});