Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/pages-and-resources/discussions/app-list/AppList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const AppList = ({ intl }) => {
labelClassName="line-height-24"
onChange={handleChange}
checked={!discussionEnabled}
data-testId="hide-discussion"
>
Hide discussion tab
</Form.Switch>
Expand Down
42 changes: 41 additions & 1 deletion src/pages-and-resources/discussions/app-list/AppList.test.jsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();

Expand Down