Skip to content

Commit

Permalink
refactor: updated tests for DiscussionsSettings
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 committed Aug 11, 2023
1 parent ebb691a commit 931b962
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/pages-and-resources/discussions/DiscussionsSettings.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -481,21 +481,23 @@ describe.each([

test(`${piiSharingAllowed ? 'shows PII share username/email field when piiSharingAllowed is true'
: 'hides PII share username/email field when piiSharingAllowed is false'}`, async () => {
history.push(`/course/${courseId}/pages-and-resources/discussion`);
setTimeout(async () => {
history.push(`/course/${courseId}/pages-and-resources/discussion`);

// This is an important line that ensures the spinner has been removed - and thus our main
// content has been loaded - prior to proceeding with our expectations.
await waitFor(() => expect(screen.queryByRole('status')).toBeNull());
// This is an important line that ensures the spinner has been removed - and thus our main
// content has been loaded - prior to proceeding with our expectations.
await waitFor(() => expect(screen.queryByRole('status')).toBeNull());

act(() => {
userEvent.click(queryByLabelText(container, 'Select Piazza'));
userEvent.click(queryByText(container, messages.nextButton.defaultMessage));
});
await waitFor(() => expect(screen.queryByRole('status')).toBeNull());
if (enablePIISharing) {
expect(queryByTestId(container, 'piiSharingFields')).toBeInTheDocument();
} else {
expect(queryByTestId(container, 'piiSharingFields')).not.toBeInTheDocument();
}
act(() => {
userEvent.click(queryByLabelText(container, 'Select Piazza'));
userEvent.click(queryByText(container, messages.nextButton.defaultMessage));
});
await waitFor(() => expect(screen.queryByRole('status')).toBeNull());
if (enablePIISharing) {
expect(queryByTestId(container, 'piiSharingFields')).toBeInTheDocument();
} else {
expect(queryByTestId(container, 'piiSharingFields')).not.toBeInTheDocument();
}
})
});
});

0 comments on commit 931b962

Please sign in to comment.