forked from bahmutov/test-todomvc-using-app-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
77 lines (71 loc) · 1.71 KB
/
utils.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
/// <reference types="cypress" />
/// <reference path='./model.d.ts' />
// @ts-check
export const TODO_ITEM_ONE = 'buy some cheese'
export const TODO_ITEM_TWO = 'feed the cat'
export const TODO_ITEM_THREE = 'book a doctors appointment'
/**
* App action to creates default todo items.
*
* @example
* import { addDefaultTodos } from './utils'
* beforeEach(addDefaultTodos)
*/
export const addDefaultTodos = () => {
addTodos(TODO_ITEM_ONE, TODO_ITEM_TWO, TODO_ITEM_THREE)
allItems().as('todos')
}
/**
* App action to create one or more todos.
*
* @example
```
import { addTodos } from './utils'
it('shows right counter', () => {
addTodos(TODO_ITEM_ONE)
cy.get('.todo-count').contains('1 item left')
addTodos(TODO_ITEM_TWO)
cy.get('.todo-count').contains('2 items left')
})
```
*/
export const addTodos = (...todos) => {
cy.window()
.its('model')
.should('be.an', 'object')
.invoke('addTodo', ...todos)
}
/**
* App action to toggle the given todo item.
* Returns chain so you can attach more Cypress commands.
* @param {number} k index of the todo item to toggle, 0 - first item
*
* @example
```js
import { addTodos, toggle } from './utils'
it('completes an item', () => {
addTodos('first')
toggle(0)
})
```
*/
export const toggle = (k = 0) =>
cy
.window()
.its('model')
.should('be.an', 'object')
.then(model => {
expect(k, 'check item index').to.be.lessThan(model.todos.length)
model.toggle(model.todos[k])
})
const ALL_ITEMS = '.todo-list li'
/**
* Returns all todo items on the page.
*
* @example
```
import {allItems} from './utils'
allItems().should('not.exist')
```
*/
export const allItems = () => cy.get(ALL_ITEMS)