Skip to content

Commit

Permalink
test: Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davidnuon committed Jul 31, 2023
1 parent 0badc4e commit a43ed0b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import PagesAndResourcesProvider from '../PagesAndResourcesProvider';
import { XpertUnitSummarySettings } from './index';
import initializeStore from '../../store';
import * as API from './data/api';
import * as Thunks from './data/thunks';
import { executeThunk } from '../../utils';

const courseId = 'course-v1:edX+TestX+Test_Course';
let axiosMock;
Expand Down Expand Up @@ -95,7 +97,7 @@ describe('XpertUnitSummarySettings', () => {
});
axiosMock = new MockAdapter(getAuthenticatedHttpClient());

// Leave the DiscussionsSettings route after the test.
// Go back to settings route
history.push('/xpert-unit-summary/settings');
});

Expand Down Expand Up @@ -146,25 +148,42 @@ describe('XpertUnitSummarySettings', () => {
expect(queryByTestId(container, 'enable-badge')).not.toBeTruthy();
});
});
});

describe('saving configuration changes', () => {
beforeEach(() => {
axiosMock.onPost(API.getXpertSettingsUrl(courseId))
.reply(200, generateCourseLevelAPIRepsonse({
success: true,
enabled: true,
}));
describe('saving configuration changes', () => {
beforeEach(() => {
axiosMock.onPost(API.getXpertSettingsUrl(courseId))
.reply(200, generateCourseLevelAPIRepsonse({
success: true,
enabled: true,
}));

renderComponent();
});

renderComponent();
test('Saving configuration changes', async () => {
jest.spyOn(API, 'postXpertSettings');

await waitFor(() => expect(container.querySelector('#enable-xpert-unit-summary-toggle')).toBeTruthy());
fireEvent.click(getByText(container, 'Save'));
await waitFor(() => expect(container.querySelector('#enable-xpert-unit-summary-toggle')).not.toBeTruthy());
expect(API.postXpertSettings).toBeCalled();
});
});

test('Saving configuration changes', async () => {
jest.spyOn(API, 'postXpertSettings');
describe('testing configurable gating', () => {
beforeEach(async () => {
axiosMock.onGet(API.getXpertConfigurationStatusUrl(courseId))
.reply(200, generateCourseLevelAPIRepsonse({
success: true,
enabled: true,
}));
jest.spyOn(API, 'getXpertPluginConfigurable');
await executeThunk(Thunks.fetchXpertPluginConfigurable(courseId), store.dispatch);
renderComponent();
});

await waitFor(() => expect(container.querySelector('#enable-xpert-unit-summary-toggle')).toBeTruthy());
fireEvent.click(getByText(container, 'Save'));
await waitFor(() => expect(container.querySelector('#enable-xpert-unit-summary-toggle')).not.toBeTruthy());
expect(API.postXpertSettings).toBeCalled();
test('getting Xpert Plugin configurable status', () => {
expect(API.getXpertPluginConfigurable).toBeCalled();
});
});
});
1 change: 0 additions & 1 deletion src/pages-and-resources/xpert-unit-summary/data/thunks.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export function fetchXpertPluginConfigurable(courseId) {
dispatch(updateLoadingStatus({ status: RequestStatus.PENDING }));
try {
const { response } = await getXpertPluginConfigurable(courseId);

enabled = response?.enabled;
} catch (e) {
enabled = false;
Expand Down

0 comments on commit a43ed0b

Please sign in to comment.