From 25a7b71fd3151e09bb2ece829fed506d085fcb42 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 Date: Mon, 8 Jan 2024 18:49:40 +0500 Subject: [PATCH] test: added factory for verified user --- src/courseware/course/Course.test.jsx | 2 +- .../notifications/NotificationsWidget.test.jsx | 12 ++++++++---- src/courseware/course/test-utils.jsx | 13 +++---------- .../data/__factories__/discussionTopics.factory.js | 7 +++++++ 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/courseware/course/Course.test.jsx b/src/courseware/course/Course.test.jsx index 40dd0da779..ab629700aa 100644 --- a/src/courseware/course/Course.test.jsx +++ b/src/courseware/course/Course.test.jsx @@ -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', () => ({ diff --git a/src/courseware/course/new-sidebar/sidebars/discussions-notifications/notifications/NotificationsWidget.test.jsx b/src/courseware/course/new-sidebar/sidebars/discussions-notifications/notifications/NotificationsWidget.test.jsx index d3f5d2aa79..666856805f 100644 --- a/src/courseware/course/new-sidebar/sidebars/discussions-notifications/notifications/NotificationsWidget.test.jsx +++ b/src/courseware/course/new-sidebar/sidebars/discussions-notifications/notifications/NotificationsWidget.test.jsx @@ -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'); @@ -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 }); @@ -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 }); diff --git a/src/courseware/course/test-utils.jsx b/src/courseware/course/test-utils.jsx index 84a428e186..df7a7cbcc8 100644 --- a/src/courseware/course/test-utils.jsx +++ b/src/courseware/course/test-utils.jsx @@ -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: () => {}, }; -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; @@ -54,3 +45,5 @@ export const setupDiscussionSidebar = async (verifiedMode = null, enabledInConte const wrapper = await render(, { store: testStore, wrapWithRouter: true }); return wrapper; }; + +export default setupDiscussionSidebar; diff --git a/src/courseware/data/__factories__/discussionTopics.factory.js b/src/courseware/data/__factories__/discussionTopics.factory.js index bef086beb4..47f863e9a4 100644 --- a/src/courseware/data/__factories__/discussionTopics.factory.js +++ b/src/courseware/data/__factories__/discussionTopics.factory.js @@ -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')