2016-03-30 16:57:19 -04:00
|
|
|
helper = require 'lib/coursesHelper'
|
|
|
|
Campaigns = require 'collections/Campaigns'
|
|
|
|
Users = require 'collections/Users'
|
|
|
|
Courses = require 'collections/Courses'
|
|
|
|
CourseInstances = require 'collections/CourseInstances'
|
|
|
|
Classrooms = require 'collections/Classrooms'
|
2016-05-03 13:38:20 -04:00
|
|
|
Levels = require 'collections/Levels'
|
|
|
|
LevelSessions = require 'collections/LevelSessions'
|
|
|
|
factories = require 'test/app/factories'
|
2016-03-30 16:57:19 -04:00
|
|
|
|
2016-04-07 17:51:02 -04:00
|
|
|
describe 'CoursesHelper', ->
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
describe 'calculateAllProgress', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
# classrooms, courses, campaigns, courseInstances, students
|
2016-05-03 13:38:20 -04:00
|
|
|
@course = factories.makeCourse()
|
|
|
|
@courses = new Courses([@course])
|
|
|
|
@members = new Users(_.times(2, -> factories.makeUser()))
|
|
|
|
@levels = new Levels(_.times(2, -> factories.makeLevel()))
|
|
|
|
|
|
|
|
@classroom = factories.makeClassroom({}, { @courses, @members, levels: [@levels] })
|
2016-04-07 17:51:02 -04:00
|
|
|
@classrooms = new Classrooms([ @classroom ])
|
2016-05-03 13:38:20 -04:00
|
|
|
|
|
|
|
courseInstance = factories.makeCourseInstance({}, { @course, @classroom, @members })
|
|
|
|
@courseInstances = new CourseInstances([courseInstance])
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
describe 'when all students have completed a course', ->
|
|
|
|
beforeEach ->
|
2016-05-03 13:38:20 -04:00
|
|
|
sessions = []
|
|
|
|
for level in @levels.models
|
|
|
|
for creator in @members.models
|
|
|
|
sessions.push(factories.makeLevelSession({state: {complete: true}}, { level, creator }))
|
|
|
|
@classroom.sessions = new LevelSessions(sessions)
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
describe 'progressData.get({classroom, course})', ->
|
|
|
|
it 'returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course}
|
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'progressData.get({classroom, course, level, user})', ->
|
|
|
|
it 'returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
for student in @members.models
|
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course, user: student}
|
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'progressData.get({classroom, course, level, user})', ->
|
|
|
|
it 'returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
for level in @levels.models
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course, level}
|
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'progressData.get({classroom, course, level, user})', ->
|
|
|
|
it 'returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
for level in @levels.models
|
|
|
|
for user in @members.models
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course, level, user}
|
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'when NOT all students have completed a course', ->
|
|
|
|
|
|
|
|
beforeEach ->
|
2016-05-03 13:38:20 -04:00
|
|
|
sessions = []
|
|
|
|
@finishedMember = @members.first()
|
|
|
|
@unfinishedMember = @members.last()
|
|
|
|
for level in @levels.models
|
|
|
|
sessions.push(factories.makeLevelSession(
|
|
|
|
{state: {complete: true}},
|
|
|
|
{level, creator: @finishedMember})
|
|
|
|
)
|
|
|
|
sessions.push(factories.makeLevelSession(
|
|
|
|
{state: {complete: false}},
|
|
|
|
{level: @levels.first(), creator: @unfinishedMember})
|
|
|
|
)
|
|
|
|
@classroom.sessions = new LevelSessions(sessions)
|
2016-03-30 16:57:19 -04:00
|
|
|
|
|
|
|
it 'progressData.get({classroom, course}) returns object with .completed=false', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course}
|
|
|
|
expect(progress.completed).toBe false
|
|
|
|
|
|
|
|
describe 'when NOT all students have completed a level', ->
|
|
|
|
it 'progressData.get({classroom, course, level}) returns object with .completed=false and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
for level in @levels.models
|
2016-03-30 16:57:19 -04:00
|
|
|
progress = progressData.get {@classroom, @course, level}
|
|
|
|
expect(progress.completed).toBe false
|
|
|
|
|
|
|
|
describe 'when the student has completed the course', ->
|
|
|
|
it 'progressData.get({classroom, course, user}) returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
progress = progressData.get {@classroom, @course, user: @finishedMember}
|
2016-03-30 16:57:19 -04:00
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'when the student has NOT completed the course', ->
|
|
|
|
it 'progressData.get({classroom, course, user}) returns object with .completed=false and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
progress = progressData.get {@classroom, @course, user: @unfinishedMember}
|
2016-03-30 16:57:19 -04:00
|
|
|
expect(progress.completed).toBe false
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'when the student has completed the level', ->
|
|
|
|
it 'progressData.get({classroom, course, level, user}) returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
for level in @levels.models
|
|
|
|
progress = progressData.get {@classroom, @course, level, user: @finishedMember}
|
2016-03-30 16:57:19 -04:00
|
|
|
expect(progress.completed).toBe true
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'when the student has NOT completed the level but has started', ->
|
|
|
|
it 'progressData.get({classroom, course, level, user}) returns object with .completed=true and .started=true', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
level = @levels.first()
|
|
|
|
progress = progressData.get {@classroom, @course, level, user: @unfinishedMember}
|
2016-03-30 16:57:19 -04:00
|
|
|
expect(progress.completed).toBe false
|
|
|
|
expect(progress.started).toBe true
|
|
|
|
|
|
|
|
describe 'when the student has NOT started the level', ->
|
|
|
|
it 'progressData.get({classroom, course, level, user}) returns object with .completed=false and .started=false', ->
|
2016-05-03 13:38:20 -04:00
|
|
|
progressData = helper.calculateAllProgress(@classrooms, @courses, @courseInstances, @members)
|
|
|
|
level = @levels.last()
|
|
|
|
progress = progressData.get {@classroom, @course, level, user: @unfinishedMember}
|
2016-03-30 16:57:19 -04:00
|
|
|
expect(progress.completed).toBe false
|
|
|
|
expect(progress.started).toBe false
|