Skip to content

Commit b5d3a1c

Browse files
committed
test: Make cypress tests more resilent
Wait for HTTP requests and use proper selectors Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent f3c467d commit b5d3a1c

12 files changed

Lines changed: 522 additions & 477 deletions

File tree

cypress.config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export default defineConfig({
4040
trashAssetsBeforeRuns: true,
4141

4242
e2e: {
43-
testIsolation: false,
43+
testIsolation: true,
44+
45+
requestTimeout: 10000,
4446

4547
// We've imported your old cypress plugins here.
4648
// You may want to clean this up later by importing these.

cypress/e2e/filesUtils.ts

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,39 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
export function renameFile(fileName: string, newName: string) {
7-
toggleMenuAction(fileName)
8-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="rename"]`).click()
9-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename input`).clear()
10-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename input`).type(`${newName}.txt`)
11-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename`).submit()
12-
cy.get('.toast-close').click()
13-
cy.wait(500)
6+
import { SidebarPage } from "../pages/SidebarPage"
7+
8+
export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`)
9+
export const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]')
10+
export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]')
11+
export const triggerActionForFile = (filename: string, actionId: string) => {
12+
getActionButtonForFile(filename)
13+
.click({ force: true })
14+
cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`)
15+
.should('exist')
16+
.click({ force: true })
17+
}
18+
19+
export function renameFile(fileName: string, newFileName: string) {
20+
getRowForFile(fileName)
21+
triggerActionForFile(fileName, 'rename')
22+
23+
// intercept the move so we can wait for it
24+
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')
25+
26+
getRowForFile(fileName)
27+
.find('[data-cy-files-list-row-name] input')
28+
.should('be.visible')
29+
.clear()
30+
getRowForFile(fileName).find('[data-cy-files-list-row-name] input').type(`${newFileName}{enter}`)
31+
32+
cy.wait('@moveFile')
33+
cy.findByRole('button', { name: 'All files' }).click()
34+
35+
getRowForFile(newFileName).should('be.visible')
1436
}
1537

