Skip to content

Commit

Permalink
Merge pull request #40931 from code-dot-org/random-stage-to-lesson-3
Browse files Browse the repository at this point in the history
More more more changes of stage to lesson
  • Loading branch information
dmcavoy committed Jun 3, 2021
2 parents c639367 + c1c6ff4 commit 6b7260b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 70 deletions.
10 changes: 5 additions & 5 deletions apps/src/code-studio/components/TeacherContentToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,20 @@ class TeacherContentToggle extends React.Component {
contentStyle.display = 'none';
}

const showLockedStageMessage = isLockedLesson && !isHiddenLesson;
const showHiddenStageMessage = isHiddenLesson;
const showLockedLessonMessage = isLockedLesson && !isHiddenLesson;
const showHiddenLessonMessage = isHiddenLesson;

// Note: This component depends on the fact that the only thing we change about
// our children as we rerender is their style.
return (
<div style={styles.container}>
<div style={contentStyle} ref="content" />
<div
style={[frameStyle, !showLockedStageMessage && styles.hidden]}
style={[frameStyle, !showLockedLessonMessage && styles.hidden]}
ref="lockMessage"
/>
<div
style={[frameStyle, !showHiddenStageMessage && styles.hidden]}
style={[frameStyle, !showHiddenLessonMessage && styles.hidden]}
ref="hiddenMessage"
/>
</div>
Expand Down Expand Up @@ -139,7 +139,7 @@ export const mapStateToProps = state => {
} else if (!state.verifiedTeacher.isVerified) {
// if not-authorized teacher
isLockedLesson = state.progress.stages.some(
stage => stage.id === currentLessonId && stage.lockable
lesson => lesson.id === currentLessonId && lesson.lockable
);
}

Expand Down
2 changes: 1 addition & 1 deletion apps/src/sites/studio/pages/levels/_teacher_panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function initPage() {
if (teacherPanelData.is_verified_teacher) {
store.dispatch(setVerified());
}
// Stage Extras fail to load with this
// Lesson Extras fail to load with this
if (!teacherPanelData.lesson_extra) {
renderTeacherContentToggle(store);
}
Expand Down
12 changes: 6 additions & 6 deletions apps/src/templates/progress/progressHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function lessonIsLockedForUser(lesson, levels, state, viewAs) {
} else if (viewAs === ViewType.Teacher) {
return !state.lessonLock.lockableAuthorized;
} else if (viewAs === ViewType.Student) {
return stageLocked(levels);
return lessonLocked(levels);
}
return true;
}
Expand All @@ -74,16 +74,16 @@ export function lessonIsLockedForUser(lesson, levels, state, viewAs) {
export function lessonIsLockedForAllStudents(lessonId, state) {
const currentSectionId = state.teacherSections.selectedSectionId;
const currentSection = state.lessonLock.lessonsBySectionId[currentSectionId];
const fullyLockedStages = fullyLockedLessonMapping(currentSection);
return !!fullyLockedStages[lessonId];
const fullyLockedLessons = fullyLockedLessonMapping(currentSection);
return !!fullyLockedLessons[lessonId];
}

/**
* @param {level[]} levels - A set of levels for a given lesson
* @returns {boolean} True if we should consider the lesson to be locked for the
* current user.
*/
export function stageLocked(levels) {
export function lessonLocked(levels) {
// For lockable lessons, there is a requirement that they have exactly one LevelGroup,
// and that it be the last level in the lesson. Because LevelGroup's can have
// multiple "pages", and single LevelGroup might appear as multiple levels/bubbles
Expand Down Expand Up @@ -244,8 +244,8 @@ export function lessonProgressForSection(sectionLevelProgress, lessons) {

/**
* The level object passed down to use via the server (and stored in
* script.stages.levels) contains more data than we need. This parses the parts
* we care about to conform to our `levelType` oject.
* script.lessons.levels) contains more data than we need. This parses the parts
* we care about to conform to our `levelType` object.
*/
export const processedLevel = level => {
return {
Expand Down
92 changes: 46 additions & 46 deletions apps/test/unit/code-studio/TeacherContentToggleTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,24 @@ describe('TeacherContentToggle', () => {
// has unhidden the original DOM element
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

assert.equal(contentElement.childNodes[0].getAttribute('id'), 'level-body');
assert.equal(contentElement.childNodes[0].style.display, '');

assert.equal(
lockedStageElement.childNodes[0].getAttribute('id'),
lockedLessonElement.childNodes[0].getAttribute('id'),
'locked-lesson'
);
assert.equal(lockedStageElement.childNodes[0].style.display, '');
assert.equal(lockedLessonElement.childNodes[0].style.display, '');

assert.equal(
hiddenStageElement.childNodes[0].getAttribute('id'),
hiddenLessonElement.childNodes[0].getAttribute('id'),
'hidden-lesson'
);
assert.equal(hiddenStageElement.childNodes[0].style.display, '');
assert.equal(hiddenLessonElement.childNodes[0].style.display, '');
});

it('shows content immediately when viewAs Teacher', () => {
Expand All @@ -90,14 +90,14 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, '');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, 'none');
});

it('shows content after async calls when Teacher is authorized', () => {
Expand All @@ -116,14 +116,14 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, '');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, 'none');
});

it('shows lock message after async calls when Teacher is unauthorized', () => {
Expand All @@ -142,14 +142,14 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

assert.equal(contentElement.style.display, 'none');
assert.equal(contentElement.style.visibility, '');
assert.equal(lockedStageElement.style.display, '');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, '');
assert.equal(hiddenLessonElement.style.display, 'none');
});

it('does not initially show anything when viewAs Student', () => {
Expand All @@ -168,15 +168,15 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

// nothing visible
assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, 'none');
});

it('does show hidden lesson message once initialized when viewAs Student', () => {
Expand All @@ -200,30 +200,30 @@ describe('TeacherContentToggle', () => {
let root = $(component.html());
let [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

// content is hidden, hiddenLesson is visible
assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, '');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, '');

component.setProps({
isBlocklyOrDroplet: false
});
root = $(component.html());
[
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();
// same thing, but we also set display:none on content
assert.equal(contentElement.style.display, 'none');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, '');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, '');
});

it('does show locked lesson message once initialized when viewAs Student', () => {
Expand All @@ -247,30 +247,30 @@ describe('TeacherContentToggle', () => {
let root = $(component.html());
let [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

// content is hidden, hiddenLesson is visible
assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, '');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, '');
assert.equal(hiddenLessonElement.style.display, 'none');

component.setProps({
isBlocklyOrDroplet: false
});
root = $(component.html());
[
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();
// same thing, but we also set display:none on content
assert.equal(contentElement.style.display, 'none');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, '');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, '');
assert.equal(hiddenLessonElement.style.display, 'none');
});

it('shows hidden message when viewAs student if locked and hidden', () => {
Expand All @@ -296,15 +296,15 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

// content is hidden, hiddenLesson is visible
assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, 'hidden');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, '');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, '');

