Skip to content

Commit

Permalink
update cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KatieMSB committed Jan 17, 2024
1 parent 7f7e79b commit b20f2d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
2 changes: 1 addition & 1 deletion web/src/app/schedules/temp-sched/TempSchedAddNewShift.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export default function TempSchedAddNewShift({
</Grid>
<Grid item xs={12}>
<FormControlLabel
control={<Checkbox checked={custom} />}
control={<Checkbox checked={custom} data-cy='toggle-custom' />}
label={
<Typography
color='textSecondary'
Expand Down
30 changes: 23 additions & 7 deletions web/src/cypress/e2e/temporarySchedule.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,18 @@ function testTemporarySchedule(screen: string): void {

const schedTZ = (t: DateTime): DateTime => t.setZone(schedule.timeZone)

it('should toggle duration field', () => {
const defaultDurationHrs = 8
it('should toggle duration field for custom shift', () => {
const defaultDurationHrs = 24
cy.get('[data-cy="new-override"]').click()
cy.dialogTitle('Choose')
cy.dialogForm({ variant: 'temp' })
cy.dialogClick('Next')

cy.get('[data-cy="add-shift-expander"]').click()

// check default state of duration
cy.get(dialog)
.find('input[name="shift-end"]')
.should('have.value', defaultDurationHrs)
cy.get(dialog).find('[data-cy="toggle-duration-off"]').click()
cy.get(dialog).find('[data-cy="toggle-custom"]').click()

// check default state of duration
cy.get('input[name="shift-start"]')
.invoke('val')
.then((shiftStart) => {
Expand All @@ -55,6 +52,12 @@ function testTemporarySchedule(screen: string): void {
)
})
})

cy.get(dialog).find('[data-cy="toggle-duration-on"]').click()

cy.get(dialog)
.find('input[name="shift-end"]')
.should('have.value', defaultDurationHrs)
})

it('should cancel and close form', () => {
Expand Down Expand Up @@ -119,6 +122,9 @@ function testTemporarySchedule(screen: string): void {
)

cy.get('[data-cy="add-shift-expander"]').click()

cy.get(dialog).find('[data-cy="toggle-custom"]').click()

cy.dialogForm({
userID: manualAddUser.name,
'shift-start': schedTZ(startTime.plus({ hour: 1 })),
Expand Down Expand Up @@ -198,6 +204,9 @@ function testTemporarySchedule(screen: string): void {
cy.get('[data-cy="shifts-list"]').should('contain', graphQLAddUser.name)

cy.get('[data-cy="add-shift-expander"]').click()

cy.get(dialog).find('[data-cy="toggle-custom"]').click()

cy.dialogForm({
userID: manualAddUser.name,
'shift-start': schedTZ(startTime.plus({ hour: 1 })),
Expand Down Expand Up @@ -251,6 +260,8 @@ function testTemporarySchedule(screen: string): void {
})
cy.get('[data-cy="add-shift-expander"]').click()

cy.get(dialog).find('[data-cy="toggle-custom"]').click()
cy.get(dialog).find('[data-cy="toggle-duration-on"]').click()
// add first shift
cy.dialogForm({
userID: manualAddUser.name,
Expand Down Expand Up @@ -298,13 +309,18 @@ function testTemporarySchedule(screen: string): void {
// add shift to split up coverage for a given day
const shiftStart = start.plus({ day: 1 }).toFormat(dtFmt)
const duration = 2

cy.get(dialog).find('[data-cy="toggle-custom"]').click()

cy.dialogForm({
userID: manualAddUser.name,
'shift-start': shiftStart,
'shift-end': duration.toString(), // this value should not change
})
cy.get('button[data-cy="add-shift"]').click()

cy.get(dialog).find('[data-cy="toggle-custom"]').click()

// reset shift start field to a random value
const randDate = randDTWithinInterval(Interval.fromDateTimes(start, end))
cy.dialogForm({ 'shift-start': randDate })
Expand Down

0 comments on commit b20f2d6

Please sign in to comment.