Skip to content

Commit

Permalink
test: added factory for verified user
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Jan 8, 2024
1 parent 91a0f5b commit 25a7b71
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/courseware/course/Course.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import * as celebrationUtils from './celebration/utils';
import { handleNextSectionCelebration } from './celebration';
import Course from './Course';
import { setupDiscussionSidebar } from './test-utils';
import setupDiscussionSidebar from './test-utils';

jest.mock('@edx/frontend-platform/analytics');
jest.mock('@edx/frontend-lib-special-exams/dist/data/thunks.js', () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { appendBrowserTimezoneToUrl, executeThunk } from '../../../../../../util
import { fetchCourse } from '../../../../../data';
import SidebarContext from '../../../SidebarContext';
import NotificationsWidget from './NotificationsWidget';
import { setupDiscussionSidebar, userVerifiedMode } from '../../../../test-utils';
import setupDiscussionSidebar from '../../../../test-utils';

initializeMockApp();
jest.mock('@edx/frontend-platform/analytics');
Expand Down Expand Up @@ -53,6 +53,8 @@ describe('NotificationsWidget', () => {
});

it('successfully Open/Hide sidebar tray.', async () => {
const userVerifiedMode = Factory.build('verifiedMode');

await setupDiscussionSidebar(userVerifiedMode);

const sidebarButton = await screen.getByRole('button', { name: /Show sidebar tray/i });
Expand Down Expand Up @@ -121,17 +123,19 @@ describe('NotificationsWidget', () => {

it.each([
{
description: 'successfully close the notification widget.',
description: 'close the notification widget.',
enabledInContext: true,
testId:
'notification-widget',
},
{
description: 'successfully close the sidebar when we have no discussion widget and close the notification widget.',
description: 'close the sidebar when we have no discussion widget and close the notification widget.',
enabledInContext: false,
testId: 'sidebar-DISCUSSIONS_NOTIFICATIONS',
},
])('case: %s', async ({ enabledInContext, testId }) => {
])('successfully %s', async ({ enabledInContext, testId }) => {
const userVerifiedMode = Factory.build('verifiedMode');

await setupDiscussionSidebar(userVerifiedMode, enabledInContext);

const sidebarButton = screen.getByRole('button', { name: /Show sidebar tray/i });
Expand Down
13 changes: 3 additions & 10 deletions src/courseware/course/test-utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,13 @@ import { executeThunk } from '../../utils';
import * as thunks from '../data/thunks';
import Course from './Course';

export const userVerifiedMode = {
accessExpirationDate: null,
currency: 'USD',
currencySymbol: '$',
price: 149,
sku: '8CF08E5',
upgradeUrl: 'http://localhost:18130/basket/add/?sku=8CF08E5',
};

const mockData = {
nextSequenceHandler: () => {},
previousSequenceHandler: () => {},
unitNavigationHandler: () => {},

Check warning on line 16 in src/courseware/course/test-utils.jsx

View check run for this annotation

Codecov / codecov/patch

src/courseware/course/test-utils.jsx#L14-L16

Added lines #L14 - L16 were not covered by tests
};

export const setupDiscussionSidebar = async (verifiedMode = null, enabledInContext = true) => {
const setupDiscussionSidebar = async (verifiedMode = null, enabledInContext = true) => {
const store = await initializeTestStore();
const { courseware, models } = store.getState();
const { courseId, sequenceId } = courseware;
Expand Down Expand Up @@ -54,3 +45,5 @@ export const setupDiscussionSidebar = async (verifiedMode = null, enabledInConte
const wrapper = await render(<Course {...mockData} />, { store: testStore, wrapWithRouter: true });
return wrapper;
};

export default setupDiscussionSidebar;
7 changes: 7 additions & 0 deletions src/courseware/data/__factories__/discussionTopics.factory.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* eslint-disable import/prefer-default-export */
import { Factory } from 'rosie'; // eslint-disable-line import/no-extraneous-dependencies

Factory.define('verifiedMode')
.attr('currency', 'USD')
.attr('currencySymbol', '$')
.attr('price', '$149')
.attr('sku', '8CF08E5')
.attr('upgradeUrl', 'http://localhost:18130/basket/add/?sku=8CF08E5');

Factory.define('discussionTopic')
.option('topicPrefix', null, '')
.option('courseId', null, 'course-v1:edX+DemoX+Demo_Course')
Expand Down

0 comments on commit 25a7b71

Please sign in to comment.