Skip to content

Commit

Permalink
test: Make cypress tests more resilent
Browse files Browse the repository at this point in the history
Wait for HTTP requests and use proper selectors

Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Jul 12, 2024
1 parent f3c467d commit b5d3a1c
Show file tree
Hide file tree
Showing 12 changed files with 522 additions and 477 deletions.
4 changes: 3 additions & 1 deletion cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ export default defineConfig({
trashAssetsBeforeRuns: true,

e2e: {
testIsolation: false,
testIsolation: true,

requestTimeout: 10000,

// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
Expand Down
63 changes: 50 additions & 13 deletions cypress/e2e/filesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,39 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

export function renameFile(fileName: string, newName: string) {
toggleMenuAction(fileName)
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="rename"]`).click()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename input`).clear()
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename input`).type(`${newName}.txt`)
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] .files-list__row-rename`).submit()
cy.get('.toast-close').click()
cy.wait(500)
import { SidebarPage } from "../pages/SidebarPage"

export const getRowForFile = (filename: string) => cy.get(`[data-cy-files-list-row-name="${CSS.escape(filename)}"]`)
export const getActionsForFile = (filename: string) => getRowForFile(filename).find('[data-cy-files-list-row-actions]')
export const getActionButtonForFile = (filename: string) => getActionsForFile(filename).find('button[aria-label="Actions"]')
export const triggerActionForFile = (filename: string, actionId: string) => {
getActionButtonForFile(filename)
.click({ force: true })
cy.get(`[data-cy-files-list-row-action="${CSS.escape(actionId)}"] > button`)
.should('exist')
.click({ force: true })
}

export function renameFile(fileName: string, newFileName: string) {
getRowForFile(fileName)
triggerActionForFile(fileName, 'rename')

// intercept the move so we can wait for it
cy.intercept('MOVE', /\/remote.php\/dav\/files\//).as('moveFile')

getRowForFile(fileName)
.find('[data-cy-files-list-row-name] input')
.should('be.visible')
.clear()
getRowForFile(fileName).find('[data-cy-files-list-row-name] input').type(`${newFileName}{enter}`)

cy.wait('@moveFile')
cy.findByRole('button', { name: 'All files' }).click()

getRowForFile(newFileName).should('be.visible')
}


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

toggleMenuAction(fileName)
cy.get(`[data-cy-files-list] [data-cy-files-list-row-action="move-copy"]`).click()
triggerActionForFile(fileName, 'move-copy')

cy.get('.file-picker').within(() => {
cy.get(`[data-filename="${dirName}"]`).click()
cy.contains(`Move to ${dirName}`).click()
Expand All @@ -43,7 +66,21 @@ export function moveFile (fileName: string, dirName: string) {
cy.wait('@moveFile')
}

export function toggleMenuAction(fileName: string) {
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"] [data-cy-files-list-row-actions] .action-item__menutoggle`).click()
cy.get('[data-cy-files-list-row-action]').should('be.visible')
export function toggleFavorite(fileName: string) {
cy.intercept('POST', `**/apps/files/api/v1/files/${fileName}`).as('makeFavorite')

triggerActionForFile(fileName, 'favorite')

cy.wait('@makeFavorite')
cy.get('.toast-close').should('be.visible').click()
}

export function showSidebarForFile(fileName: string) {
const sidebar = new SidebarPage()
sidebar.close()

triggerActionForFile(fileName, 'details')

sidebar.sidebar()
.should('be.visible')
}
66 changes: 30 additions & 36 deletions cypress/e2e/settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,63 +4,56 @@
*/

describe('Check that user\'s settings survive a reload', () => {
before(() => {

beforeEach(() => {
cy.createRandomUser()
.then((user) => {
cy.login(user)
cy.visit('/settings/user/notifications')
})
})

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

cy.reload()
cy.wait('@checkbox')
}

it('Form survive a reload', () => {
cy.get('#file_changed_notification').should('not.be.checked')
cy.get('#comments_email').should('not.be.checked')
cy.get('#comments_notification').should('not.be.checked')
cy.get('#calendar_email').should('not.be.checked')
cy.get('#calendar_notification').should('not.be.checked')
cy.get('#systemtags_email').should('not.be.checked')
cy.get('#personal_settings_notification').should('not.be.checked')

cy.get("#app-content input[type='checkbox']").uncheck({ force: true })
cy.get("#app-content input[type='checkbox']").should('not.be.checked')
checkBox('#file_changed_notification')
checkBox('#comments_email')
checkBox('#comments_notification')
checkBox('#calendar_email')
checkBox('#calendar_notification')
checkBox('#systemtags_email')
checkBox('#personal_settings_notification')

cy.get('#file_changed_notification').check({ force: true })
cy.get('#comments_email').check({ force: true })
cy.get('#comments_notification').check({ force: true })
cy.get('#calendar_email').check({ force: true })
cy.get('#calendar_notification').check({ force: true })
cy.get('#personal_settings_email').check({ force: true })
cy.get('#personal_settings_notification').check({ force: true })
cy.reload()

cy.get('#file_changed_email').should('not.be.checked')
cy.get('#file_changed_notification').should('be.checked')
cy.get('#shared_email').should('not.be.checked')
cy.get('#shared_notification').should('not.be.checked')
cy.get('#remote_share_email').should('not.be.checked')
cy.get('#remote_share_notification').should('not.be.checked')
cy.get('#public_links_email').should('not.be.checked')
cy.get('#public_links_notification').should('not.be.checked')
cy.get('#comments_email').should('be.checked')
cy.get('#comments_notification').should('be.checked')
cy.get('#calendar_email').should('be.checked')
cy.get('#calendar_notification').should('be.checked')
cy.get('#calendar_event_email').should('not.be.checked')
cy.get('#calendar_event_notification').should('not.be.checked')
cy.get('#calendar_todo_email').should('not.be.checked')
cy.get('#calendar_todo_notification').should('not.be.checked')
cy.get('#contacts_email').should('not.be.checked')
cy.get('#contacts_notification').should('not.be.checked')
cy.get('#group_settings_email').should('not.be.checked')
cy.get('#group_settings_notification').should('not.be.checked')
cy.get('#personal_settings_email').should('not.be.checked')
cy.get('#systemtags_email').should('be.checked')
cy.get('#personal_settings_notification').should('be.checked')
cy.get('#security_email').should('be.checked')
cy.get('#security_notification').should('not.be.checked')
cy.get('#comments_email').should('be.checked')
cy.get('#comments_notification').should('be.checked')
cy.get('#systemtags_email').should('not.be.checked')
cy.get('#systemtags_notification').should('not.be.checked')
})

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

cy.get('.notification-frequency__select').scrollIntoView()
cy.get('.notification-frequency__select').select('Weekly')

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

cy.contains('[data-cy-checkbox]', 'Send daily activity summary in the morning')
.scrollIntoView()
.find('input')
.check({ force: true })
cy.contains('[data-cy-checkbox]', 'Send daily activity summary in the morning')
Expand Down
85 changes: 57 additions & 28 deletions cypress/e2e/sidebar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,100 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

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

describe('Check activity listing in the sidebar', { testIsolation: true }, () => {
let sidebar: SidebarPage

beforeEach(function() {
cy.createRandomUser()
.then((user) => {
cy.login(user)
cy.visit('/apps/files')
sidebar = new SidebarPage()
})
})

it('Has creation activity', () => {
showActivityTab('welcome.txt')
cy.get('.activity-entry').last().should('contains.text', 'You created')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.last()
.should('contains.text', 'You created')
})

it('Has favorite activity', () => {
addToFavorites('welcome.txt')
showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'Added to favorites')
toggleFavorite('welcome.txt')

showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'Added to favorites')
sidebar.close()

cy.reload()
toggleFavorite('welcome.txt')

removeFromFavorites('welcome.txt')
showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'Removed from favorites')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'Removed from favorites')
})

it('Has share activity', () => {
createPublicShare('welcome.txt')
cy.get('body').contains('Link share created').should('exist')
cy.get('.toast-close').click({ multiple: true })
showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'Shared as public link')
showSidebarForFile('welcome.txt')
sidebar.createPublicShare()
sidebar.close()

showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'Shared as public link')
})

it('Has rename activity', () => {
renameFile('welcome.txt', 'new name')
renameFile('new name.txt', 'welcome')
it('Has rename activity', { retries: 5 }, () => {
renameFile('welcome.txt', 'new name.txt')
renameFile('new name.txt', 'welcome.txt')

showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'You renamed')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'You renamed')
})

it('Has move activity', () => {
createFolder('Test folder')
moveFile('welcome.txt', 'Test folder')
cy.get('.toast-close').click({ multiple: true })

goToDir('Test folder')

showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'You moved')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'You moved')
})

it('Has tag activity', () => {
addTag('welcome.txt', 'my_tag')
showSidebarForFile('welcome.txt')
sidebar.addTag('some cool tag')
sidebar.close()

showActivityTab('welcome.txt')
cy.get('.activity-entry').first().should('contains.text', 'Added system tag')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'Added system tag')
})

it('Has comment activity', () => {
addComment('welcome.txt', 'A comment')
showSidebarForFile('welcome.txt')
sidebar.addComment('A comment')
sidebar.close()

showActivityTab('welcome.txt')
cy.get('.comments-activity').first().should('contains.text', 'A comment')
showSidebarForFile('welcome.txt')
sidebar.getActivities()
.first()
.should('contains.text', 'A comment')
})

})
74 changes: 0 additions & 74 deletions cypress/e2e/sidebarUtils.ts

This file was deleted.

Loading

0 comments on commit b5d3a1c

Please sign in to comment.