component.setProps({
isBlocklyOrDroplet: false
Expand Down Expand Up @@ -334,15 +334,15 @@ describe('TeacherContentToggle', () => {
const root = $(component.html());
const [
contentElement,
lockedStageElement,
hiddenStageElement
lockedLessonElement,
hiddenLessonElement
] = root.children().toArray();

// content is hidden, hiddenLesson is visible
assert.equal(contentElement.style.display, '');
assert.equal(contentElement.style.visibility, '');
assert.equal(lockedStageElement.style.display, 'none');
assert.equal(hiddenStageElement.style.display, 'none');
assert.equal(lockedLessonElement.style.display, 'none');
assert.equal(hiddenLessonElement.style.display, 'none');

component.setProps({
isBlocklyOrDroplet: false
Expand Down
6 changes: 3 additions & 3 deletions apps/test/unit/code-studio/progressReduxTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const lessonData = [
id: 264,
position: 1,
name: 'Computational Thinking',
title: 'Stage 1: Computational Thinking',
title: 'Lesson 1: Computational Thinking',
lesson_group_display_name: null,
lockable: false,
levels: [
Expand Down Expand Up @@ -103,7 +103,7 @@ const lessonData = [
id: 265,
position: 2,
name: 'Maze',
title: 'Stage 2: Maze',
title: 'Lesson 2: Maze',
lesson_group_display_name: null,
lockable: false,
levels: [
Expand Down Expand Up @@ -168,7 +168,7 @@ const lockableLessonData = [
id: 264,
position: 1,
name: 'Computational Thinking',
title: 'Stage 1: Computational Thinking',
title: 'Lesson 1: Computational Thinking',
lesson_group_display_name: null,
lockable: true,
levels: [
Expand Down
12 changes: 6 additions & 6 deletions apps/test/unit/templates/progress/progressHelpersTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
lessonIsLockedForUser,
lessonIsLockedForAllStudents,
getIconForLevel,
stageLocked,
lessonLocked,
lessonProgressForSection,
isLevelAssessment,
lessonIsAllAssessment
Expand Down Expand Up @@ -143,7 +143,7 @@ describe('progressHelpers', () => {
);
});

it('returns true for lockable lesson for stageLocked', () => {
it('returns true for lockable lesson for lessonLocked', () => {
assert.strictEqual(
lessonIsLockedForUser(
lockableLesson,
Expand Down Expand Up @@ -221,13 +221,13 @@ describe('progressHelpers', () => {
});
});

describe('stageLocked', () => {
describe('lessonLocked', () => {
it('returns true when we only have a level group and it is locked', () => {
const levels = fakeLevels(3).map((level, index) => ({
...level,
isLocked: index === 2 // lock last level in level group
}));
assert.strictEqual(true, stageLocked(levels));
assert.strictEqual(true, lessonLocked(levels));
});

describe('level group preceeded by another level', () => {
Expand All @@ -244,11 +244,11 @@ describe('progressHelpers', () => {
isLocked: index === 3 // lock last level in level group
}));

assert.strictEqual(true, stageLocked(levels));
assert.strictEqual(true, lessonLocked(levels));
});

it('returns false when level group is not locked', () => {
assert.strictEqual(false, stageLocked(baseLevels));
assert.strictEqual(false, lessonLocked(baseLevels));
});
});
});
Expand Down
1 change: 0 additions & 1 deletion dashboard/app/models/script.rb
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ def get_bonus_script_levels(current_lesson)
summarized_lesson_levels = lesson_levels.map do |lesson|
{
lessonNumber: lesson[:lessonNumber],
stageNumber: lesson[:lessonNumber], #TODO: remove once launched
levels: lesson[:levels].map(&:summarize_as_bonus)
}
end
Expand Down

0 comments on commit 6b7260b

Please sign in to comment.