-
Notifications
You must be signed in to change notification settings - Fork 2
/
table.cy.js
122 lines (108 loc) · 2.93 KB
/
table.cy.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/// <reference types="cypress" />
// @ts-check
// import cypress-map plugin
import '../../commands'
describe('table', { viewportWidth: 300, viewportHeight: 200 }, () => {
beforeEach(() => {
cy.visit('cypress/table.html')
})
it('checks the column of cells', () => {
cy.contains('table#people thead td:nth-child(2)', 'Age')
cy.get('table#people tbody td:nth-child(2)')
.should('have.length', 4)
.map('innerText')
.map(Number)
.should('deep.equal', [20, 30, 28, 22])
})
it('gets the entire table', () => {
cy.get('table')
.table()
.should('deep.equal', [
['Name', 'Age', 'Date (YYYY-MM-DD)'],
['Dave', '20', '2023-12-23'],
['Cary', '30', '2024-01-24'],
['Joe', '28', '2022-02-25'],
['Anna', '22', '2027-03-26'],
])
})
it('gets the table body', () => {
cy.get('table tbody')
.table()
.should('deep.equal', [
['Dave', '20', '2023-12-23'],
['Cary', '30', '2024-01-24'],
['Joe', '28', '2022-02-25'],
['Anna', '22', '2027-03-26'],
])
})
it('gets the headings', () => {
cy.get('table')
.table(0, 0, 3, 1)
.its(0)
.print()
.should('deep.equal', ['Name', 'Age', 'Date (YYYY-MM-DD)'])
})
it('gets the headings row', () => {
cy.get('table')
.table(0, 0)
.its(0)
.print()
.should('deep.equal', ['Name', 'Age', 'Date (YYYY-MM-DD)'])
})
it('gets the headings row from thead', () => {
cy.get('table thead')
.table(0, 0)
.should('have.length', 1)
.its(0)
.print()
.should('deep.equal', ['Name', 'Age', 'Date (YYYY-MM-DD)'])
})
it('gets the first column', () => {
cy.get('table')
.table(0, 0, 1, 5)
.print()
.should('deep.equal', [['Name'], ['Dave'], ['Cary'], ['Joe'], ['Anna']])
})
it('gets the entire first column', () => {
cy.get('table')
.table(0, 0, 1)
.print()
.should('deep.equal', [['Name'], ['Dave'], ['Cary'], ['Joe'], ['Anna']])
})
it('joins the first column into one array', () => {
cy.get('table')
.table(0, 1, 1) // skip the heading "Name" cell
// combine 1x1 arrays into one array
.invoke('flatMap', Cypress._.identity)
.print()
.should('deep.equal', ['Dave', 'Cary', 'Joe', 'Anna'])
})
it('gets a region of the table', () => {
cy.get('table')
.table(0, 2, 2, 2)
.print()
.should('deep.equal', [
['Cary', '30'],
['Joe', '28'],
])
})
it('gets a region of the table using slice', () => {
cy.get('table')
.table()
.invoke('slice', 2, 4)
.mapInvoke('slice', 0, 2)
.print()
.should('deep.equal', [
['Cary', '30'],
['Joe', '28'],
])
})
it('checks the last row', () => {
cy.get('table')
.table()
.invoke('slice', -1)
.its(0)
.print()
.should('deep.equal', ['Anna', '22', '2027-03-26'])
})
})