From a218e7e5f8c58ced93c3a94ec5a638273a9af646 Mon Sep 17 00:00:00 2001 From: sundasnoreen12 <72802712+sundasnoreen12@users.noreply.github.com> Date: Tue, 8 Aug 2023 02:11:41 -0700 Subject: [PATCH] test: added test cases for hide discussion tab (#552) Co-authored-by: SundasNoreen --- .../discussions/app-list/AppList.jsx | 1 + .../discussions/app-list/AppList.test.jsx | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/pages-and-resources/discussions/app-list/AppList.jsx b/src/pages-and-resources/discussions/app-list/AppList.jsx index 4b1ad4eb2..122a6e38c 100644 --- a/src/pages-and-resources/discussions/app-list/AppList.jsx +++ b/src/pages-and-resources/discussions/app-list/AppList.jsx @@ -132,6 +132,7 @@ const AppList = ({ intl }) => { labelClassName="line-height-24" onChange={handleChange} checked={!discussionEnabled} + data-testId="hide-discussion" > Hide discussion tab diff --git a/src/pages-and-resources/discussions/app-list/AppList.test.jsx b/src/pages-and-resources/discussions/app-list/AppList.test.jsx index 9bfa74d8f..ccc3fd2e3 100644 --- a/src/pages-and-resources/discussions/app-list/AppList.test.jsx +++ b/src/pages-and-resources/discussions/app-list/AppList.test.jsx @@ -1,10 +1,11 @@ /* eslint-disable react/jsx-no-constructed-context-values */ import React from 'react'; import { - render, screen, within, queryAllByRole, waitFor, + render, screen, within, queryAllByRole, waitFor, fireEvent, } from '@testing-library/react'; import { initializeMockApp } from '@edx/frontend-platform'; import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; +import { act } from 'react-dom/test-utils'; import { IntlProvider } from '@edx/frontend-platform/i18n'; import { AppProvider } from '@edx/frontend-platform/react'; import { breakpoints } from '@edx/paragon'; @@ -67,6 +68,45 @@ describe('AppList', () => { await mockStore(piazzaApiResponse); }); + test('Successfully shows the disable toggle state of the hide discussion tab by default.', async () => { + renderComponent(); + + await waitFor(async () => { + const hideDiscussionTab = screen.getByTestId('hide-discussion'); + + expect(hideDiscussionTab).not.toBeChecked(); + }); + }); + + test.each([ + { title: 'OK', description: 'Enable the toggle state by clicking on OK button' }, + { title: 'Cancel', description: 'Disable the toggle state by clicking on Cancel button' }, + ])('%s of the hide discussion tab', async ({ title }) => { + renderComponent(); + + await waitFor(async () => { + let hideDiscussionTab = screen.getByTestId('hide-discussion'); + + await act(async () => { + fireEvent.click(hideDiscussionTab); + }); + + const actionButton = screen.queryByText(title); + + await act(async () => { + fireEvent.click(actionButton); + }); + + hideDiscussionTab = screen.getByTestId('hide-discussion'); + + if (title === 'OK') { + expect(hideDiscussionTab).toBeChecked(); + } else { + expect(hideDiscussionTab).not.toBeChecked(); + } + }); + }); + test('display a card for each available app', async () => { renderComponent();