test: test fixes for refactored code
This commit is contained in:
@@ -25,6 +25,7 @@ import { fetchApps } from '../../../data/thunks';
|
||||
import { legacyApiResponse } from '../../../factories/mockApiResponses';
|
||||
import messages from '../../messages';
|
||||
import LegacyConfigForm from './LegacyConfigForm';
|
||||
import { selectApp } from '../../../data/slice';
|
||||
|
||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||
const defaultAppConfig = {
|
||||
@@ -32,12 +33,12 @@ const defaultAppConfig = {
|
||||
divideByCohorts: false,
|
||||
divideCourseTopicsByCohorts: false,
|
||||
discussionTopics: [
|
||||
{ name: 'General', id: 'course' },
|
||||
{ name: 'Edx', id: '13f106c6-6735-4e84-b097-0456cff55960' },
|
||||
{ name: 'General', id: 'course' },
|
||||
],
|
||||
divideDiscussionIds: [
|
||||
'course',
|
||||
'13f106c6-6735-4e84-b097-0456cff55960',
|
||||
'course',
|
||||
],
|
||||
allowAnonymousPosts: false,
|
||||
allowAnonymousPostsPeers: false,
|
||||
@@ -49,7 +50,7 @@ describe('LegacyConfigForm', () => {
|
||||
let store;
|
||||
let container;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
initializeMockApp({
|
||||
authenticatedUser: {
|
||||
userId: 3,
|
||||
@@ -58,7 +59,6 @@ describe('LegacyConfigForm', () => {
|
||||
roles: [],
|
||||
},
|
||||
});
|
||||
|
||||
axiosMock = new MockAdapter(getAuthenticatedHttpClient());
|
||||
store = initializeStore();
|
||||
});
|
||||
@@ -67,13 +67,11 @@ describe('LegacyConfigForm', () => {
|
||||
axiosMock.reset();
|
||||
});
|
||||
|
||||
const createComponent = (appConfig, onSubmit = jest.fn(), formRef = createRef()) => {
|
||||
const createComponent = (onSubmit = jest.fn(), formRef = createRef()) => {
|
||||
const wrapper = render(
|
||||
<AppProvider store={store}>
|
||||
<IntlProvider locale="en">
|
||||
<LegacyConfigForm
|
||||
title="Test Legacy edX Discussions"
|
||||
appConfig={appConfig}
|
||||
onSubmit={onSubmit}
|
||||
formRef={formRef}
|
||||
/>
|
||||
@@ -87,13 +85,13 @@ describe('LegacyConfigForm', () => {
|
||||
const mockStore = async (mockResponse) => {
|
||||
axiosMock.onGet(getAppsUrl(courseId)).reply(200, mockResponse);
|
||||
await executeThunk(fetchApps(courseId), store.dispatch);
|
||||
store.dispatch(selectApp({ appId: 'legacy' }));
|
||||
};
|
||||
|
||||
test('title rendering', async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(defaultAppConfig);
|
||||
|
||||
expect(container.querySelector('h3')).toHaveTextContent('Test Legacy edX Discussions');
|
||||
createComponent();
|
||||
expect(container.querySelector('h3')).toHaveTextContent('edX');
|
||||
});
|
||||
|
||||
test('calls onSubmit when the formRef is submitted', async () => {
|
||||
@@ -101,10 +99,7 @@ describe('LegacyConfigForm', () => {
|
||||
const handleSubmit = jest.fn();
|
||||
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent({
|
||||
...defaultAppConfig,
|
||||
divideByCohorts: true,
|
||||
}, handleSubmit, formRef);
|
||||
createComponent(handleSubmit, formRef);
|
||||
|
||||
await act(async () => {
|
||||
formRef.current.submit();
|
||||
@@ -122,15 +117,12 @@ describe('LegacyConfigForm', () => {
|
||||
});
|
||||
|
||||
test('default field states are correct, including removal of folded sub-fields', async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(defaultAppConfig);
|
||||
|
||||
await mockStore({ ...legacyApiResponse, plugin_configuration: { divided_course_wide_discussions: [] } });
|
||||
createComponent();
|
||||
// DivisionByGroupFields
|
||||
expect(container.querySelector('#divideByCohorts')).toBeInTheDocument();
|
||||
expect(container.querySelector('#divideByCohorts')).not.toBeChecked();
|
||||
expect(
|
||||
container.querySelector('#divideCourseTopicsByCohorts'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(container.querySelector('#divideCourseTopicsByCohorts')).not.toBeInTheDocument();
|
||||
|
||||
defaultAppConfig.divideDiscussionIds.forEach(id => expect(
|
||||
container.querySelector(`#checkbox-${id}`),
|
||||
@@ -148,12 +140,11 @@ describe('LegacyConfigForm', () => {
|
||||
});
|
||||
|
||||
test('folded sub-fields are in the DOM when parents are enabled', async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent({
|
||||
...defaultAppConfig,
|
||||
divideByCohorts: true,
|
||||
allowAnonymousPosts: true,
|
||||
await mockStore({
|
||||
...legacyApiResponse,
|
||||
plugin_configuration: { ...legacyApiResponse.plugin_configuration, allow_anonymous: true },
|
||||
});
|
||||
createComponent();
|
||||
|
||||
// DivisionByGroupFields
|
||||
expect(container.querySelector('#divideByCohorts')).toBeInTheDocument();
|
||||
@@ -182,12 +173,15 @@ describe('LegacyConfigForm', () => {
|
||||
|
||||
test('folded discussion topics are in the DOM when divideByCohorts and divideCourseWideTopics are enabled',
|
||||
async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent({
|
||||
...defaultAppConfig,
|
||||
divideByCohorts: true,
|
||||
divideCourseTopicsByCohorts: true,
|
||||
await mockStore({
|
||||
...legacyApiResponse,
|
||||
plugin_configuration: {
|
||||
...legacyApiResponse.plugin_configuration,
|
||||
divided_course_wide_discussions: ['13f106c6-6735-4e84-b097-0456cff55960',
|
||||
'course', 'test-topic'],
|
||||
},
|
||||
});
|
||||
createComponent();
|
||||
|
||||
// DivisionByGroupFields
|
||||
expect(container.querySelector('#divideByCohorts')).toBeInTheDocument();
|
||||
@@ -230,7 +224,7 @@ describe('LegacyConfigForm', () => {
|
||||
test('show required error on field when leaving empty topic name',
|
||||
async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(defaultAppConfig);
|
||||
createComponent();
|
||||
|
||||
const topicCard = await updateTopicName('13f106c6-6735-4e84-b097-0456cff55960', '');
|
||||
await waitForElementToBeRemoved(queryByText(topicCard, messages.addTopicHelpText.defaultMessage));
|
||||
@@ -255,7 +249,7 @@ describe('LegacyConfigForm', () => {
|
||||
|
||||
beforeEach(async () => {
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(defaultAppConfig);
|
||||
createComponent();
|
||||
|
||||
topicCard = await updateTopicName('course', 'edx');
|
||||
duplicateTopicCard = await updateTopicName('13f106c6-6735-4e84-b097-0456cff55960', 'EDX');
|
||||
|
||||
@@ -8,6 +8,7 @@ import { render, queryByLabelText } from '@testing-library/react';
|
||||
|
||||
import AppCard from './AppCard';
|
||||
import messages from './messages';
|
||||
import appMessages from '../app-config-form/messages';
|
||||
import initializeStore from '../../../store';
|
||||
import { executeThunk } from '../../../utils';
|
||||
import { getAppsUrl } from '../data/api';
|
||||
@@ -64,7 +65,7 @@ describe('AppCard', () => {
|
||||
};
|
||||
|
||||
test('checkbox input is checked when AppCard is selected', async () => {
|
||||
const labelText = `Select ${messages[`appName-${app.id}`].defaultMessage}`;
|
||||
const labelText = `Select ${appMessages[`appName-${app.id}`].defaultMessage}`;
|
||||
|
||||
await mockStore(legacyApiResponse);
|
||||
createComponent(app);
|
||||
@@ -78,7 +79,7 @@ describe('AppCard', () => {
|
||||
[false],
|
||||
])('providerName and text from the app are displayed with full support %s', async (hasFullSupport) => {
|
||||
const appWithCustomSupport = { ...app, hasFullSupport };
|
||||
const title = messages[`appName-${appWithCustomSupport.id}`].defaultMessage;
|
||||
const title = appMessages[`appName-${appWithCustomSupport.id}`].defaultMessage;
|
||||
const text = messages[`appDescription-${appWithCustomSupport.id}`].defaultMessage;
|
||||
|
||||
await mockStore(legacyApiResponse);
|
||||
|
||||
@@ -75,6 +75,12 @@ const messages = defineMessages({
|
||||
defaultMessage: 'Ed Discussion helps scale class communication in a beautiful and intuitive interface. Questions reach and benefit the whole class. Less emails, more time saved.',
|
||||
description: 'A description of the Ed discus app.',
|
||||
},
|
||||
// Features
|
||||
'featureName-discussion-page': {
|
||||
id: 'authoring.discussions.featureName-discussion-page',
|
||||
defaultMessage: 'Discussion page',
|
||||
description: 'The name of a discussions feature.',
|
||||
},
|
||||
'featureName-embedded-course-sections': {
|
||||
id: 'authoring.discussions.featureName-embedded-course-sections',
|
||||
defaultMessage: 'Embedded course sections',
|
||||
|
||||
@@ -58,8 +58,8 @@ function normalizePluginConfig(data) {
|
||||
}
|
||||
const discussionDividedTopicsCount = _.size(data.divided_course_wide_discussions);
|
||||
const discussionTopicsCount = _.size(data.discussion_topics);
|
||||
const enableDivideCourseTopicsByCohorts = discussionDividedTopicsCount
|
||||
&& (discussionDividedTopicsCount !== discussionTopicsCount);
|
||||
const enableDivideCourseTopicsByCohorts = Boolean(discussionDividedTopicsCount
|
||||
&& (discussionDividedTopicsCount !== discussionTopicsCount));
|
||||
return {
|
||||
allowAnonymousPosts: data.allow_anonymous,
|
||||
allowAnonymousPostsPeers: data.allow_anonymous_to_peers,
|
||||
|
||||
@@ -14,6 +14,7 @@ import { executeThunk } from '../../../utils';
|
||||
|
||||
const courseId = 'course-v1:edX+TestX+Test_Course';
|
||||
const pagesAndResourcesPath = `/course/${courseId}/pages-and-resources`;
|
||||
|
||||
const featuresState = {
|
||||
'discussion-page': {
|
||||
id: 'discussion-page',
|
||||
@@ -174,9 +175,6 @@ describe('Data layer integration tests', () => {
|
||||
consumerKey: 'client_key_123',
|
||||
consumerSecret: 'client_secret_123',
|
||||
launchUrl: 'https://localhost/example',
|
||||
piiSharing: false,
|
||||
piiShareUsername: undefined,
|
||||
piiShareEmail: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -187,6 +185,7 @@ describe('Data layer integration tests', () => {
|
||||
...piazzaApiResponse.lti_configuration,
|
||||
pii_share_username: true,
|
||||
pii_share_email: false,
|
||||
piiSharing: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -210,9 +209,6 @@ describe('Data layer integration tests', () => {
|
||||
consumerKey: 'client_key_123',
|
||||
consumerSecret: 'client_secret_123',
|
||||
launchUrl: 'https://localhost/example',
|
||||
piiSharing: true,
|
||||
piiShareUsername: true,
|
||||
piiShareEmail: false,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -376,9 +372,6 @@ describe('Data layer integration tests', () => {
|
||||
consumerKey: 'new_consumer_key',
|
||||
consumerSecret: 'new_consumer_secret',
|
||||
launchUrl: 'https://localhost/new_launch_url',
|
||||
piiSharing: false,
|
||||
piiShareUsername: undefined,
|
||||
piiShareEmail: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ export const generatePiazzaApiResponse = (piazzaAdminOnlyConfig = false) => ({
|
||||
},
|
||||
});
|
||||
|
||||
export const legacyApiResponse = {
|
||||
export const generateLegacyApiResponse = () => ({
|
||||
context_key: 'course-v1:edX+DemoX+Demo_Course',
|
||||
enabled: true,
|
||||
provider_type: 'legacy',
|
||||
@@ -143,7 +143,8 @@ export const legacyApiResponse = {
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
});
|
||||
export const legacyApiResponse = generateLegacyApiResponse();
|
||||
|
||||
export const emptyAppApiResponse = {
|
||||
context_key: '',
|
||||
|
||||
Reference in New Issue
Block a user