Skip to content

Commit

Permalink
update sectionProgressReduxTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Erin007 committed May 8, 2018
1 parent 2144e05 commit 1a3a1a2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/src/templates/sectionProgress/ScriptSelector.js
Expand Up @@ -46,7 +46,7 @@ export default class ScriptSelector extends Component {
return (
<div>
<select
value={scriptId || ""}
value={scriptId}
onChange={event => onChange(parseInt(event.target.value))}
style={styles.dropdown}
>
Expand Down
7 changes: 5 additions & 2 deletions apps/src/templates/sectionProgress/sectionProgressRedux.js
Expand Up @@ -90,6 +90,8 @@ export const ViewType = {
DETAIL: "detail",
};

export const ACCELERATED_SCRIPT_ID = 1;

/**
* Shape for the section
* The section we get directly from angular right now. This gives us a
Expand Down Expand Up @@ -203,9 +205,10 @@ export default function sectionProgress(state=initialState, action) {

let validScripts = action.validScripts;
if (action.studentScriptIds && action.validCourses) {
// Include the id for the Accelerated Course so that there will always be // at least one validScript and we don't end up with an empty dropdown.
const idMap = {ACCELERATED_SCRIPT_ID: true};
// First, construct an id map consisting only of script ids which a
// student has participated in.
const idMap = {1: true};
action.studentScriptIds.forEach(id => idMap[id] = true);

// If the student has participated in a script which is a unit in a
Expand Down Expand Up @@ -240,7 +243,7 @@ export default function sectionProgress(state=initialState, action) {
scriptId = validScripts[0].id;
break;
default:
scriptId = 1;
scriptId = ACCELERATED_SCRIPT_ID;
}
}

Expand Down
Expand Up @@ -10,6 +10,7 @@ import sectionProgress, {
setLessonOfInterest,
startLoadingProgress,
finishLoadingProgress,
ACCELERATED_SCRIPT_ID,
} from '@cdo/apps/templates/sectionProgress/sectionProgressRedux';

const fakeSectionData = {
Expand Down Expand Up @@ -172,23 +173,26 @@ describe('sectionProgressRedux', () => {
});

describe('setValidScripts', () => {
it('sets the script data and defaults scriptId', () => {
const action = setValidScripts(fakeValidScripts);
const nextState = sectionProgress(initialState, action);
assert.deepEqual(nextState.validScripts, fakeValidScripts);
assert.deepEqual(nextState.scriptId, fakeValidScripts[0].id);
});

it('sets the script data and does not override already assigned scriptId', () => {
const action = setValidScripts(fakeValidScripts);
it('does not override already assigned scriptId', () => {
const studentScriptIds = [];
const validCourses = [];
const action = setValidScripts(fakeValidScripts, studentScriptIds, validCourses);
const nextState = sectionProgress({
...initialState,
scriptId: 100
}, action);
assert.deepEqual(nextState.validScripts, fakeValidScripts);
assert.deepEqual(nextState.scriptId, 100);
});

it('filtered validScripts includes Accelerated script id by default', () => {
const studentScriptIds = [];
const validCourses = [];
const action = setValidScripts(fakeValidScripts, studentScriptIds, validCourses);
const nextState = sectionProgress(initialState, action);
assert.deepEqual(nextState.validScripts, fakeValidScripts.filter(script => script.id === ACCELERATED_SCRIPT_ID));
});

it('filters validScripts to those included in studentScriptIds', () => {
const studentScriptIds = [456];
const validCourses = [];
Expand Down

0 comments on commit 1a3a1a2

Please sign in to comment.