fix rubric selector tests and add app thunkAction tests
This commit is contained in:
@@ -109,7 +109,7 @@ describe('app selectors unit tests', () => {
|
||||
testOraSelector(selectors.ora.type, oraMetadata.type);
|
||||
});
|
||||
test('rubricConfig selector returns rubricConfig from oraMetadata', () => {
|
||||
testOraSelector(selectors.rubricConfig, oraMetadata.rubricConfig);
|
||||
testOraSelector(selectors.rubric.config, oraMetadata.rubricConfig);
|
||||
});
|
||||
});
|
||||
describe('rubricConfig selectors', () => {
|
||||
@@ -117,7 +117,7 @@ describe('app selectors unit tests', () => {
|
||||
const testRubricSelector = (selector, expected, args = null) => (
|
||||
testReselect({
|
||||
selector,
|
||||
preSelectors: [selectors.rubricConfig],
|
||||
preSelectors: [selectors.rubric.config],
|
||||
args: args === null ? rubricConfig : args,
|
||||
expected,
|
||||
})
|
||||
@@ -125,13 +125,13 @@ describe('app selectors unit tests', () => {
|
||||
test('hasConfig', () => {
|
||||
testReselect({
|
||||
selector: rubric.hasConfig,
|
||||
preSelectors: [selectors.rubricConfig],
|
||||
preSelectors: [selectors.rubric.config],
|
||||
args: rubricConfig,
|
||||
expected: true,
|
||||
});
|
||||
testReselect({
|
||||
selector: rubric.hasConfig,
|
||||
preSelectors: [selectors.rubricConfig],
|
||||
preSelectors: [selectors.rubric.config],
|
||||
args: undefined,
|
||||
expected: false,
|
||||
});
|
||||
|
||||
@@ -2,7 +2,7 @@ import { StrictDict } from 'utils';
|
||||
|
||||
import actions from 'data/actions';
|
||||
import api from 'data/services/lms/api';
|
||||
import { locationId } from '../constants/app';
|
||||
import { locationId } from 'data/constants/app';
|
||||
|
||||
/**
|
||||
* initialize the app, loading ora and course metadata from the api, and loading the initial
|
||||
|
||||
53
src/data/thunkActions/app.test.js
Normal file
53
src/data/thunkActions/app.test.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import api from 'data/services/lms/api';
|
||||
import { locationId } from 'data/constants/app';
|
||||
|
||||
import actions from 'data/actions';
|
||||
import thunkActions from './app';
|
||||
|
||||
jest.mock('data/services/lms/api', () => {
|
||||
const response = {
|
||||
oraMetadata: { some: 'ora-metadata' },
|
||||
courseMetadata: { some: 'course-metadata' },
|
||||
submissions: { some: 'submissions' },
|
||||
};
|
||||
return {
|
||||
response,
|
||||
initializeApp: jest.fn(() => new Promise((resolve) => resolve(response))),
|
||||
};
|
||||
});
|
||||
jest.mock('data/constants/app', () => ({
|
||||
locationId: 'fake-location-id',
|
||||
}));
|
||||
jest.mock('data/actions', () => ({
|
||||
app: {
|
||||
loadOraMetadata: (data) => ({ loadOraMetadata: data }),
|
||||
loadCourseMetadata: (data) => ({ loadCourseMetadata: data }),
|
||||
},
|
||||
submissions: {
|
||||
loadList: (data) => ({ loadList: data }),
|
||||
},
|
||||
}));
|
||||
|
||||
describe('app thunkActions', () => {
|
||||
let dispatch;
|
||||
beforeEach(() => {
|
||||
dispatch = jest.fn((action) => ({ dispatch: action }));
|
||||
});
|
||||
describe('initialize', () => {
|
||||
beforeEach(() => {
|
||||
thunkActions.initialize()(dispatch);
|
||||
});
|
||||
test('it is called with location id from constants/app', () => {
|
||||
expect(api.initializeApp).toHaveBeenCalledWith(locationId);
|
||||
});
|
||||
describe('on success', () => {
|
||||
test('loads oraMetadata, courseMetadata and list data', () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.app.loadOraMetadata(api.response.oraMetadata)],
|
||||
[actions.app.loadCourseMetadata(api.response.courseMetadata)],
|
||||
[actions.submissions.loadList(api.response.submissions)],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user