Skip to content

Commit

Permalink
[Class statistics] Fix a bug where change in filtered students didn't…
Browse files Browse the repository at this point in the history
… trigger a new request for course stats

Also added two tests for this scenario
  • Loading branch information
valtterikantanen committed Oct 24, 2024
1 parent 59cb463 commit f8496ed
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
40 changes: 40 additions & 0 deletions cypress/e2e/Population_statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,46 @@ describe('Population Statistics tests', () => {
cy.get('[data-cy=toggle-group-module-MAT-tyo]').should('not.exist')
})

it('New fetch of courses data is done when curriculum is changed', () => {
cy.visit(pathToMathBSc2020)
cy.contains('Courses of class').click()
cy.intercept('/api/v2/populationstatistics/courses').as('courseData')
cy.get('[data-cy=curriculum-picker]').click().contains('2020 - 2023').click()
cy.wait('@courseData').then(({ response }) => {
expect(response.body).to.have.property('allStudents')
expect(response.body).to.have.property('coursestatistics')
expect(response.body.allStudents).to.equal(27)
expect(response.body.coursestatistics.some(stat => stat.course.code === 'DIGI-100')).to.be.true
})
cy.get('[data-cy=curriculum-picker]').click().contains('2023 - 2026').click()
cy.wait('@courseData').then(({ response }) => {
expect(response.body).to.have.property('allStudents')
expect(response.body).to.have.property('coursestatistics')
expect(response.body.allStudents).to.equal(27)
expect(response.body.coursestatistics.some(stat => stat.course.code === 'DIGI-100')).to.be.not.true
})
})

it('New fetch of courses data is done when filtered students change', () => {
cy.visit(pathToMathBSc2020)
cy.contains('Courses of class').click()
cy.intercept('/api/v2/populationstatistics/courses').as('courseData')
cy.wait('@courseData').then(({ response }) => {
expect(response.body).to.have.property('allStudents')
expect(response.body).to.have.property('coursestatistics')
expect(response.body.allStudents).to.equal(27)
})
cy.get('[data-cy=GraduatedFromProgramme-filter-card]').within(() => {
cy.get('[data-cy=GraduatedFromProgramme-header]').click()
cy.get('[data-cy=option-graduated-true]').click()
cy.wait('@courseData').then(({ response }) => {
expect(response.body).to.have.property('allStudents')
expect(response.body).to.have.property('coursestatistics')
expect(response.body.allStudents).to.equal(16)
})
})
})

it("Empty 'tags' tab has a link to the page where tags can be created", { retries: 2 }, () => {
cy.visit(pathToMathBSc2020)
cy.contains('Students (27)')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,21 @@ export const PopulationCourses = ({
}, [mandatoryCourses])

useEffect(() => {
if (programmeCodesToFetch == null || populationSelectedStudentCourses?.query == null) {
return
}
const { courses, selectedStudents } = populationSelectedStudentCourses.query
if (
programmeCodesToFetch != null &&
!isEqual(programmeCodesToFetch, populationSelectedStudentCourses.query.courses)
!isEqual(programmeCodesToFetch, courses) ||
selectedStudents.length !== filteredStudents.length ||
!isEqual(
selectedStudents,
filteredStudents.map(({ studentNumber }) => studentNumber)
)
) {
fetch(programmeCodesToFetch)
}
}, [programmeCodesToFetch])
}, [programmeCodesToFetch, filteredStudents])

const pending = populationSelectedStudentCourses.pending || !mandatoryCourses

Expand Down

0 comments on commit f8496ed

Please sign in to comment.