scratch-www/test/unit/components/become-a-scratcher.test.jsx

98 lines
3.3 KiB
React
Raw Permalink Normal View History

2022-02-23 17:00:45 -05:00
/* eslint-disable max-len */
2022-02-22 16:03:06 -05:00
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(
<BecomeAScratcherPage />, {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(
<BecomeAScratcherPage />, {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(
<BecomeAScratcherPage />, {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: {
2022-02-23 17:00:45 -05:00
user: {
2022-02-22 16:03:06 -05:00
id: 123,
2022-02-23 17:00:45 -05:00
thumbnailUrl: 'test',
username: 'test123'
2022-02-22 16:03:06 -05:00
},
permissions: {
scratcher: true
}
}
}
});
const component = mountWithIntl(
<BecomeAScratcherPage />, {context: {store: AlreadyScratcherStore}}
);
expect(component.find('div.hooray-screen').exists()).toBeTruthy();
});
});