test: added test cases for hide discussion tab (#552)

Co-authored-by: SundasNoreen <sundas.noreen@arbisoft.com>
This commit is contained in:
sundasnoreen12
2023-08-08 02:11:41 -07:00
committed by GitHub
parent f2a4386892
commit a218e7e5f8
2 changed files with 42 additions and 1 deletions

View File

@@ -132,6 +132,7 @@ const AppList = ({ intl }) => {
labelClassName="line-height-24"
onChange={handleChange}
checked={!discussionEnabled}
data-testId="hide-discussion"
>
Hide discussion tab
</Form.Switch>

View File

@@ -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();