fixed remaining broken tests

This commit is contained in:
Aaro Koivukangas
2025-12-03 21:54:04 +02:00
parent 4dca2b96b8
commit 23ba996fd5
2 changed files with 195 additions and 142 deletions
+194 -141
View File
@@ -13,8 +13,9 @@ const addDaysToDate = (date, days) => {
const formatDate = (date) => date.toISOString().slice(0, 10)
describe.skip('Time logs & sprints', () => {
describe('Time logs & sprints', () => {
before(() => {
cy.deleteAllGroups()
cy.loginAsAdmin()
cy.createGroup({
name: 'Brand New Group',
@@ -28,6 +29,10 @@ describe.skip('Time logs & sprints', () => {
beforeEach(() => {
cy.loginAsRegisteredUser()
cy.visit('/')
cy.get("h4", { timeout: 15000 })
.should("include.text", "Brand New Group")
.should("include.text", "testertester3")
.should("include.text", "Registration details")
})
it('add 2 sprints', () => {
@@ -37,6 +42,9 @@ describe.skip('Time logs & sprints', () => {
cy.contains('Sprint Dashboard').click()
})
cy.get("h4").should("include.text", "Add new sprint")
const dateToday = new Date()
const dateYesterday = addDaysToDate(dateToday, -1)
@@ -44,11 +52,14 @@ describe.skip('Time logs & sprints', () => {
cy.get('#startDate').type(formatDate(addWeeksToDate(dateYesterday, -1)))
cy.get('#endDate').type(formatDate(dateYesterday))
cy.get('#add-sprint-button').click()
cy.get("[data-cy=sprint-1]").should("exist")
cy.get('#sprintNumber').type('2')
cy.get('#startDate').type(formatDate(dateToday))
cy.get('#endDate').type(formatDate(addWeeksToDate(dateToday, 1)))
cy.get('#add-sprint-button').click()
cy.get("[data-cy=sprint-2]").should("exist")
})
it('renders current sprint by default', () => {
@@ -57,6 +68,7 @@ describe.skip('Time logs & sprints', () => {
.then(() => {
cy.contains('Time Log').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-sprint-select').contains('SPRINT 2')
})
@@ -68,6 +80,8 @@ describe.skip('Time logs & sprints', () => {
cy.contains('Time Log').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('#previous-sprint-button').click()
cy.get('#date').should('be.disabled')
cy.get('#time').should('be.disabled')
@@ -82,18 +96,28 @@ describe.skip('Time logs & sprints', () => {
cy.contains('Time Log').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('#date').type(formatDate(new Date()))
cy.get('#time').type('01:00')
cy.get('#description').type('test description 1')
cy.get('#time-log-submit-button').click()
cy.get('.notification')
.should('exist')
.should('have.text', 'Time log created successfully')
cy.get('#date').type(formatDate(addDaysToDate(new Date(), 1)))
cy.get('#time').type('02:00')
cy.get('#description').type('test description 2')
cy.get('#time-log-submit-button').click()
cy.get('.notification').should('exist')
cy.get('.notification').should('have.text', 'Time log created successfully')
cy.get('.notification')
.should('exist')
.should('have.text', 'Time log created successfully')
cy.get("#timelog-rows").should('include.text', "test description 1")
cy.get("#timelog-rows").should('include.text', "test description 2")
})
it('should display 2 time logs', () => {
@@ -102,14 +126,19 @@ describe.skip('Time logs & sprints', () => {
.then(() => {
cy.contains('Time Log').click()
})
cy.get('.timelogs-container-1').should('contain', 'test description 1')
cy.get('.timelogs-container-1').should('contain', 'test description 2')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1', { timeout: 15000 }).should('contain', 'test description 1')
cy.get('.timelogs-container-1', { timeout: 15000 }).should('contain', 'test description 2')
cy.get('#timelog-rows').children().should('have.length', 2)
})
it('shows error from backend when creating timeLog fails with data outside sprint', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-02-01')
@@ -130,6 +159,9 @@ describe.skip('Time logs & sprints', () => {
.then(() => {
cy.contains('Time Log').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('contain', 'test description 2')
cy.get('#previous-sprint-button').click()
cy.get('#timelog-rows').children().should('have.length', 1)
@@ -143,23 +175,28 @@ describe.skip('Time logs & sprints', () => {
cy.contains('Time Log').click()
})
cy.get(':nth-child(1) > .timelogs-description')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-description')
.first()
.invoke('text')
.as('testedLogDescription')
cy.get('#timelog-rows > :nth-child(1)')
cy.get('#timelog-rows')
.find('[id^="timelog-remove-button-"]')
.first()
.click()
cy.get('.confirmation-dialog').should(
'contain',
'Delete this time log? It cannot be restored.'
)
cy.get('.confirmation-dialog').find('#confirmation-dialog-no-button').click()
cy.get('@testedLogDescription').then((testedLogDescription) => {
cy.get('#timelog-rows > :nth-child(1) > .timelogs-description').contains(
testedLogDescription
)
cy.get('#timelog-rows')
.find(".timelogs-description")
.first()
.should("be.text", testedLogDescription)
})
cy.get('#timelog-rows').children().should('have.length', 2)
})
@@ -171,12 +208,16 @@ describe.skip('Time logs & sprints', () => {
cy.contains('Time Log').click()
})
cy.get(':nth-child(1) > .timelogs-description')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-description')
.first()
.invoke('text')
.as('removedLogDescription')
cy.get('#timelog-rows > :nth-child(1)')
cy.get('#timelog-rows')
.find('[id^="timelog-remove-button-"]')
.first()
.click()
cy.get('.confirmation-dialog').should(
@@ -186,152 +227,164 @@ describe.skip('Time logs & sprints', () => {
cy.get('.confirmation-dialog').find('#confirmation-dialog-yes-button').click()
cy.get('@removedLogDescription').then((removedLogDescription) => {
cy.get('#timelog-rows > :nth-child(1) > .timelogs-description').should(
'not.contain',
removedLogDescription
)
cy.get('#timelog-rows')
.find(".timelogs-description")
.first()
.should('not.contain', removedLogDescription)
})
cy.get('#timelog-rows').children().should('have.length', 1)
})
it('displays error on time field of form when input is negative hours', () => {
cy.visit('/timelogs')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('-01:00')
cy.get('.description').type('negative time')
cy.get('.submit-button').click()
it('displays error on time field of form when input is negative hours', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'negative time')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('-01:00')
cy.get('.description').type('negative time')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'negative time')
})
it('displays error on time field of form when input is letters', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('aabee')
cy.get('.description').type('letters in time')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'letters in time')
})
it('displays error on time field of form when input is missing a colon', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('0100')
cy.get('.description').type('missing colon')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'missing colon')
})
it('displays error on time field of form when input has over 60 minutes', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('01:61')
cy.get('.description').type('over 60 minutes')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'over 60 minutes')
})
it('displays error on description field of form when input is under 5 characters long', () => {
cy.visit('/timelogs')
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('01:00')
cy.get('.description').type('1234')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Description must be at least 5 characters')
cy.get('#timelog-rows').should('not.contain', '1234')
})
it('trying to remove sprint with existing time logs displays error', () => {
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Sprint Dashboard').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Add new sprint")
cy.get('.sprints-container')
.find('[id^="sprint-remove-button-"]')
.last()
.click()
cy.get('.sprints-container')
.find('[id^="sprint-remove-button-"]')
.first()
.click()
.then(() => {
cy.get('.notification').should('exist')
cy.get('[data-testid="notification-message"]', { timeout: 10000 }).should('contain', 'Sprint has time logs, cannot delete.')
}
)
})
it('remove sprints, should not display sprints or time logs', () => {
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Time Log').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Time Logs")
it('displays error on time field of form when input is letters', () => {
cy.visit('/timelogs')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('aabee')
cy.get('.description').type('letters in time')
cy.get('.submit-button').click()
cy.get('#timelog-rows')
.find('[id^="timelog-remove-button-"]')
.first()
.click()
cy.get('.confirmation-dialog').should('contain', 'Delete this time log? It cannot be restored.')
cy.get('.confirmation-dialog').find('#confirmation-dialog-yes-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'letters in time')
})
cy.get('#timelog-rows').children().should('have.length', 1)
it('displays error on time field of form when input is missing a colon', () => {
cy.visit('/timelogs')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('0100')
cy.get('.description').type('missing colon')
cy.get('.submit-button').click()
// Again
cy.get('#timelog-rows')
.find('[id^="timelog-remove-button-"]')
.first()
.click()
cy.get('.confirmation-dialog').should('contain', 'Delete this time log? It cannot be restored.')
cy.get('.confirmation-dialog').find('#confirmation-dialog-yes-button').click()
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'missing colon')
})
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Sprint Dashboard').click()
})
cy.get("h4", { timeout: 15000 }).should("include.text", "Add new sprint")
it('displays error on time field of form when input has over 60 minutes', () => {
cy.visit('/timelogs')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('01:61')
cy.get('.description').type('over 60 minutes')
cy.get('.submit-button').click()
cy.get('.sprints-container')
.find('[id^="sprint-remove-button-"]')
.click({ multiple: true })
.then(() =>
cy.get('#app-content').should('not.contain', '.sprint-list-container')
)
cy.get('.input-container').contains('Time must be in format HH:MM')
cy.get('#timelog-rows').should('not.contain', 'over 60 minutes')
})
it('displays error on description field of form when input is under 5 characters long', () => {
cy.visit('/timelogs')
cy.get('.timelogs-container-1').should('exist')
cy.get('.input-container').should('exist')
cy.get('.date').type('2022-01-01')
cy.get('.time').type('01:00')
cy.get('.description').type('1234')
cy.get('.submit-button').click()
cy.get('.input-container').contains('Description must be at least 5 characters')
cy.get('#timelog-rows').should('not.contain', '1234')
})
it('trying to remove sprint with existing time logs displays error', () => {
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Sprint Dashboard').click()
})
cy.get('.sprints-container')
.find('[id^="sprint-remove-button-"]')
.click({ multiple: true })
.then(() => {
cy.get('.notification').should('exist')
cy.get('[data-testid="notification-message"]').should('contain', 'Sprint has time logs, cannot delete.')
}
)
})
it('remove sprints, should not display sprints or time logs', () => {
cy.get('#hamburger-menu-button')
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Time Log').click()
})
cy.get(':nth-child(1) > .timelogs-description')
.invoke('text')
.as('removedLogDescription')
cy.get('#timelog-rows > :nth-child(1)')
.find('[id^="timelog-remove-button-"]')
.click()
cy.get('.confirmation-dialog').should(
cy.get('#app-content', { timeout: 15000 }).should(
'contain',
'Delete this time log? It cannot be restored.'
'Your group has no sprints. Add a sprint using Sprint Dashboard.'
)
cy.get('.confirmation-dialog').find('#confirmation-dialog-yes-button').click()
cy.get('@removedLogDescription').then((removedLogDescription) => {
cy.get('#timelog-rows > :nth-child(1) > .timelogs-description').should(
'not.contain',
removedLogDescription
)
})
cy.get('#timelog-rows').children().should('have.length', 1)
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Sprint Dashboard').click()
})
cy.get('.sprints-container')
.find('[id^="sprint-remove-button-"]')
.click({ multiple: true })
.then(() =>
cy.get('#app-content').should('not.contain', '.sprint-list-container')
)
cy.get('#hamburger-menu-button')
.click()
.then(() => {
cy.contains('Time Log').click()
})
cy.get('#app-content').should(
'contain',
'Your group has no sprints. Add a sprint using Sprint Dashboard.'
)
})
})
after(() => {
cy.deleteAllGroups()
@@ -160,7 +160,7 @@ const SprintsPage = (props) => {
}).replace(/\./g, '/')
return (
<tr key={sprint.id}>
<tr key={sprint.id} data-cy={`sprint-${sprint.sprint}`}>
<td className="sprint-list-sprint-number">{sprint.sprint}</td>
<td>{formattedStartDate}</td>
<td>{formattedEndDate}</td>