forked from cypress-io/testing-workshop-cypress
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsmoke-tests.spec.js
executable file
·92 lines (80 loc) · 2.03 KB
/
smoke-tests.spec.js
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
describe('Smoke tests', () => {
beforeEach(() => {
cy.request('GET', '/api/todos')
.its('body')
.each(todo => cy.request('DELETE', `/api/todos/${todo.id}`))
})
context('With no todos', () => {
it('Saves new todos', () => {
const items = [
{text: 'Buy milk', expectedLength: 1},
{text: 'Buy eggs', expectedLength: 2},
{text: 'Buy bread', expectedLength: 3}
]
cy.visit('/')
cy.server()
cy.route('POST', '/api/todos')
.as('create')
cy.wrap(items)
.each(todo => {
cy.focused()
.type(todo.text)
.type('{enter}')
cy.wait('@create')
cy.get('.todo-list li')
.should('have.length', todo.expectedLength)
})
})
})
context('With active todos', () => {
beforeEach(() => {
cy.fixture('todos')
.each(todo => {
const newTodo = Cypress._.merge(todo, {isComplete: false})
cy.request('POST', '/api/todos', newTodo)
})
cy.visit('/')
})
it('Loads existing data from the DB', () => {
cy.get('.todo-list li')
.should('have.length', 4)
})
it('Deletes todos', () => {
cy.server()
cy.route('DELETE', '/api/todos/*')
.as('delete')
cy.get('.todo-list li')
.each($el => {
cy.wrap($el)
.find('.destroy')
.invoke('show')
.click()
cy.wait('@delete')
})
.should('not.exist')
})
it('Toggles todos', () => {
const clickAndWait = ($el) => {
cy.wrap($el)
.as('item')
.find('.toggle')
.click()
cy.wait('@update')
}
cy.server()
cy.route('PUT', '/api/todos/*')
.as('update')
cy.get('.todo-list li')
.each($el => {
clickAndWait($el)
cy.get('@item')
.should('have.class', 'completed')
})
.each($el => {
clickAndWait($el)
cy.get('@item')
.should('not.have.class', 'completed')
})
})
})
})