Skip to content

Commit

Permalink
test: fixed test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sundasnoreen12 committed Dec 27, 2023
1 parent b1003b5 commit fe36b0d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 63 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ TWITTER_HASHTAG=''
TWITTER_URL=''
USER_INFO_COOKIE_NAME=''
OPTIMIZELY_FULL_STACK_SDK_KEY=''
ENABLE_SIDEBAR_NEW_VIEW='false'
ENABLE_SIDEBAR_NEW_VIEW='false'
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ describe('Discussions Trigger', () => {
mockData = {
courseId,
unitId,
currentSidebar: 'DISCUSSIONS',
currentSidebar: 'NEWSIDEBAR',
hideDiscussionbar: false,
isDiscussionbarAvailable: true,
};

axiosMock.onGet(`${getConfig().LMS_BASE_URL}/api/discussion/v1/courses/${courseId}`).reply(
Expand Down Expand Up @@ -64,7 +66,7 @@ describe('Discussions Trigger', () => {
});

it('should show nothing if unit has no discussions associated with it', async () => {
renderWithProvider({ unitId: 'no-discussion' });
renderWithProvider({ isDiscussionbarAvailable: false });
expect(screen.queryByTitle('Discussions')).not.toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { breakpoints } from '@edx/paragon';
import MockAdapter from 'axios-mock-adapter';
import React from 'react';
import { Factory } from 'rosie';
import {
fireEvent, initializeMockApp, render, screen, waitFor,
} from '../../../../../setupTest';
import { initializeMockApp, render, screen } from '../../../../../setupTest';
import initializeStore from '../../../../../store';
import { appendBrowserTimezoneToUrl, executeThunk } from '../../../../../utils';

Expand Down Expand Up @@ -50,42 +48,13 @@ describe('NotificationTray', () => {
axiosMock.onGet(courseHomeMetadataUrl).reply(200, courseHomeMetadata);
});

it('renders notification tray and close tray button', async () => {
global.innerWidth = breakpoints.extraLarge.minWidth;
const toggleNotificationTray = jest.fn();
await fetchAndRender(
<SidebarContext.Provider value={{
currentSidebar: ID,
courseId,
toggleSidebar: toggleNotificationTray,
shouldDisplayFullScreen: false,
}}
>
<NotificationTray />
</SidebarContext.Provider>,
);
expect(screen.getByText('Notifications'))
.toBeInTheDocument();
const notificationCloseIconButton = screen.getByRole('button', { name: /Close notification tray/i });
expect(notificationCloseIconButton)
.toBeInTheDocument();
expect(notificationCloseIconButton)
.toHaveClass('btn-icon-primary');
fireEvent.click(notificationCloseIconButton);
expect(toggleNotificationTray)
.toHaveBeenCalledTimes(1);

// should not render responsive "Back to course" to close the tray
expect(screen.queryByText('Back to course'))
.not
.toBeInTheDocument();
});

it('renders upgrade card', async () => {
await fetchAndRender(
<SidebarContext.Provider value={{
currentSidebar: ID,
courseId,
hideNotificationbar: false,
isNotificationbarAvailable: true,
}}
>
<NotificationTray />
Expand All @@ -102,18 +71,21 @@ describe('NotificationTray', () => {
.toBeInTheDocument();
});

it('renders no notifications message if no verified mode', async () => {
it('renders no notifications bar if no verified mode', async () => {
setMetadata({ verified_mode: null });
await fetchAndRender(
<SidebarContext.Provider value={{
currentSidebar: ID,
courseId,
hideNotificationbar: true,
isNotificationbarAvailable: false,
}}
>
<NotificationTray />
</SidebarContext.Provider>,
);
expect(screen.queryByText('You have no new notifications at this time.'))
expect(screen.queryByText('Notifications'))
.not
.toBeInTheDocument();
});

Expand All @@ -125,6 +97,8 @@ describe('NotificationTray', () => {
currentSidebar: ID,
courseId,
onNotificationSeen,
hideNotificationbar: false,
isNotificationbarAvailable: true,
}}
>
<NotificationTray />
Expand All @@ -134,28 +108,4 @@ describe('NotificationTray', () => {
jest.advanceTimersByTime(3000);
expect(onNotificationSeen).toHaveBeenCalledTimes(1);
});

it('renders notification tray with full screen "Back to course" at responsive view', async () => {
global.innerWidth = breakpoints.medium.maxWidth;
const toggleNotificationTray = jest.fn();
await fetchAndRender(
<SidebarContext.Provider value={{
currentSidebar: ID,
courseId,
shouldDisplayFullScreen: true,
toggleSidebar: toggleNotificationTray,
}}
>
<NotificationTray />
</SidebarContext.Provider>,
);

const responsiveCloseButton = screen.getByRole('button', { name: 'Back to course' });
await waitFor(() => expect(responsiveCloseButton)
.toBeInTheDocument());

fireEvent.click(responsiveCloseButton);
expect(toggleNotificationTray)
.toHaveBeenCalledTimes(1);
});
});

0 comments on commit fe36b0d

Please sign in to comment.