-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
InlineSpecList.cy.tsx
224 lines (180 loc) · 7.31 KB
/
InlineSpecList.cy.tsx
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import { Specs_InlineSpecListFragment, Specs_InlineSpecListFragmentDoc, SpecFilter_SetPreferencesDocument } from '../generated/graphql-test'
import InlineSpecList from './InlineSpecList.vue'
import { defaultMessages } from '@cy/i18n'
let specs: Array<any> = []
const hoverRunAllSpecs = (directory?: string, specNumber?: number) => {
let command
if (directory) {
command = cy.contains('[data-cy=directory-item]', directory)
} else {
command = cy.get('[data-cy=directory-item]').first()
}
return command.realHover().then(() => {
cy.get('[data-cy=play-button]').should('exist')
cy.get('[data-cy=run-all-specs]').realHover().then(() => {
cy.get('[data-cy=tooltip-content]').should('contain.text', `Run ${specNumber} spec`)
})
})
}
describe('InlineSpecList', () => {
const mountInlineSpecList = ({ specFilter, experimentalRunAllSpecs }: {specFilter?: string, experimentalRunAllSpecs?: boolean} = {}) => cy.mountFragment(Specs_InlineSpecListFragmentDoc, {
onResult: (ctx) => {
if (!ctx.currentProject?.specs) {
return ctx
}
specs = ctx.currentProject.specs = specs.map((spec) => ({ __typename: 'Spec', ...spec, id: spec.relative }))
if (specFilter) {
ctx.currentProject.savedState = { specFilter }
}
if (experimentalRunAllSpecs) {
ctx.currentProject.config = [{ field: 'experimentalRunAllSpecs', value: true }]
}
return ctx
},
render: (gqlValue) => {
return (
<div class="bg-gray-1000">
<InlineSpecList gql={gqlValue}></InlineSpecList>
</div>
)
},
})
describe('with no saved search term', () => {
beforeEach(() => {
cy.fixture('found-specs').then((foundSpecs) => specs = foundSpecs)
})
it('should render a list of specs', () => {
mountInlineSpecList()
cy.get('li')
.should('exist')
.and('have.length', 7)
// overflow is required for the virtual list to work
// this test will fail if the overflow set by `useVirtualList`
// is overridden
cy.get('[data-cy="specs-list-container"]')
.should('have.css', 'overflow-y', 'auto')
cy.percySnapshot()
})
it('should support fuzzy sort', () => {
mountInlineSpecList()
cy.get('input').type('compspec')
cy.get('li').should('have.length', 4)
.should('contain', 'src/components')
.and('contain', 'Spec-A.spec.tsx')
// Don't want the search to be too fuzzy
// sr => src, co => components, se => spec
cy.get('input').clear().type('srcose')
cy.get('li').should('have.length', 0)
})
it('should open CreateSpec modal', () => {
mountInlineSpecList()
const newSpecSelector = `[aria-label="New spec"]`
cy.get(newSpecSelector).click()
cy.contains(defaultMessages.createSpec.newSpecModalTitle).should('be.visible')
cy.percySnapshot()
})
it('should handle spec refresh', () => {
const scrollVirtualList = (lastItem: string) => {
cy.findAllByTestId('spec-row-item').last().dblclick().then(($el) => {
if (!$el.text().includes(lastItem)) {
scrollVirtualList(lastItem)
}
})
}
let _gqlValue: Specs_InlineSpecListFragment
cy.mountFragment(Specs_InlineSpecListFragmentDoc, {
onResult (ctx) {
if (ctx.currentProject?.specs) {
ctx.currentProject.specs = ctx.currentProject.specs.slice(0, 50)
}
return ctx
},
render (gqlValue) {
_gqlValue = gqlValue
return (
<div class="bg-gray-1000">
<InlineSpecList gql={gqlValue}></InlineSpecList>
</div>
)
},
}).then(() => {
const sortedSpecs = _gqlValue?.currentProject?.specs.sort((a, b) => a.relative < b.relative ? -1 : 1) || []
const firstSpec = sortedSpecs[0]
const lastSpec = sortedSpecs[sortedSpecs.length - 1]
cy.contains(firstSpec.fileName).should('be.visible')
scrollVirtualList(lastSpec.fileName)
cy.contains(lastSpec.fileName).should('be.visible')
cy.then(() => {
// Emulating a gql update that shouldn't cause a scroll snap
if (_gqlValue.currentProject?.specs) {
_gqlValue.currentProject.specs = [..._gqlValue.currentProject.specs]
}
})
cy.contains(lastSpec.fileName).should('be.visible')
const newSpec = { ...lastSpec, relative: 'zzz/my-test.spec.tsx', fileName: 'my-test' }
cy.then(() => {
// Checking that specs list refreshes when spec is added
if (_gqlValue.currentProject?.specs) {
_gqlValue.currentProject.specs = _gqlValue.currentProject.specs.concat(newSpec)
}
})
cy.contains(firstSpec.fileName).should('be.visible')
scrollVirtualList(newSpec.fileName)
cy.contains(newSpec.fileName).should('be.visible')
cy.then(() => {
// Checking that specs list refreshes when spec is deleted
if (_gqlValue.currentProject?.specs) {
_gqlValue.currentProject.specs = _gqlValue.currentProject.specs.filter(((spec) => spec.relative !== newSpec.relative))
}
})
cy.contains(firstSpec.fileName).should('be.visible')
scrollVirtualList(lastSpec.fileName)
cy.contains(newSpec.fileName).should('not.exist')
})
})
})
describe('with a saved spec filter', () => {
beforeEach(() => {
cy.fixture('found-specs').then((foundSpecs) => specs = foundSpecs)
mountInlineSpecList({ specFilter: 'saved-search-term 🗑' })
cy.findByLabelText(defaultMessages.specPage.searchPlaceholder)
.as('searchField')
cy.findByLabelText(defaultMessages.specPage.clearSearch, { selector: 'button' })
.as('searchFieldClearButton')
})
it('starts with the saved filter', () => {
cy.get('@searchField').should('have.value', 'saved-search-term 🗑')
cy.get('li').should('not.exist')
cy.get('@searchFieldClearButton').click()
cy.get('li').should('have.length.greaterThan', 0)
})
it('calls gql mutation to save updated filter', () => {
const setSpecFilterStub = cy.stub()
cy.stubMutationResolver(SpecFilter_SetPreferencesDocument, (defineResult, variables) => {
const specFilter = JSON.parse(variables.value)?.specFilter
setSpecFilterStub(specFilter)
})
// since there is a saved search, clear it out
cy.get('@searchFieldClearButton').click()
cy.get('@searchField').type('test')
cy.wrap(setSpecFilterStub).should('have.been.calledWith', 'test')
cy.get('@searchField').type('{backspace}{backspace}')
cy.wrap(setSpecFilterStub).should('have.been.calledWith', 'te')
cy.get('@searchField').type('{backspace}{backspace}')
cy.wrap(setSpecFilterStub).should('have.been.calledWith', '')
})
})
describe('Run all Specs', () => {
beforeEach(() => {
cy.fixture('found-specs').then((foundSpecs) => specs = foundSpecs)
})
it('displays runAllSpecs when hovering over a spec-list directory row', () => {
mountInlineSpecList({ experimentalRunAllSpecs: true })
hoverRunAllSpecs('src', 4)
})
it('checks if functionality works after a search', () => {
mountInlineSpecList({ experimentalRunAllSpecs: true, specFilter: 'B' })
hoverRunAllSpecs('src', 1)
})
})
})