[TNL-7268] refactor tests to use factories
This commit is contained in:
@@ -49,13 +49,13 @@ export default function buildSimpleCourseBlocks(courseId, title, numUnits = 1) {
|
||||
{ type: 'chapter', children: [sequenceBlock.id] },
|
||||
{ courseId },
|
||||
);
|
||||
const courseBlock = Factory.build(
|
||||
const courseBlock = options.courseBlocks || Factory.build(
|
||||
'block',
|
||||
{ type: 'course', display_name: title, children: [sectionBlock.id] },
|
||||
{ courseId },
|
||||
);
|
||||
return {
|
||||
courseBlocks: Factory.build(
|
||||
courseBlocks: options.courseBlocks || Factory.build(
|
||||
'courseBlocks',
|
||||
{ courseId },
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Factory } from 'rosie'; // eslint-disable-line import/no-extraneous-dependencies
|
||||
|
||||
import './block.factory';
|
||||
import buildSimpleCourseBlocks from './courseBlocks.factory';
|
||||
|
||||
Factory.define('sequenceMetadata')
|
||||
.option('courseId', (courseId) => {
|
||||
@@ -33,8 +33,8 @@ Factory.define('sequenceMetadata')
|
||||
.attr('gated_content', ['sequenceBlock'], sequenceBlock => ({
|
||||
gated: false,
|
||||
prereq_url: null,
|
||||
prereq_id: null,
|
||||
prereq_section_name: null,
|
||||
prereq_id: `${sequenceBlock.id}-prereq`,
|
||||
prereq_section_name: `${sequenceBlock.display_name}-prereq`,
|
||||
gated_section_name: sequenceBlock.display_name,
|
||||
}))
|
||||
.attr('items', ['unitBlocks', 'sequenceBlock'], (unitBlocks, sequenceBlock) => unitBlocks.map(
|
||||
@@ -42,10 +42,10 @@ Factory.define('sequenceMetadata')
|
||||
href: '',
|
||||
graded: unitBlock.graded,
|
||||
id: unitBlock.id,
|
||||
bookmarked: false,
|
||||
bookmarked: unitBlock.bookmarked || false,
|
||||
path: `Chapter Display Name > ${sequenceBlock.display_name} > ${unitBlock.display_name}`,
|
||||
type: 'other',
|
||||
complete: null,
|
||||
type: unitBlock.type,
|
||||
complete: unitBlock.complete || null,
|
||||
content: '',
|
||||
page_title: unitBlock.display_name,
|
||||
}),
|
||||
@@ -61,3 +61,30 @@ Factory.define('sequenceMetadata')
|
||||
show_completion: true,
|
||||
banner_text: null,
|
||||
});
|
||||
|
||||
/**
|
||||
* Build a simple course and simple metadata for its sequence.
|
||||
*/
|
||||
export default function buildSimpleCourseAndSequenceMetadata(options = {}) {
|
||||
const courseMetadata = options.courseMetadata || Factory.build('courseMetadata', {
|
||||
can_load_courseware: {
|
||||
has_access: false,
|
||||
},
|
||||
});
|
||||
const courseId = courseMetadata.id;
|
||||
const simpleCourseBlocks = buildSimpleCourseBlocks(courseId, courseMetadata.name, options);
|
||||
const { unitBlocks, sequenceBlock } = simpleCourseBlocks;
|
||||
const sequenceMetadata = options.sequenceMetadata || sequenceBlock.map(block => Factory.build(
|
||||
'sequenceMetadata',
|
||||
{ courseId },
|
||||
{
|
||||
unitBlocks,
|
||||
sequenceBlock: block,
|
||||
},
|
||||
));
|
||||
return {
|
||||
...simpleCourseBlocks,
|
||||
courseMetadata,
|
||||
sequenceMetadata,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import * as thunks from './thunks';
|
||||
import executeThunk from '../../utils';
|
||||
|
||||
import buildSimpleCourseBlocks from './__factories__/courseBlocks.factory';
|
||||
import './__factories__';
|
||||
import initializeMockApp from '../../setupTest';
|
||||
import initializeStore from '../../store';
|
||||
|
||||
@@ -29,7 +28,7 @@ describe('Data layer integration tests', () => {
|
||||
const sequenceMetadata = Factory.build(
|
||||
'sequenceMetadata',
|
||||
{},
|
||||
{ courseId, unitBlocks, sequenceBlock },
|
||||
{ courseId, unitBlocks: [unitBlock], sequenceBlock },
|
||||
);
|
||||
|
||||
const courseUrl = `${courseBaseUrl}/${courseId}`;
|
||||
@@ -124,13 +123,13 @@ describe('Data layer integration tests', () => {
|
||||
// ensure that initial state has no additional sequence info
|
||||
let state = store.getState();
|
||||
expect(state.models.sequences).toEqual({
|
||||
[sequenceBlock.id]: expect.not.objectContaining({
|
||||
[sequenceId]: expect.not.objectContaining({
|
||||
gatedContent: expect.any(Object),
|
||||
activeUnitIndex: expect.any(Number),
|
||||
}),
|
||||
});
|
||||
expect(state.models.units).toEqual({
|
||||
[unitBlock.id]: expect.not.objectContaining({
|
||||
[unitId]: expect.not.objectContaining({
|
||||
complete: null,
|
||||
bookmarked: expect.any(Boolean),
|
||||
}),
|
||||
@@ -144,20 +143,20 @@ describe('Data layer integration tests', () => {
|
||||
expect(state.courseware.sequenceStatus).toEqual('loading');
|
||||
expect(state.courseware.sequenceId).toEqual(null);
|
||||
|
||||
await executeThunk(thunks.fetchSequence(sequenceBlock.id), store.dispatch);
|
||||
await executeThunk(thunks.fetchSequence(sequenceId), store.dispatch);
|
||||
|
||||
// Update our state variable again.
|
||||
state = store.getState();
|
||||
|
||||
// ensure that additional information appeared in store
|
||||
expect(state.models.sequences).toEqual({
|
||||
[sequenceBlock.id]: expect.objectContaining({
|
||||
[sequenceId]: expect.objectContaining({
|
||||
gatedContent: expect.any(Object),
|
||||
activeUnitIndex: expect.any(Number),
|
||||
}),
|
||||
});
|
||||
expect(state.models.units).toEqual({
|
||||
[unitBlock.id]: expect.objectContaining({
|
||||
[unitId]: expect.objectContaining({
|
||||
complete: null,
|
||||
bookmarked: expect.any(Boolean),
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user