From 6bf5c4dd89557b4952acde9693376dff5eaa9986 Mon Sep 17 00:00:00 2001 From: tomlum Date: Tue, 22 Feb 2022 16:03:06 -0500 Subject: [PATCH] adds tests --- .../become-a-scratcher/become-a-scratcher.jsx | 2 +- .../components/become-a-scratcher.test.jsx | 96 +++++++++++++++++++ 2 files changed, 97 insertions(+), 1 deletion(-) create mode 100644 test/unit/components/become-a-scratcher.test.jsx diff --git a/src/views/become-a-scratcher/become-a-scratcher.jsx b/src/views/become-a-scratcher/become-a-scratcher.jsx index 9f16b6210..375903930 100644 --- a/src/views/become-a-scratcher/become-a-scratcher.jsx +++ b/src/views/become-a-scratcher/become-a-scratcher.jsx @@ -575,7 +575,7 @@ const mapStateToProps = state => ({ sessionStatus: state.session.status }); -const ConnectedBecomeAScratcher = connect( +export const ConnectedBecomeAScratcher = connect( mapStateToProps )(BecomeAScratcher); diff --git a/test/unit/components/become-a-scratcher.test.jsx b/test/unit/components/become-a-scratcher.test.jsx new file mode 100644 index 000000000..b394d9fec --- /dev/null +++ b/test/unit/components/become-a-scratcher.test.jsx @@ -0,0 +1,96 @@ +const React = require('react'); +const {mountWithIntl} = require('../../helpers/intl-helpers.jsx'); +import {ConnectedBecomeAScratcher as BecomeAScratcherPage} from '../../../src/views/become-a-scratcher/become-a-scratcher.jsx'; +import sessionActions from '../../../src/redux/session.js'; +import configureStore from 'redux-mock-store'; + +jest.mock('react-dom', () => ({ + render: jest.fn() +})); + +jest.mock('../../../src/components/modal/base/modal.jsx', () => () => 'MockModal'); + +describe('BecomeAScratcherPage', () => { + const mockStore = configureStore(); + + test('Display 404 when no user', () => { + const NotLoggedInUserStore = mockStore({ + session: { + status: sessionActions.Status.FETCHED, + session: { + user: null, + permissions: {} + } + } + }); + const component = mountWithIntl( + , {context: {store: NotLoggedInUserStore}} + ); + expect(component.find('div.not-available-outer').exists()).toBeTruthy(); + }); + + test('Display No Invitation when user is not invited', () => { + + const NotInvitedUserStore = mockStore({ + session: { + status: sessionActions.Status.FETCHED, + session: { + user: { + id: 123, + thumbnailUrl: 'test', + username: 'test123' + }, + permissions: {} + } + } + }); + const component = mountWithIntl( + , {context: {store: NotInvitedUserStore}} + ); + expect(component.find('div.no-invitation').exists()).toBeTruthy(); + }); + + test('Display Onboarding when user is invited', () => { + const InvitedUserStore = mockStore({ + session: { + status: sessionActions.Status.FETCHED, + session: { + user: { + id: 123, + thumbnailUrl: 'test', + username: 'test123' + }, + permissions: { + invited_scratcher: true + } + } + } + }); + const component = mountWithIntl( + , {context: {store: InvitedUserStore}} + ); + expect(component.find('div.congratulations-page').exists()).toBeTruthy(); + }); + + test('Display celebration page when user is already a scratcher', () => { + const AlreadyScratcherStore = mockStore({ + session: { + status: sessionActions.Status.FETCHED, + session: { + user:{ + id: 123, + thumbnailUrl: "test", + username: "test123" + }, + permissions: { + scratcher: true + } + } + } + }); + const component = mountWithIntl( + , {context: {store: AlreadyScratcherStore}} + ); + expect(component.find('div.hooray-screen').exists()).toBeTruthy(); + }); +});