Skip to content

Commit b4cddfc

Browse files
authored
Merge pull request #645 from geonetwork/fixes-datahub-e2e
Fixes and improvements to e2e tests
2 parents e5584f9 + 81356bf commit b4cddfc

19 files changed

Lines changed: 135 additions & 75 deletions

File tree

apps/datahub-e2e/src/e2e/datasetDetailPage.cy.ts

Lines changed: 49 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable cypress/no-unnecessary-waiting */
21
import 'cypress-real-events'
32

43
describe('dataset pages', () => {
@@ -40,6 +39,13 @@ describe('dataset pages', () => {
4039
fixture: 'insee-rectangles_200m_menage_erbm.json',
4140
}
4241
)
42+
cy.intercept(
43+
'GET',
44+
'/geoserver/insee/ows?SERVICE=WFS&REQUEST=GetFeature&VERSION=2.0.0&TYPENAMES=insee%3Arectangles_200m_menage_erbm&OUTPUTFORMAT=csv',
45+
{
46+
fixture: 'population-millesimee-communes-francaises.csv',
47+
}
48+
)
4349
cy.intercept(
4450
'GET',
4551
'/explore/dataset/population-millesimee-communes-francaises/download?format=csv&timezone=Europe/Berlin&use_labels_for_header=false',
@@ -211,99 +217,102 @@ describe('dataset pages', () => {
211217
cy.get('gn-ui-record-metadata')
212218
.find('[id="preview"]')
213219
.first()
214-
.as('prevSection')
220+
.as('previewSection')
215221
})
216222
describe('display', () => {
217223
it('should display the tabs', () => {
218-
cy.get('@prevSection')
224+
cy.get('@previewSection')
219225
.find('.mat-mdc-tab-labels')
220226
.children('div')
221227
.should('have.length', 3)
222228
})
223229
it('should display the dataset dropdown with at least 1 option', () => {
224-
cy.get('@prevSection')
230+
cy.get('@previewSection')
225231
.find('gn-ui-dropdown-selector')
226-
.find('select')
227-
.children('option')
232+
.openDropdown()
233+
.children('button')
228234
.should('have.length.gt', 1)
229235
})
230236
it('should display the map', () => {
231-
cy.get('@prevSection').find('gn-ui-map').should('be.visible')
237+
cy.get('@previewSection').find('gn-ui-map').should('be.visible')
232238
})
233239
it('should display the table', () => {
234-
cy.get('@prevSection')
240+
cy.get('@previewSection')
235241
.find('.mat-mdc-tab-labels')
236242
.children('div')
237243
.eq(1)
238244
.click()
239-
cy.wait(1000)
240-
cy.get('@prevSection').find('gn-ui-table').should('be.visible')
241-
cy.get('@prevSection')
245+
cy.get('@previewSection').find('gn-ui-table').should('be.visible')
246+
cy.get('@previewSection')
242247
.find('gn-ui-table')
243248
.find('table')
244249
.find('tbody')
245250
.children('tr')
246251
.should('have.length.gt', 0)
247252
})
248253
it('should display the chart & dropdowns', () => {
249-
cy.get('@prevSection')
254+
cy.get('@previewSection')
250255
.find('.mat-mdc-tab-labels')
251256
.children('div')
252257
.eq(2)
253258
.click()
254-
cy.get('@prevSection').find('gn-ui-chart').should('not.match', ':empty')
255-
cy.get('@prevSection')
259+
cy.get('@previewSection')
260+
.find('gn-ui-chart')
261+
.should('not.match', ':empty')
262+
cy.get('@previewSection')
256263
.find('gn-ui-chart-view')
257264
.find('gn-ui-dropdown-selector')
258265
.filter(':visible')
259266
.as('drop')
260267
cy.get('@drop').should('have.length', 4)
261268
cy.get('@drop').each((dropdown) => {
262-
cy.wrap(dropdown).find('option').should('have.length.greaterThan', 0)
269+
cy.wrap(dropdown)
270+
.openDropdown()
271+
.find('button')
272+
.should('have.length.greaterThan', 0)
263273
})
264274
})
265275
})
266276
describe('features', () => {
267277
it('MAP : should open a popup on layer click', () => {
268-
cy.get('@prevSection').find('canvas').realClick()
278+
cy.get('@previewSection').find('canvas').realClick()
269279
cy.request({
270280
method: 'GET',
271281
url: ' https://www.geo2france.fr/geoserver/insee/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image%2Fpng&TRANSPARENT=true&QUERY_LAYERS=rectangles_200m_menage_erbm&LAYERS=rectangles_200m_menage_erbm&INFO_FORMAT=application%2Fjson&I=249&J=65&WIDTH=296&HEIGHT=296&CRS=EPSG%3A3857&STYLES=&BBOX=-24459.849051256402%2C6237261.508070382%2C337545.9169073383%2C6599267.274028977',
272282
failOnStatusCode: false,
273283
})
274-
cy.get('@prevSection').find('gn-ui-feature-detail')
284+
cy.get('@previewSection').find('gn-ui-feature-detail')
275285
})
276286
it('TABLE : should scroll', () => {
277-
cy.get('@prevSection')
287+
cy.get('@previewSection')
278288
.find('.mat-mdc-tab-labels')
279289
.children('div')
280290
.eq(1)
281291
.click()
282-
cy.get('@prevSection').find('gn-ui-table').find('table').as('table')
292+
cy.get('@previewSection').find('gn-ui-table').find('table').as('table')
283293
cy.get('@table').scrollTo('bottom', { ensureScrollable: false })
284294

285295
cy.get('@table').find('tr:last-child').should('be.visible')
286296
})
287297
it('CHART : should change the chart on options change', () => {
288-
cy.get('@prevSection')
298+
cy.get('@previewSection')
289299
.find('.mat-mdc-tab-labels')
290300
.children('div')
291301
.eq(2)
292302
.click()
293-
cy.get('@prevSection')
303+
cy.get('@previewSection')
294304
.find('gn-ui-chart-view')
295305
.find('gn-ui-dropdown-selector')
296-
.find('select')
297306
.filter(':visible')
298307
.as('drop')
299-
cy.get('@drop').eq(0).select('pie chart')
300-
cy.get('@drop').eq(2).select('men')
301-
cy.get('@drop').eq(3).select('average')
302-
cy.get('@prevSection')
308+
cy.get('@drop').eq(0).selectDropdownOption('pie')
309+
cy.get('@drop').eq(2).selectDropdownOption('men')
310+
cy.get('@drop').eq(3).selectDropdownOption('average')
311+
cy.get('@previewSection')
303312
.find('gn-ui-chart')
304313
.invoke('attr', 'ng-reflect-type')
305314
.should('include', 'pie')
306-
cy.get('@prevSection')
315+
cy.get('@previewSection')
307316
.find('gn-ui-chart')
308317
.invoke('attr', 'ng-reflect-value-property')
309318
.should('include', 'average(men)')
@@ -368,7 +377,6 @@ describe('dataset pages', () => {
368377
.find('gn-ui-download-item')
369378
.first()
370379
.click()
371-
cy.wait(4000)
372380
cy.exec('ls cypress/downloads').then((result) => {
373381
const fileList = result.stdout.split('\n')
374382

@@ -417,19 +425,14 @@ describe('dataset pages', () => {
417425
.find('button')
418426
.first()
419427
.click({ force: true })
420-
// eslint-disable-next-line cypress/unsafe-to-chain-command
421-
cy.wait(500)
422-
.get('body')
423-
.focus()
424-
.realClick()
425-
.window()
426-
.then((win) => {
427-
win.navigator.clipboard.readText().then((text) => {
428-
expect(text).to.eq(
429-
'https://www.geo2france.fr/geoserver/insee/ows'
430-
)
431-
})
428+
// attempt to make the whole page focused
429+
cy.get('body').focus()
430+
cy.get('body').realClick()
431+
cy.window().then((win) => {
432+
win.navigator.clipboard.readText().then((text) => {
433+
expect(text).to.eq('https://www.geo2france.fr/geoserver/insee/ows')
432434
})
435+
})
433436
})
434437
it('goes to dataset on click', () => {
435438
let targetLink
@@ -458,21 +461,21 @@ describe('record with file distributions', () => {
458461
cy.get('gn-ui-record-metadata')
459462
.find('[id="preview"]')
460463
.first()
461-
.as('prevSection')
462-
cy.get('@prevSection')
464+
.as('previewSection')
465+
cy.get('@previewSection')
463466
.find('.mat-mdc-tab-labels')
464467
.children('div')
465468
.eq(1)
466469
.click()
467470
})
468471

469472
it('should display the distributions by priority', () => {
470-
cy.get('@prevSection')
473+
cy.get('@previewSection')
471474
.find('gn-ui-dropdown-selector')
472475
.last()
473-
.find('select')
474-
.children('option')
475-
.then((options) => options.toArray().map((el) => el.text))
476+
.openDropdown()
477+
.children('button')
478+
.then((options) => options.toArray().map((el) => el.innerText.trim()))
476479
.should('deep.eq', ['csv (csv)', 'json (json)', 'geojson (geojson)'])
477480
})
478481
})

apps/datahub-e2e/src/e2e/datasets.cy.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ describe('datasets', () => {
44
beforeEach(() => {
55
cy.clearCookies()
66
cy.visit('/search')
7-
cy.viewport(1700, 1200)
87

98
// aliases
109
cy.get('gn-ui-results-list-item').find('a').as('results')
@@ -13,7 +12,7 @@ describe('datasets', () => {
1312
.then(($results) => $results.length)
1413
.as('resultsCount')
1514
cy.get('gn-ui-filter-dropdown').as('filters')
16-
cy.get('gn-ui-sort-by').as('sortBy')
15+
cy.get('gn-ui-sort-by').find('gn-ui-dropdown-selector').as('sortBy')
1716
cy.get('[data-cy="addMoreBtn"]').as('addMoreBtn')
1817
})
1918

@@ -46,15 +45,15 @@ describe('datasets', () => {
4645
})
4746
it('should sort by relevance initially', () => {
4847
cy.get('@sortBy')
49-
.find('option:checked')
50-
.invoke('val')
48+
.getActiveDropdownOption()
49+
.invoke('attr', 'data-cy-value')
5150
.should('equal', 'desc,_score')
5251
})
5352
})
5453

5554
describe('display of dataset previews', () => {
5655
it('should display a logo for first and a placeholder for second result', () => {
57-
cy.get('@sortBy').find('select').select('desc,createDate') // this makes the order reliable
56+
cy.get('@sortBy').selectDropdownOption('desc,createDate') // this makes the order reliable
5857
cy.get('@firstResult')
5958
.find('gn-ui-thumbnail')
6059
.children('div')
@@ -417,7 +416,7 @@ describe('datasets', () => {
417416
describe('sorting results', () => {
418417
describe('sort by popularity', () => {
419418
beforeEach(() => {
420-
cy.get('@sortBy').find('select').select('desc,userSavedCount')
419+
cy.get('@sortBy').selectDropdownOption('desc,userSavedCount')
421420
cy.get('@results')
422421
.find('gn-ui-favorite-star')
423422
.find('span')
@@ -436,14 +435,14 @@ describe('datasets', () => {
436435
describe('sort by date', () => {
437436
beforeEach(() => {
438437
// first sort by popularity
439-
cy.get('@sortBy').find('select').select('desc,userSavedCount')
438+
cy.get('@sortBy').selectDropdownOption('desc,userSavedCount')
440439
cy.get('@results')
441440
.find('[data-cy="recordTitle"]')
442441
.then(($titles) =>
443442
$titles.toArray().map((title) => title.innerText.trim())
444443
)
445444
.as('initialResultTitles')
446-
cy.get('@sortBy').find('select').select('desc,createDate')
445+
cy.get('@sortBy').selectDropdownOption('desc,createDate')
447446
})
448447
it('changes the results order', () => {
449448
cy.get('@initialResultTitles').then((initialResultTitles) => {

apps/datahub-e2e/src/e2e/header.cy.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,18 @@ describe('header', () => {
121121
it('should sort results by latest date', () => {
122122
cy.get('gn-ui-fuzzy-search').next().find('button').first().click()
123123
cy.get('gn-ui-record-preview-row').should('not.eq', '@initialList')
124-
cy.get('gn-ui-sort-by option:selected').should(
125-
'have.value',
126-
'desc,createDate'
127-
)
124+
cy.get('gn-ui-sort-by gn-ui-dropdown-selector')
125+
.getActiveDropdownOption()
126+
.invoke('attr', 'data-cy-value')
127+
.should('equal', 'desc,createDate')
128128
})
129129
it('should filter results by popularity', () => {
130130
cy.get('gn-ui-fuzzy-search').next().find('button').eq(1).click()
131131
cy.get('gn-ui-record-preview-row').should('not.eq', '@initialList')
132-
cy.get('gn-ui-sort-by option:selected').should(
133-
'have.value',
134-
'desc,userSavedCount'
135-
)
132+
cy.get('gn-ui-sort-by gn-ui-dropdown-selector')
133+
.getActiveDropdownOption()
134+
.invoke('attr', 'data-cy-value')
135+
.should('equal', 'desc,userSavedCount')
136136
})
137137
})
138138
})

apps/datahub-e2e/src/e2e/home.cy.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,13 @@ describe('header', () => {
9090
.find('[data-cy=recordTitle]')
9191
.invoke('text')
9292
.as('favoriteTitle')
93-
cy.get('@favoriteItem').find('gn-ui-favorite-star').click()
93+
cy.get('@favoriteItem').find('gn-ui-favorite-star button').click()
94+
cy.wait(100)
9495

9596
// show my favorites only
96-
cy.get('datahub-header-badge-button[label$=favorites]').realClick()
97+
cy.get('datahub-header-badge-button[label$=favorites] button').click({
98+
force: true,
99+
})
97100
})
98101
it('only shows one record, same as the favorite one', () => {
99102
cy.get('gn-ui-results-list-item').should('have.length', 1)

apps/datahub-e2e/src/e2e/organizations.cy.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ import 'cypress-real-events'
33
describe('organizations', () => {
44
beforeEach(() => {
55
cy.visit('/home/organisations')
6-
cy.viewport(1700, 1200)
76

87
// aliases
98
cy.get('gn-ui-organisations-sort')
109
.find('gn-ui-dropdown-selector')
11-
.find('select')
1210
.as('sort')
1311
cy.get('gn-ui-pagination').children('div').as('pagination')
1412
cy.get('gn-ui-organisations')
@@ -35,7 +33,7 @@ describe('organizations', () => {
3533
})
3634
it('should display the welcome panel', () => {
3735
cy.get('gn-ui-organisations-sort').should('be.visible')
38-
cy.get('@sort').children('option').should('have.length', 4)
36+
cy.get('@sort').openDropdown().children('button').should('have.length', 4)
3937
})
4038
it('should display organizations with thumbnail, title and description', () => {
4139
cy.get('@organizations').find('gn-ui-thumbnail').should('be.visible')
@@ -93,28 +91,28 @@ describe('organizations', () => {
9391
}
9492

9593
it('should order the list alphabetically (asc)', () => {
96-
cy.get('@sort').select('asc,name')
94+
cy.get('@sort').selectDropdownOption('asc,name')
9795
cy.get('@organizationsName').then(($orgsName) => {
9896
const orderedNames = getInnerTexts($orgsName)
9997
expect(orderedNames).to.eql(orderBy(orderedNames, 1))
10098
})
10199
})
102100
it('should order the list alphabetically (desc)', () => {
103-
cy.get('@sort').select('desc,name')
101+
cy.get('@sort').selectDropdownOption('desc,name')
104102
cy.get('@organizationsName').then(($orgsName) => {
105103
const orderedNames = getInnerTexts($orgsName)
106104
expect(orderedNames).to.eql(orderBy(orderedNames, -1))
107105
})
108106
})
109107
it('should order the list by dataset count (asc)', () => {
110-
cy.get('@sort').select('asc,recordCount')
108+
cy.get('@sort').selectDropdownOption('asc,recordCount')
111109
cy.get('@organizationsRecordsCount').then(($orgsRecordsCount) => {
112110
const orderedCounts = getInnerTexts($orgsRecordsCount)
113111
expect(orderedCounts).to.eql(orderBy(orderedCounts, 1))
114112
})
115113
})
116114
it('should order the list by dataset count (desc)', () => {
117-
cy.get('@sort').select('desc,recordCount')
115+
cy.get('@sort').selectDropdownOption('desc,recordCount')
118116
cy.get('@organizationsRecordsCount').then(($orgsRecordsCount) => {
119117
const orderedCounts = getInnerTexts($orgsRecordsCount)
120118
expect(orderedCounts).to.eql(orderBy(orderedCounts, -1))

0 commit comments

Comments
 (0)