test: tests added based on piisharing flag

This commit is contained in:
Mehak Nasir
2021-12-21 19:07:41 +05:00
committed by Mehak Nasir
parent 1c003efd62
commit eafd82bff3
3 changed files with 53 additions and 3 deletions

View File

@@ -418,3 +418,50 @@ describe.each([
}
});
});
describe.each([
{ piiSharingAllowed: false },
{ piiSharingAllowed: true },
])('PII sharing fields test', ({ piiSharingAllowed }) => {
beforeEach(() => {
initializeMockApp({
authenticatedUser: {
userId: 3,
username: 'abc123',
administrator: true,
roles: [],
},
});
store = initializeStore({
models: {
courseDetails: {
[courseId]: {},
},
},
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
// Leave the DiscussionsSettings route after the test.
history.push(`/course/${courseId}/pages-and-resources`);
axiosMock.onGet(getAppsUrl(courseId)).reply(200, generatePiazzaApiResponse(false, piiSharingAllowed));
renderComponent();
});
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`);
// 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 waitForElementToBeRemoved(screen.getByRole('status'));
userEvent.click(queryByLabelText(container, 'Select Piazza'));
userEvent.click(queryByText(container, messages.nextButton.defaultMessage));
if (piiSharingAllowed) {
expect(queryByTestId(container, 'piiSharingFields')).toBeInTheDocument();
} else {
expect(queryByTestId(container, 'piiSharingFields')).not.toBeInTheDocument();
}
});
});

View File

@@ -134,7 +134,7 @@ function LtiConfigForm({ onSubmit, intl, formRef }) {
</>
)}
{piiConfig.piiSharing && (
<>
<div data-testid="piiSharingFields">
<Form.Text className="my-2">{intl.formatMessage(messages.piiSharing)}</Form.Text>
<Form.Group controlId="piiSharing">
<Form.Check
@@ -154,7 +154,7 @@ function LtiConfigForm({ onSubmit, intl, formRef }) {
label={intl.formatMessage(messages.piiShareEmail)}
/>
</Form.Group>
</>
</div>
)}
</Form>
<AppExternalLinks externalLinks={externalLinks} providerName={providerName} />

View File

@@ -1,4 +1,4 @@
export const generatePiazzaApiResponse = (piazzaAdminOnlyConfig = false) => ({
export const generatePiazzaApiResponse = (piazzaAdminOnlyConfig = false, piiSharingAllowed = false) => ({
context_key: 'course-v1:edX+DemoX+Demo_Course',
enabled: true,
provider_type: 'piazza',
@@ -12,6 +12,9 @@ export const generatePiazzaApiResponse = (piazzaAdminOnlyConfig = false) => ({
lti_1p1_client_key: 'client_key_123',
lti_1p1_client_secret: 'client_secret_123',
lti_1p1_launch_url: 'https://localhost/example',
pii_sharing_allowed: piiSharingAllowed,
pii_share_email: false,
pii_share_username: false,
version: 'lti_1p1',
},
plugin_configuration: {},