mirror of
https://github.com/UniversityOfHelsinkiCS/ohtuilmo.git
synced 2026-10-12 19:03:41 +03:00
tests: make tests more reliable and isolated
This commit is contained in:
@@ -4,14 +4,52 @@ describe('Group Management Page', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearLocalStorage()
|
cy.clearLocalStorage()
|
||||||
cy.loginAsAdmin()
|
cy.loginAsAdmin()
|
||||||
|
|
||||||
|
// Ensure Aihe A and Aihe B have topicAccepted emails so they appear in the Topic dropdown.
|
||||||
|
// topicListPage.spec.js deletes all sent emails, which pollutes subsequent test runs.
|
||||||
|
cy.window().then((win) => {
|
||||||
|
const token = JSON.parse(win.localStorage.getItem('loggedInUser')).token
|
||||||
|
cy.request({
|
||||||
|
url: '/api/topics',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
}).then((res) => {
|
||||||
|
const topics = res.body.topics
|
||||||
|
const aiheA = topics.find((t) => t.content.title === 'Aihe A')
|
||||||
|
const aiheB = topics.find((t) => t.content.title === 'Aihe B')
|
||||||
|
|
||||||
|
if (aiheA) {
|
||||||
|
cy.request({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/email/send',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
body: { messageType: 'topicAccepted', messageLanguage: 'finnish', topicId: aiheA.id },
|
||||||
|
failOnStatusCode: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if (aiheB) {
|
||||||
|
cy.request({
|
||||||
|
method: 'POST',
|
||||||
|
url: '/api/email/send',
|
||||||
|
headers: { Authorization: `Bearer ${token}` },
|
||||||
|
body: { messageType: 'topicAccepted', messageLanguage: 'finnish', topicId: aiheB.id },
|
||||||
|
failOnStatusCode: false,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
cy.visit('/administration/groups')
|
cy.visit('/administration/groups')
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('Creating a group', () => {
|
describe('Creating a group', () => {
|
||||||
it('is successful when all necessary details are provided', () => {
|
it('is successful when all necessary details are provided', () => {
|
||||||
cy.get('.configuration-selector').click()
|
cy.get('.configuration-selector').should('be.visible').click()
|
||||||
|
cy.wait(500)
|
||||||
cy.get('.configuration-1').click()
|
cy.get('.configuration-1').click()
|
||||||
cy.get('.create-group-form-topic__selector').click()
|
cy.wait(500)
|
||||||
|
|
||||||
|
cy.get('.create-group-form-topic__selector').should('be.visible').click()
|
||||||
|
cy.wait(500)
|
||||||
cy.get('.topic-menu-item').contains('Aihe A').click()
|
cy.get('.topic-menu-item').contains('Aihe A').click()
|
||||||
cy.get('.create-group-form__name input').clear().type('Ryhmä A')
|
cy.get('.create-group-form__name input').clear().type('Ryhmä A')
|
||||||
cy.get('.create-group-form__student-input textarea:not([aria-hidden="true"])').type(
|
cy.get('.create-group-form__student-input textarea:not([aria-hidden="true"])').type(
|
||||||
@@ -33,8 +71,10 @@ describe('Group Management Page', () => {
|
|||||||
|
|
||||||
describe('Viewing a group', () => {
|
describe('Viewing a group', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.get('.configuration-selector').click()
|
cy.get('.configuration-selector').should('be.visible').click()
|
||||||
|
cy.wait(500)
|
||||||
cy.get('.configuration-1').click()
|
cy.get('.configuration-1').click()
|
||||||
|
cy.wait(500)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('deletes a student', () => {
|
it('deletes a student', () => {
|
||||||
@@ -53,8 +93,10 @@ describe('Group Management Page', () => {
|
|||||||
|
|
||||||
describe('Editing a group', () => {
|
describe('Editing a group', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.get('.configuration-selector').click()
|
cy.get('.configuration-selector').should('be.visible').click()
|
||||||
|
cy.wait(500)
|
||||||
cy.get('.configuration-1').click()
|
cy.get('.configuration-1').click()
|
||||||
|
cy.wait(500)
|
||||||
cy.get('[data-cy=edit-group-button]').eq(0).click()
|
cy.get('[data-cy=edit-group-button]').eq(0).click()
|
||||||
cy.get('.notification').should('contain', 'Editing for group').should('contain', 'enabled!')
|
cy.get('.notification').should('contain', 'Editing for group').should('contain', 'enabled!')
|
||||||
})
|
})
|
||||||
@@ -77,13 +119,8 @@ describe('Group Management Page', () => {
|
|||||||
|
|
||||||
it('changes topic', () => {
|
it('changes topic', () => {
|
||||||
cy.get('.edit-group-form-topic__selector').should('be.visible').click()
|
cy.get('.edit-group-form-topic__selector').should('be.visible').click()
|
||||||
cy.get('.topic-menu-item')
|
cy.wait(500)
|
||||||
.first()
|
cy.get('.topic-menu-item').contains('Aihe B').click()
|
||||||
.should('be.visible')
|
|
||||||
.within(() => {
|
|
||||||
cy.wait(500)
|
|
||||||
cy.contains('Aihe B').click()
|
|
||||||
})
|
|
||||||
cy.get('[data-cy=edit-group-name-field] input').clear().type('Ryhmä B')
|
cy.get('[data-cy=edit-group-name-field] input').clear().type('Ryhmä B')
|
||||||
cy.get('[data-cy=edit-group-save-button]').click()
|
cy.get('[data-cy=edit-group-save-button]').click()
|
||||||
cy.get('.notification').should('have.text', 'Group updated!')
|
cy.get('.notification').should('have.text', 'Group updated!')
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ const formatDate = (date) => date.toISOString().slice(0, 10)
|
|||||||
describe('Staff tag page', () => {
|
describe('Staff tag page', () => {
|
||||||
before(() => {
|
before(() => {
|
||||||
cy.deleteAllGroups()
|
cy.deleteAllGroups()
|
||||||
|
cy.loginAsRegisteredUser()
|
||||||
|
cy.loginAsRegisteredIndicatedUser()
|
||||||
cy.loginAsAdmin()
|
cy.loginAsAdmin()
|
||||||
cy.visit('/')
|
cy.visit('/')
|
||||||
cy.createTag('Coding')
|
cy.createTag('Coding')
|
||||||
@@ -114,16 +116,13 @@ describe('Staff tag page', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('displays correct tag data for group', () => {
|
it('displays correct tag data for group', () => {
|
||||||
cy.get('[data-cy="configuration-selector"]')
|
cy.get('[data-cy="configuration-selector"]').should('be.visible').click()
|
||||||
.click()
|
cy.wait(500)
|
||||||
.then(() => {
|
cy.get('.configuration-menu-item').contains('Konfiguraatio 1').click()
|
||||||
cy.contains('Konfiguraatio 1').click()
|
|
||||||
})
|
cy.get('[data-cy="group-selector"]').should('be.visible').click()
|
||||||
cy.get('[data-cy="group-selector"]')
|
cy.wait(500)
|
||||||
.click()
|
cy.get('.group-menu-item').contains('Brand New Group').click()
|
||||||
.then(() => {
|
|
||||||
cy.contains('Brand New Group').click()
|
|
||||||
})
|
|
||||||
cy.contains('Tag usage for Brand New Group').should('exist')
|
cy.contains('Tag usage for Brand New Group').should('exist')
|
||||||
cy.get('#bar-Coding').trigger('mouseover')
|
cy.get('#bar-Coding').trigger('mouseover')
|
||||||
cy.get('.recharts-tooltip-wrapper').should('be.visible').and('contain.text', '6 h')
|
cy.get('.recharts-tooltip-wrapper').should('be.visible').and('contain.text', '6 h')
|
||||||
@@ -151,21 +150,17 @@ describe('Staff tag page', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('displays correct tag data for individual student', () => {
|
it('displays correct tag data for individual student', () => {
|
||||||
cy.get('[data-cy="configuration-selector"]')
|
cy.get('[data-cy="configuration-selector"]').should('be.visible').click()
|
||||||
.click()
|
cy.wait(500)
|
||||||
.then(() => {
|
cy.get('.configuration-menu-item').contains('Konfiguraatio 1').click()
|
||||||
cy.contains('Konfiguraatio 1').click()
|
|
||||||
})
|
cy.get('[data-cy="group-selector"]').should('be.visible').click()
|
||||||
cy.get('[data-cy="group-selector"]')
|
cy.wait(500)
|
||||||
.click()
|
cy.get('.group-menu-item').contains('Brand New Group').click()
|
||||||
.then(() => {
|
|
||||||
cy.contains('Brand New Group').click()
|
cy.get('[data-cy="student-selector"]').should('be.visible').click()
|
||||||
})
|
cy.wait(500)
|
||||||
cy.get('[data-cy="student-selector"]')
|
cy.get('.student-menu-item').contains('Volodymyr').click()
|
||||||
.click()
|
|
||||||
.then(() => {
|
|
||||||
cy.contains('Volodymyr').click()
|
|
||||||
})
|
|
||||||
cy.contains('Tag usage for Volodymyr').should('exist')
|
cy.contains('Tag usage for Volodymyr').should('exist')
|
||||||
cy.get('#bar-Coding').trigger('mouseover')
|
cy.get('#bar-Coding').trigger('mouseover')
|
||||||
cy.get('.recharts-tooltip-wrapper').should('be.visible').and('contain.text', '4 h')
|
cy.get('.recharts-tooltip-wrapper').should('be.visible').and('contain.text', '4 h')
|
||||||
|
|||||||
@@ -140,6 +140,9 @@ describe('Topic list page', () => {
|
|||||||
.eq(2)
|
.eq(2)
|
||||||
.invoke('attr', 'data-cy-topic-name')
|
.invoke('attr', 'data-cy-topic-name')
|
||||||
.should('eq', 'Ohjelmistotuotantoprojektin laajennus')
|
.should('eq', 'Ohjelmistotuotantoprojektin laajennus')
|
||||||
|
|
||||||
|
// Restore Aihe C to its original Active state to prevent test pollution in subsequent runs!
|
||||||
|
findTopicActiveCheckbox('Aihe C').click()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user