-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
tests_spec.ts
158 lines (129 loc) · 4.94 KB
/
tests_spec.ts
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { EventEmitter } from 'events'
import { itHandlesFileOpening } from '../support/utils'
describe('controls', function () {
beforeEach(function () {
cy.fixture('runnables').as('runnables')
this.runner = new EventEmitter()
cy.visit('/dist').then((win) => {
win.render({
runner: this.runner,
spec: {
name: 'foo.js',
relative: 'relative/path/to/foo.js',
absolute: '/absolute/path/to/foo.js',
},
})
})
cy.get('.reporter').then(() => {
this.runner.emit('runnables:ready', this.runnables)
this.runner.emit('reporter:start', {})
})
})
describe('tests', function () {
beforeEach(function () {
this.passingTestTitle = this.runnables.suites[0].tests[0].title
this.failingTestTitle = this.runnables.suites[0].tests[1].title
})
describe('expand and collapse', function () {
it('is collapsed by default', function () {
cy.contains(this.passingTestTitle)
.parents('.collapsible').first()
.should('not.have.class', 'is-open')
.find('.collapsible-content')
.should('not.be.visible')
})
describe('expand/collapse test manually', function () {
beforeEach(function () {
cy.contains(this.passingTestTitle)
.parents('.collapsible').first().as('testWrapper')
.should('not.have.class', 'is-open')
.find('.collapsible-content')
.should('not.be.visible')
})
it('expands/collapses on click', function () {
cy.contains(this.passingTestTitle)
.click()
cy.get('@testWrapper')
.should('have.class', 'is-open')
.find('.collapsible-content').should('be.visible')
cy.contains(this.passingTestTitle)
.click()
cy.get('@testWrapper')
.should('not.have.class', 'is-open')
.find('.collapsible-content').should('not.be.visible')
})
it('expands/collapses on enter', function () {
cy.contains(this.passingTestTitle)
.parents('.collapsible-header').first()
.focus().type('{enter}')
cy.get('@testWrapper')
.should('have.class', 'is-open')
.find('.collapsible-content').should('be.visible')
cy.contains(this.passingTestTitle)
.parents('.collapsible-header').first()
.focus().type('{enter}')
cy.get('@testWrapper')
.should('not.have.class', 'is-open')
.find('.collapsible-content').should('not.be.visible')
})
it('expands/collapses on space', function () {
cy.contains(this.passingTestTitle)
.parents('.collapsible-header').first()
.focus().type(' ')
cy.get('@testWrapper')
.should('have.class', 'is-open')
.find('.collapsible-content').should('be.visible')
cy.contains(this.passingTestTitle)
.parents('.collapsible-header').first()
.focus().type(' ')
cy.get('@testWrapper')
.should('not.have.class', 'is-open')
.find('.collapsible-content').should('not.be.visible')
})
})
})
describe('failed tests', function () {
it('expands automatically', function () {
cy.contains(this.failingTestTitle)
.parents('.collapsible').first()
.should('have.class', 'is-open')
.find('.collapsible-content')
.should('be.visible')
})
})
describe('header', function () {
it('displays', function () {
cy.get('.runnable-header').find('a').should('have.text', 'relative/path/to/foo.js')
})
it('displays tooltip on hover', () => {
cy.get('.runnable-header a').first().trigger('mouseover')
cy.get('.cy-tooltip').first().should('have.text', 'Open in IDE')
})
itHandlesFileOpening('.runnable-header a', {
file: '/absolute/path/to/foo.js',
line: 0,
column: 0,
})
})
describe('progress bar', function () {
it('displays', function () {
cy.get('.runnable-active').click()
cy.get('.command-progress').should('be.visible')
})
it('calculates correct width', function () {
const { wallClockStartedAt } = this.runnables.suites[0].suites[0].tests[1].commands[0]
// take the wallClockStartedAt of this command and add 2500 milliseconds to it
// in order to simulate the command having run for 2.5 seconds of the total 4000 timeout
const date = new Date(wallClockStartedAt).setMilliseconds(2500)
cy.clock(date, ['Date'])
cy.get('.runnable-active').click()
cy.get('.command-progress > span').should(($span) => {
expect($span.attr('style')).to.contain('animation-duration: 1500ms')
expect($span.attr('style')).to.contain('width: 37.5%')
// ensures that actual width hits 0 within default timeout
expect($span).to.have.css('width', '0px')
})
})
})
})
})