38+
1639
export function goToDir(dirName: string) {
1740
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${dirName}"]`).click()
1841
cy.url().should('match', new RegExp(`\\?dir=(.*/)?${encodeURI(dirName)}`))
@@ -33,8 +56,8 @@ export function createFolder (dirName: string) {
3356
export function moveFile (fileName: string, dirName: string) {
3457
cy.intercept('MOVE', '**/remote.php/dav/files/**').as('moveFile')
3558

36-
toggleMenuAction(fileName)
37-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="move-copy"]`).click()
59+
triggerActionForFile(fileName, 'move-copy')
60+
3861
cy.get('.file-picker').within(() => {
3962
cy.get(`[data-filename="${dirName}"]`).click()
4063
cy.contains(`Move to ${dirName}`).click()
@@ -43,7 +66,21 @@ export function moveFile (fileName: string, dirName: string) {
4366
cy.wait('@moveFile')
4467
}
4568

46-
export function toggleMenuAction(fileName: string) {
47-
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] [data-cy-files-list-row-actions] .action-item__menutoggle`).click()
48-
cy.get('[data-cy-files-list-row-action]').should('be.visible')
69+
export function toggleFavorite(fileName: string) {
70+
cy.intercept('POST', `**/apps/files/api/v1/files/${fileName}`).as('makeFavorite')
71+
72+
triggerActionForFile(fileName, 'favorite')
73+
74+
cy.wait('@makeFavorite')
75+
cy.get('.toast-close').should('be.visible').click()
76+
}
77+
78+
export function showSidebarForFile(fileName: string) {
79+
const sidebar = new SidebarPage()
80+
sidebar.close()
81+
82+
triggerActionForFile(fileName, 'details')
83+
84+
sidebar.sidebar()
85+
.should('be.visible')
4986
}

cypress/e2e/settings.cy.ts

Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,56 @@
44
*/
55

66
describe('Check that user\'s settings survive a reload', () => {
7-
before(() => {
7+
8+
beforeEach(() => {
89
cy.createRandomUser()
910
.then((user) => {
1011
cy.login(user)
1112
cy.visit('/settings/user/notifications')
1213
})
1314
})
1415

15-
it('Form survive a reload', () => {
16-
cy.get("#app-content input[type='checkbox']").uncheck({ force: true })
17-
cy.get("#app-content input[type='checkbox']").should('not.be.checked')
16+
function checkBox(id: string) {
17+
cy.intercept('POST', '**/apps/activity/settings').as('checkbox')
18+
cy.get(id)
19+
.scrollIntoView()
20+
.check({ force: true })
1821

19-
cy.reload()
22+
cy.wait('@checkbox')
23+
}
24+
25+
it('Form survive a reload', () => {
26+
cy.get('#file_changed_notification').should('not.be.checked')
27+
cy.get('#comments_email').should('not.be.checked')
28+
cy.get('#comments_notification').should('not.be.checked')
29+
cy.get('#calendar_email').should('not.be.checked')
30+
cy.get('#calendar_notification').should('not.be.checked')
31+
cy.get('#systemtags_email').should('not.be.checked')
32+
cy.get('#personal_settings_notification').should('not.be.checked')
2033

21-
cy.get("#app-content input[type='checkbox']").uncheck({ force: true })
22-
cy.get("#app-content input[type='checkbox']").should('not.be.checked')
34+
checkBox('#file_changed_notification')
35+
checkBox('#comments_email')
36+
checkBox('#comments_notification')
37+
checkBox('#calendar_email')
38+
checkBox('#calendar_notification')
39+
checkBox('#systemtags_email')
40+
checkBox('#personal_settings_notification')
2341

24-
cy.get('#file_changed_notification').check({ force: true })
25-
cy.get('#comments_email').check({ force: true })
26-
cy.get('#comments_notification').check({ force: true })
27-
cy.get('#calendar_email').check({ force: true })
28-
cy.get('#calendar_notification').check({ force: true })
29-
cy.get('#personal_settings_email').check({ force: true })
30-
cy.get('#personal_settings_notification').check({ force: true })
3142
cy.reload()
3243

33-
cy.get('#file_changed_email').should('not.be.checked')
3444
cy.get('#file_changed_notification').should('be.checked')
35-
cy.get('#shared_email').should('not.be.checked')
36-
cy.get('#shared_notification').should('not.be.checked')
37-
cy.get('#remote_share_email').should('not.be.checked')
38-
cy.get('#remote_share_notification').should('not.be.checked')
39-
cy.get('#public_links_email').should('not.be.checked')
40-
cy.get('#public_links_notification').should('not.be.checked')
45+
cy.get('#comments_email').should('be.checked')
46+
cy.get('#comments_notification').should('be.checked')
4147
cy.get('#calendar_email').should('be.checked')
4248
cy.get('#calendar_notification').should('be.checked')
43-
cy.get('#calendar_event_email').should('not.be.checked')
44-
cy.get('#calendar_event_notification').should('not.be.checked')
45-
cy.get('#calendar_todo_email').should('not.be.checked')
46-
cy.get('#calendar_todo_notification').should('not.be.checked')
47-
cy.get('#contacts_email').should('not.be.checked')
48-
cy.get('#contacts_notification').should('not.be.checked')
49-
cy.get('#group_settings_email').should('not.be.checked')
50-
cy.get('#group_settings_notification').should('not.be.checked')
51-
cy.get('#personal_settings_email').should('not.be.checked')
49+
cy.get('#systemtags_email').should('be.checked')
5250
cy.get('#personal_settings_notification').should('be.checked')
53-
cy.get('#security_email').should('be.checked')
54-
cy.get('#security_notification').should('not.be.checked')
55-
cy.get('#comments_email').should('be.checked')
56-
cy.get('#comments_notification').should('be.checked')
57-
cy.get('#systemtags_email').should('not.be.checked')
58-
cy.get('#systemtags_notification').should('not.be.checked')
5951
})
6052

6153
it('Notification frequency survive a reload', () => {
6254
cy.intercept({ method: 'POST', url: '**/activity/settings' }).as('apiCall')
6355

56+
cy.get('.notification-frequency__select').scrollIntoView()
6457
cy.get('.notification-frequency__select').select('Weekly')
6558

6659
cy.wait('@apiCall')
@@ -79,6 +72,7 @@ describe('Check that user\'s settings survive a reload', () => {
7972
cy.intercept({ method: 'POST', url: '**/activity/settings' }).as('apiCall')
8073

8174
cy.contains('[data-cy-checkbox]', 'Send daily activity summary in the morning')
75+
.scrollIntoView()
8276
.find('input')
8377
.check({ force: true })
8478
cy.contains('[data-cy-checkbox]', 'Send daily activity summary in the morning')

cypress/e2e/sidebar.cy.ts

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,100 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6-
import { createFolder, goToDir, moveFile, renameFile } from './filesUtils'
7-
import { addComment, addTag, addToFavorites, createPublicShare, removeFromFavorites, showActivityTab } from './sidebarUtils'
6+
import { createFolder, goToDir, moveFile, renameFile, showSidebarForFile, toggleFavorite } from './filesUtils'
7+
import { SidebarPage } from '../pages/SidebarPage'
88

99
describe('Check activity listing in the sidebar', { testIsolation: true }, () => {
10+
let sidebar: SidebarPage
11+
1012
beforeEach(function() {
1113
cy.createRandomUser()
1214
.then((user) => {
1315
cy.login(user)
1416
cy.visit('/apps/files')
17+
sidebar = new SidebarPage()
1518
})
1619
})
1720

1821
it('Has creation activity', () => {
19-
showActivityTab('welcome.txt')
20-
cy.get('.activity-entry').last().should('contains.text', 'You created')
22+
showSidebarForFile('welcome.txt')
23+
sidebar.getActivities()
24+
.last()
25+
.should('contains.text', 'You created')
2126
})
2227

2328
it('Has favorite activity', () => {
24-
addToFavorites('welcome.txt')
25-
showActivityTab('welcome.txt')
26-
cy.get('.activity-entry').first().should('contains.text', 'Added to favorites')
29+
toggleFavorite('welcome.txt')
30+
31+
showSidebarForFile('welcome.txt')
32+
sidebar.getActivities()
33+
.first()
34+
.should('contains.text', 'Added to favorites')
35+
sidebar.close()
36+
37+
cy.reload()
38+
toggleFavorite('welcome.txt')
2739

28-
removeFromFavorites('welcome.txt')
29-
showActivityTab('welcome.txt')
30-
cy.get('.activity-entry').first().should('contains.text', 'Removed from favorites')
40+
showSidebarForFile('welcome.txt')
41+
sidebar.getActivities()
42+
.first()
43+
.should('contains.text', 'Removed from favorites')
3144
})
3245

3346
it('Has share activity', () => {
34-
createPublicShare('welcome.txt')
35-
cy.get('body').contains('Link share created').should('exist')
36-
cy.get('.toast-close').click({ multiple: true })
37-
showActivityTab('welcome.txt')
38-
cy.get('.activity-entry').first().should('contains.text', 'Shared as public link')
47+
showSidebarForFile('welcome.txt')
48+
sidebar.createPublicShare()
49+
sidebar.close()
50+
51+
showSidebarForFile('welcome.txt')
52+
sidebar.getActivities()
53+
.first()
54+
.should('contains.text', 'Shared as public link')
3955
})
4056

41-
it('Has rename activity', () => {
42-
renameFile('welcome.txt', 'new name')
43-
renameFile('new name.txt', 'welcome')
57+
it('Has rename activity', { retries: 5 }, () => {
58+
renameFile('welcome.txt', 'new name.txt')
59+
renameFile('new name.txt', 'welcome.txt')
4460

45-
showActivityTab('welcome.txt')
46-
cy.get('.activity-entry').first().should('contains.text', 'You renamed')
61+
showSidebarForFile('welcome.txt')
62+
sidebar.getActivities()
63+
.first()
64+
.should('contains.text', 'You renamed')
4765
})
4866

4967
it('Has move activity', () => {
5068
createFolder('Test folder')
5169
moveFile('welcome.txt', 'Test folder')
5270
cy.get('.toast-close').click({ multiple: true })
71+
5372
goToDir('Test folder')
5473

55-
showActivityTab('welcome.txt')
56-
cy.get('.activity-entry').first().should('contains.text', 'You moved')
74+
showSidebarForFile('welcome.txt')
75+
sidebar.getActivities()
76+
.first()
77+
.should('contains.text', 'You moved')
5778
})
5879

5980
it('Has tag activity', () => {
60-
addTag('welcome.txt', 'my_tag')
81+
showSidebarForFile('welcome.txt')
82+
sidebar.addTag('some cool tag')
83+
sidebar.close()
6184

62-
showActivityTab('welcome.txt')
63-
cy.get('.activity-entry').first().should('contains.text', 'Added system tag')
85+
showSidebarForFile('welcome.txt')
86+
sidebar.getActivities()
87+
.first()
88+
.should('contains.text', 'Added system tag')
6489
})
6590

6691
it('Has comment activity', () => {
67-
addComment('welcome.txt', 'A comment')
92+
showSidebarForFile('welcome.txt')
93+
sidebar.addComment('A comment')
94+
sidebar.close()
6895

69-
showActivityTab('welcome.txt')
70-
cy.get('.comments-activity').first().should('contains.text', 'A comment')
96+
showSidebarForFile('welcome.txt')
97+
sidebar.getActivities()
98+
.first()
99+
.should('contains.text', 'A comment')
71100
})
72101

73102
})

cypress/e2e/sidebarUtils.ts

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)