mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Added action tests for Account Page
Adds signout button test for account page
This commit is contained in:
parent
22bee293bc
commit
4789f473e3
@ -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>
|
||||
|
@ -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');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user