Updated tests for magiclink page

no issue

- Add test for close button firing correct action(closePopup) on magic link page
- Use common test utils setup
This commit is contained in:
Rish 2020-04-30 11:49:18 +05:30
parent 30a14023cf
commit 712ac5cd74

View File

@ -1,15 +1,33 @@
import React from 'react';
import {render} from '@testing-library/react';
import {render, fireEvent} from 'test-utils';
import MagicLinkPage from './MagicLinkPage';
const setup = (overrides) => {
const {mockOnActionFn, ...utils} = render(
<MagicLinkPage />
);
const inboxText = utils.getByText(/check your inbox!/i);
const closeBtn = utils.queryByRole('button', {name: 'Close'});
return {
inboxText,
closeBtn,
mockOnActionFn,
...utils
};
};
describe('MagicLinkPage', () => {
test('renders', () => {
const {getByText} = render(
<MagicLinkPage />
);
const inboxText = getByText(/check your inbox!/i);
const {inboxText, closeBtn} = setup();
expect(inboxText).toBeInTheDocument();
expect(closeBtn).toBeInTheDocument();
});
test('calls on action with close popup', () => {
const {closeBtn, mockOnActionFn} = setup();
fireEvent.click(closeBtn);
expect(mockOnActionFn).toHaveBeenCalledWith('closePopup');
});
});