This repository was archived by the owner on May 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathMainSection.cy-spec.js
93 lines (82 loc) · 2.36 KB
/
MainSection.cy-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
93
/// <reference types="cypress" />
import React from 'react'
import MainSection from './MainSection'
import { mount } from 'cypress-react-unit-test'
// we are making mini application - thus we need a store!
import { Provider } from 'react-redux'
import { store } from '../store'
const setup = (propOverrides) => {
const props = Object.assign(
{
todosCount: 2,
completedCount: 1,
actions: {
editTodo: cy.stub().as('edit'),
deleteTodo: cy.stub().as('delete'),
completeTodo: cy.stub().as('complete'),
completeAllTodos: cy.stub().as('completeAll'),
clearCompleted: cy.stub().as('clearCompleted'),
},
},
propOverrides
)
mount(
<Provider store={store}>
<MainSection {...props} />
</Provider>,
{ cssFile: 'node_modules/todomvc-app-css/index.css' }
)
}
describe('components', () => {
describe('MainSection', () => {
it('should render container', () => {
setup()
cy.get('section').should('have.class', 'main')
})
describe('toggle all input', () => {
it('should render', () => {
setup()
cy.get('input[type=checkbox]')
.should('have.class', 'toggle-all')
.and('not.be.checked')
})
it('should be checked if all todos completed', () => {
setup({
completedCount: 2,
})
cy.get('input[type=checkbox]').should('be.checked')
})
it('should call completeAllTodos on change', () => {
setup()
cy.get('input[type=checkbox]').click({ force: true })
cy.get('@completeAll').should('be.called')
})
})
describe('footer', () => {
it('should render', () => {
setup()
cy.get('footer').contains('1 item left')
})
it('onClearCompleted should call clearCompleted', () => {
setup()
cy.contains('button', 'Clear completed').click()
cy.get('@clearCompleted').should('have.been.called')
})
})
describe('visible todo list', () => {
it('should render', () => {
setup()
cy.get('li').should('have.length', 3)
})
})
describe('toggle all input and footer', () => {
it('should not render if there are no todos', () => {
setup({
todosCount: 0,
completedCount: 0,
})
cy.get('li').should('have.length', 0)
})
})
})
})