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 c91577d commit d836e25
Show file tree
Hide file tree
Showing 11 changed files with 518 additions and 452 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
40 changes: 38 additions & 2 deletions cypress/e2e/filesUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { SidebarPage } from "../pages/SidebarPage"

export function renameFile(fileName: string, newName: string) {
cy.intercept('MOVE', '**/remote.php/dav/files/**').as('renameFile')

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.wait('@renameFile')
cy.get('.toast-close').click()
cy.wait(500)
}

export function goToDir(dirName: string) {
Expand Down Expand Up @@ -45,5 +50,36 @@ export function moveFile (fileName: string, dirName: string) {

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')
cy.get('[role="menu"] [data-cy-files-list-row-action]').should('be.visible')
}

export function addToFavorites(fileName: string) {
cy.intercept('POST', `**/apps/files/api/v1/files/${fileName}`).as('makeFavorite')

toggleMenuAction(fileName)
cy.get('[data-cy-files-list-row-action="favorite"]').should('contain', 'Add to favorites').click()

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

export function removeFromFavorites(fileName: string) {
cy.intercept('POST', `**/apps/files/api/v1/files/${fileName}`).as('makeFavorite')

toggleMenuAction(fileName)
cy.get('[data-cy-files-list-row-action="favorite"]').should('contain', 'Remove from favorites').click()

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

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

toggleMenuAction(fileName)
cy.get('[data-cy-files-list-row-action="details"] button').click()

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
74 changes: 51 additions & 23 deletions cypress/e2e/sidebar.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
* 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 { addToFavorites, createFolder, goToDir, moveFile, removeFromFavorites, renameFile, showSidebarForFile } from './filesUtils'
import { SidebarPage } from '../pages/SidebarPage'

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

beforeEach(function() {
cy.createRandomUser()
.then((user) => {
Expand All @@ -16,58 +18,84 @@ describe('Check activity listing in the sidebar', { testIsolation: true }, () =>
})

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')

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

cy.reload()
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')

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 d836e25

Please sign in to comment.