/
todo-page.js
51 lines (38 loc) · 1.26 KB
/
todo-page.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
/// <reference types="cypress" />
export class TodoPage {
navigate() {
cy.visit('http://todomvc-app-for-testing.surge.sh/')
}
addTodo(todoText) {
cy.get('.new-todo').type(todoText + '{enter}')
}
toggleTodo(todoIndex) {
cy.get(`.todo-list li:nth-child(${todoIndex + 1}) .toggle`).click()
}
showOnlyCompletedTodos() {
cy.contains('Completed').click()
}
showOnlyActiveTodos() {
cy.contains('Active').click()
}
showAllTodos() {
cy.contains('All').click()
}
clearCompleted() {
cy.contains('Clear completed').click()
}
validateNumberOfTodosShown(expectedNumberOfTodos) {
cy.get('.todo-list li').should('have.length', expectedNumberOfTodos)
}
validateTodoCompletedState(todoIndex, shouldBeCompleted) {
const l = cy.get(`.todo-list li:nth-child(${todoIndex + 1}) label`)
l.should(`${shouldBeCompleted ? '' : 'not.'}have.css`, 'text-decoration-line', 'line-through')
}
validateTodoText(todoIndex, expectedText) {
cy.get(`.todo-list li:nth-child(${todoIndex + 1}) label`).should('have.text', expectedText)
}
validateToggleState(todoIndex, shouldBeToggled) {
const label = cy.get(`.todo-list li:nth-child(${todoIndex + 1}) label`)
label.should(`${shouldBeToggled ? '' : 'not.'}be.checked`)
}
}