-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cy.ts
107 lines (93 loc) · 3.73 KB
/
main.cy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { DATE_FORMAT } from '@utils/constants'
import dayjs from 'dayjs'
// import { useBookingsStore } from "@utils/store"
import { type DateRangeProps } from '@components/Booking'
const startDate = dayjs() as DateRangeProps
const endDate = startDate.add(1, 'day') as DateRangeProps
const guests = 2
const description = 'text should be saved'
const formatedStartDate = startDate.format(DATE_FORMAT)
const formatedEndDate = endDate.format(DATE_FORMAT)
const addBooking = () => {
cy.get('#\\:r1\\:').type(formatedStartDate)
cy.get('#\\:r3\\:').type(formatedEndDate)
cy.get('#guests').type('{selectall}', { force: true }).type(guests.toString(), { force: true })
cy.get('[data-testid="booking-description"]').type(description, { force: true })
cy.get('#booking-submit').click({ force: true })
}
describe('Booking Demo', () => {
beforeEach(() => {
cy.visit('http://localhost:5173/')
})
it('should have an empty bookings list with proper message', () => {
cy.get('[data-testid="bookings-list"]').should('not.exist')
cy.get('[data-testid="bookings-empty-message"]')
.should('exist')
.should('have.text', 'No bookings yet, try creating one!')
})
describe('Manipulating bookings', () => {
beforeEach(() => {
// TODO: Should set the state, needs investigation
/* useBookingsStore.setState({
bookins: [{
id: '123',
startDate: startDate.$d,
endDate: endDate.$d,
guests,
description
}]
}) */
// FIXME: workaround
addBooking()
})
afterEach(() => {
// TODO: should reset state
// useBookingsStore.setState(useBookingsStore.getInitialState())
})
it('should create a booking', () => {
// check ui
cy.get('[data-testid="form-title"]').should('have.text', 'Create a booking')
cy.get('#booking-submit').should('have.text', 'Request booking')
cy.get('#booking-reset').should('not.exist')
cy.get('[data-testid="booking-details-0"]')
.should('be.visible')
.should('have.text', `Guests ${guests} - Dates: ${formatedStartDate} - ${formatedEndDate}${description}`)
})
it('should remove a booking', () => {
cy.get('[data-testid="booking-details-0"]')
.should('exist')
.within(() => {
cy.get('[aria-label="delete"]')
.should('exist')
.click({ force: true })
})
.should('not.exist')
})
it('should update a booking', () => {
cy.get('[data-testid="booking-details-0"]')
.should('exist')
.within(() => {
cy.get('[aria-label="edit"]')
.should('exist')
.click({ force: true })
})
// check ui
cy.get('[data-testid="form-title"]').should('have.text', 'Update booking')
cy.get('#booking-submit').should('have.text', 'Update booking')
cy.get('#booking-reset').should('exist')
// change data
const newGuests = 5
const newDescription = 'Should update booking description'
const newFormatedStartDate = startDate.add(5, 'day').format(DATE_FORMAT)
const newFormatedEndDate = endDate.add(10, 'day').format(DATE_FORMAT)
cy.get('#\\:r1\\:').clear().type(newFormatedStartDate)
cy.get('#\\:r3\\:').clear().type(newFormatedEndDate)
cy.get('#guests').type('{selectall}', { force: true }).type(newGuests.toString(), { force: true })
cy.get('[data-testid="booking-description"]').clear().type(newDescription, { force: true })
cy.get('#booking-submit').click({ force: true })
cy.get('[data-testid="booking-details-0"]')
.should('be.visible')
.should('have.text', `Guests ${newGuests} - Dates: ${newFormatedStartDate} - ${newFormatedEndDate}${newDescription}`)
})
})
})