mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Add test for Export Student Progress (CSV) button
Add number checking to CSV test
This commit is contained in:
parent
94e3c5a2b5
commit
bd45f75bc0
1 changed files with 34 additions and 7 deletions
|
@ -24,7 +24,12 @@ describe 'TeacherClassView', ->
|
|||
beforeEach (done) ->
|
||||
me = factories.makeUser({})
|
||||
|
||||
@courses = new Courses([factories.makeCourse({name: 'First Course'}), factories.makeCourse({name: 'Second Course'})])
|
||||
@courses = new Courses([
|
||||
factories.makeCourse({name: 'First Course'}),
|
||||
factories.makeCourse({name: 'Second Course'}),
|
||||
factories.makeCourse({name: 'Beta Course', releasePhase: 'beta'}),
|
||||
])
|
||||
@releasedCourses = new Courses(@courses.where({ releasePhase: 'released' }))
|
||||
available = factories.makePrepaid()
|
||||
expired = factories.makePrepaid({endDate: moment().subtract(1, 'day').toISOString()})
|
||||
@students = new Users([
|
||||
|
@ -35,11 +40,11 @@ describe 'TeacherClassView', ->
|
|||
factories.makeUser({name: 'Ned'}, {prepaid: expired})
|
||||
factories.makeUser({name: 'Ebner'}, {prepaid: expired})
|
||||
])
|
||||
@levels = new Levels(_.times(2, -> factories.makeLevel()))
|
||||
@classroom = factories.makeClassroom({}, { @courses, members: @students, levels: [@levels, new Levels()] })
|
||||
@levels = new Levels(_.times(2, -> factories.makeLevel({ concepts: ['basic_syntax', 'arguments', 'functions'] })))
|
||||
@classroom = factories.makeClassroom({}, { courses: @releasedCourses, members: @students, levels: [@levels, new Levels()] })
|
||||
@courseInstances = new CourseInstances([
|
||||
factories.makeCourseInstance({}, { course: @courses.first(), @classroom, members: @students })
|
||||
factories.makeCourseInstance({}, { course: @courses.last(), @classroom, members: @students })
|
||||
factories.makeCourseInstance({}, { course: @releasedCourses.first(), @classroom, members: @students })
|
||||
factories.makeCourseInstance({}, { course: @releasedCourses.last(), @classroom, members: @students })
|
||||
])
|
||||
|
||||
sessions = []
|
||||
|
@ -47,11 +52,11 @@ describe 'TeacherClassView', ->
|
|||
@unfinishedStudent = @students.last()
|
||||
for level in @levels.models
|
||||
sessions.push(factories.makeLevelSession(
|
||||
{state: {complete: true}},
|
||||
{state: {complete: true}, playtime: 60},
|
||||
{level, creator: @finishedStudent})
|
||||
)
|
||||
sessions.push(factories.makeLevelSession(
|
||||
{state: {complete: true}},
|
||||
{state: {complete: true}, playtime: 60},
|
||||
{level: @levels.first(), creator: @unfinishedStudent})
|
||||
)
|
||||
@levelSessions = new LevelSessions(sessions)
|
||||
|
@ -118,3 +123,25 @@ describe 'TeacherClassView', ->
|
|||
users = @view.enrollStudents.calls.argsFor(0)[0]
|
||||
expect(users.size()).toBe(1)
|
||||
expect(users.first().id).toBe(@view.students.first().id)
|
||||
|
||||
describe 'Export Student Progress (CSV) button', ->
|
||||
it 'downloads a CSV file', ->
|
||||
spyOn(window, 'open').and.callFake (encodedCSV) =>
|
||||
progressData = decodeURI(encodedCSV)
|
||||
CSVHeader = 'data:text\/csv;charset=utf-8,'
|
||||
expect(progressData).toMatch new RegExp('^' + CSVHeader)
|
||||
lines = progressData.slice(CSVHeader.length).split('\n')
|
||||
expect(lines.length).toBe(@students.length + 1)
|
||||
for line in lines
|
||||
simplerLine = line.replace(/"[^"]+"/g, '""')
|
||||
# Username,Email,Total Playtime, [CS1-? Playtime], Concepts
|
||||
expect(simplerLine.match(/[^,]+/g).length).toBe(3 + @releasedCourses.length + 1)
|
||||
if simplerLine.match new RegExp(@finishedStudent.get('email'))
|
||||
expect(simplerLine).toMatch /2 minutes,2 minutes,0/
|
||||
else if simplerLine.match new RegExp(@unfinishedStudent.get('email'))
|
||||
expect(simplerLine).toMatch /a minute,a minute,0/
|
||||
else if simplerLine.match /@/
|
||||
expect(simplerLine).toMatch /0,0,0/
|
||||
return true
|
||||
@view.$('.export-student-progress-btn').click()
|
||||
expect(window.open).toHaveBeenCalled()
|
||||
|
|
Loading…
Reference in a new issue