Chore: Test coverage hunt (#36)
* chore: add brand mocking in gallery view * feat: dev gallery app * chore: link mock block ids to real block type api * feat: image settings page features * chore: more tests * chore: keystore util and more testing * chore: more tests * chore: re-install lint plugin... * chore: lint fixes * chore: moar tests * chore: remove brand from module.config and link gallery to edx.org brand
This commit is contained in:
9
src/editors/data/constants/tinyMCE.js
Normal file
9
src/editors/data/constants/tinyMCE.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import { StrictDict } from '../../utils';
|
||||
|
||||
const commands = StrictDict({
|
||||
insertContent: 'mceInsertContent',
|
||||
});
|
||||
|
||||
export default StrictDict({
|
||||
commands,
|
||||
});
|
||||
@@ -46,6 +46,16 @@ describe('app reducer', () => {
|
||||
['setBlockTitle', 'blockTitle'],
|
||||
['setSaveResponse', 'saveResponse'],
|
||||
].map(args => setterTest(...args));
|
||||
describe('setBlockValue', () => {
|
||||
it('sets blockValue, as well as setting the blockTitle from data.display_name', () => {
|
||||
const blockValue = { data: { display_name: 'my test name' }, other: 'data' };
|
||||
expect(reducer(testingState, actions.setBlockValue(blockValue))).toEqual({
|
||||
...testingState,
|
||||
blockValue,
|
||||
blockTitle: blockValue.data.display_name,
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('initializeEditor', () => {
|
||||
it('sets editorInitialized to true', () => {
|
||||
expect(reducer(testingState, actions.initializeEditor())).toEqual({
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// import * in order to mock in-file references
|
||||
import { keyStore } from '../../../utils';
|
||||
import * as urls from '../../services/cms/urls';
|
||||
import * as selectors from './selectors';
|
||||
|
||||
@@ -30,17 +31,19 @@ describe('app selectors unit tests', () => {
|
||||
expect(cb({ ...testState, [key]: testValue })).toEqual(testValue);
|
||||
});
|
||||
};
|
||||
const simpleKeys = keyStore(simpleSelectors);
|
||||
describe('simple selectors link their values from app store', () => {
|
||||
[
|
||||
'blockContent',
|
||||
'blockId',
|
||||
'blockType',
|
||||
'blockValue',
|
||||
'courseId',
|
||||
'editorInitialized',
|
||||
'saveResponse',
|
||||
'studioEndpointUrl',
|
||||
'unitUrl',
|
||||
simpleKeys.blockContent,
|
||||
simpleKeys.blockId,
|
||||
simpleKeys.blockTitle,
|
||||
simpleKeys.blockType,
|
||||
simpleKeys.blockValue,
|
||||
simpleKeys.courseId,
|
||||
simpleKeys.editorInitialized,
|
||||
simpleKeys.saveResponse,
|
||||
simpleKeys.studioEndpointUrl,
|
||||
simpleKeys.unitUrl,
|
||||
].map(testSimpleSelector);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,50 +36,88 @@ describe('requests thunkActions module', () => {
|
||||
const testData = ({ some: 'test data' });
|
||||
let resolveFn;
|
||||
let rejectFn;
|
||||
beforeEach(() => {
|
||||
onSuccess = jest.fn();
|
||||
onFailure = jest.fn();
|
||||
requests.networkRequest({
|
||||
requestKey,
|
||||
promise: new Promise((resolve, reject) => {
|
||||
resolveFn = resolve;
|
||||
rejectFn = reject;
|
||||
}),
|
||||
onSuccess,
|
||||
onFailure,
|
||||
})(dispatch);
|
||||
});
|
||||
test('calls startRequest action with requestKey', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([[actions.requests.startRequest(requestKey)]]);
|
||||
});
|
||||
describe('on success', () => {
|
||||
beforeEach(async () => {
|
||||
await resolveFn(testData);
|
||||
describe('without success and failure handlers', () => {
|
||||
beforeEach(() => {
|
||||
requests.networkRequest({
|
||||
requestKey,
|
||||
promise: new Promise((resolve, reject) => {
|
||||
resolveFn = resolve;
|
||||
rejectFn = reject;
|
||||
}),
|
||||
})(dispatch);
|
||||
});
|
||||
it('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.completeRequest({ requestKey, response: testData })],
|
||||
]);
|
||||
test('calls startRequest action with requestKey', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([[actions.requests.startRequest(requestKey)]]);
|
||||
});
|
||||
it('calls onSuccess with response', async () => {
|
||||
expect(onSuccess).toHaveBeenCalledWith(testData);
|
||||
expect(onFailure).not.toHaveBeenCalled();
|
||||
describe('on success', () => {
|
||||
beforeEach(async () => {
|
||||
await resolveFn(testData);
|
||||
});
|
||||
it('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.completeRequest({ requestKey, response: testData })],
|
||||
]);
|
||||
});
|
||||
});
|
||||
describe('on failure', () => {
|
||||
beforeEach(async () => {
|
||||
await rejectFn(testData);
|
||||
});
|
||||
test('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.failRequest({ requestKey, error: testData })],
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('on failure', () => {
|
||||
beforeEach(async () => {
|
||||
await rejectFn(testData);
|
||||
describe('with handlers', () => {
|
||||
beforeEach(() => {
|
||||
onSuccess = jest.fn();
|
||||
onFailure = jest.fn();
|
||||
requests.networkRequest({
|
||||
requestKey,
|
||||
promise: new Promise((resolve, reject) => {
|
||||
resolveFn = resolve;
|
||||
rejectFn = reject;
|
||||
}),
|
||||
onSuccess,
|
||||
onFailure,
|
||||
})(dispatch);
|
||||
});
|
||||
test('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.failRequest({ requestKey, error: testData })],
|
||||
]);
|
||||
test('calls startRequest action with requestKey', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([[actions.requests.startRequest(requestKey)]]);
|
||||
});
|
||||
test('calls onSuccess with response', async () => {
|
||||
expect(onFailure).toHaveBeenCalledWith(testData);
|
||||
expect(onSuccess).not.toHaveBeenCalled();
|
||||
describe('on success', () => {
|
||||
beforeEach(async () => {
|
||||
await resolveFn(testData);
|
||||
});
|
||||
it('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.completeRequest({ requestKey, response: testData })],
|
||||
]);
|
||||
});
|
||||
it('calls onSuccess with response', async () => {
|
||||
expect(onSuccess).toHaveBeenCalledWith(testData);
|
||||
expect(onFailure).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
describe('on failure', () => {
|
||||
beforeEach(async () => {
|
||||
await rejectFn(testData);
|
||||
});
|
||||
test('dispatches completeRequest', async () => {
|
||||
expect(dispatch.mock.calls).toEqual([
|
||||
[actions.requests.startRequest(requestKey)],
|
||||
[actions.requests.failRequest({ requestKey, error: testData })],
|
||||
]);
|
||||
});
|
||||
test('calls onFailure with response', async () => {
|
||||
expect(onFailure).toHaveBeenCalledWith(testData);
|
||||
expect(onSuccess).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable import/no-extraneous-dependencies */
|
||||
/* istanbul ignore file */
|
||||
import configureMockStore from 'redux-mock-store';
|
||||
import thunk from 'redux-thunk';
|
||||
|
||||
|
||||
@@ -50,8 +50,6 @@ export const apiMethods = {
|
||||
|
||||
export const checkMockApi = (key) => {
|
||||
if (process.env.REACT_APP_DEVGALLERY) {
|
||||
// eslint-disable-next-line
|
||||
console.log('use devgallery api methods');
|
||||
return mockApi[key];
|
||||
}
|
||||
return module.apiMethods[key];
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* istanbul ignore file */
|
||||
|
||||
import * as urls from './urls';
|
||||
|
||||
const mockPromise = (returnValue) => new Promise(resolve => resolve(returnValue));
|
||||
|
||||
Reference in New Issue
Block a user