Skip to content

Commit

Permalink
Merge pull request #43762 from nextcloud/fix/cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Feb 22, 2024
2 parents 84693f8 + 5b757c3 commit 0254af8
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 74 deletions.
39 changes: 19 additions & 20 deletions cypress/e2e/files_versions/filesVersionsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
*
*/

import path from "path"
import type { User } from "@nextcloud/cypress"
import type { User } from '@nextcloud/cypress'
import path from 'path'

export function uploadThreeVersions(user: User, fileName: string) {
export const uploadThreeVersions = (user: User, fileName: string) => {
// A new version will not be created if the changes occur
// within less than one second of each other.
// eslint-disable-next-line cypress/no-unnecessary-waiting
Expand All @@ -35,23 +35,22 @@ export function uploadThreeVersions(user: User, fileName: string) {
cy.login(user)
}

export function openVersionsPanel(fileName: string) {
cy.get(`[data-cy-files-list] [data-cy-files-list-row-name="${fileName}"]`).within(() => {
cy.get('[data-cy-files-list-row-actions] .action-item__menutoggle')
.click()
})

cy.get('.action-item__popper')
.get('[data-cy-files-list-row-action="details"]')
.click()
export const openVersionsPanel = (fileName: string) =>{
// Detect the versions list fetch
cy.intercept('PROPFIND', '**/dav/versions/*/versions/**').as('getVersions')

cy.get('#app-sidebar-vue')
.get('[aria-controls="tab-version_vue"]')
.click()
// Open the versions tab
cy.window().then(win => {
win.OCA.Files.Sidebar.setActiveTab('version_vue')
win.OCA.Files.Sidebar.open(`/${fileName}`)
})

// Wait for the versions list to be fetched
cy.wait('@getVersions')
cy.get('#tab-version_vue').should('be.visible', { timeout: 10000 })
}

export function openVersionMenu(index: number) {
export const openVersionMenu = (index: number) => {
cy.get('#tab-version_vue').within(() => {
cy.get('[data-files-versions-version]')
.eq(index).within(() => {
Expand All @@ -61,19 +60,19 @@ export function openVersionMenu(index: number) {
})
}

export function clickPopperAction(actionName: string) {
export const clickPopperAction = (actionName: string) => {
cy.get('.v-popper__popper').filter(':visible')
.contains(actionName)
.click()
}

export function nameVersion(index: number, name: string) {
export const nameVersion = (index: number, name: string) => {
openVersionMenu(index)
clickPopperAction('Name this version')
cy.get(':focused').type(`${name}{enter}`)
}

export function assertVersionContent(filename: string, index: number, expectedContent: string) {
export const assertVersionContent = (filename: string, index: number, expectedContent: string) => {
const downloadsFolder = Cypress.config('downloadsFolder')

openVersionMenu(index)
Expand All @@ -82,4 +81,4 @@ export function assertVersionContent(filename: string, index: number, expectedCo
return cy.readFile(path.join(downloadsFolder, filename))
.then((versionContent) => expect(versionContent).to.equal(expectedContent))
.then(() => cy.exec(`rm ${downloadsFolder}/${filename}`))
}
}
4 changes: 3 additions & 1 deletion cypress/e2e/files_versions/version_restoration.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@

import { assertVersionContent, clickPopperAction, openVersionMenu, openVersionsPanel, uploadThreeVersions } from './filesVersionsUtils'

function restoreVersion(index: number) {
const restoreVersion = (index: number) => {
cy.intercept('MOVE', '**/dav/versions/*/versions/**').as('restoreVersion')
openVersionMenu(index)
clickPopperAction('Restore version')
cy.wait('@restoreVersion')
}

describe('Versions restoration', () => {
Expand Down
126 changes: 75 additions & 51 deletions cypress/e2e/theming/navigation-bar-settings.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ describe('Admin theming set default apps', () => {
it('See the current default app is the dashboard', () => {
cy.visit('/')
cy.url().should('match', /apps\/dashboard/)

// Also check the top logo link
cy.get('#nextcloud').click()
cy.url().should('match', /apps\/dashboard/)
})
Expand All @@ -54,9 +56,9 @@ describe('Admin theming set default apps', () => {
})

it('See the default app order selector', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})
})

Expand All @@ -70,13 +72,17 @@ describe('Admin theming set default apps', () => {
})

it('See the default app is changed', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['files', 'dashboard'])
})

cy.get('#nextcloud').click()
cy.url().should('match', /apps\/files/)
// Check the redirect to the default app works
cy.request({ url: '/', followRedirect: false }).then((response) => {
expect(response.status).to.eq(302)
expect(response).to.have.property('headers')
expect(response.headers.location).to.contain('/apps/files')
})
})

it('Toggle the "use custom default app" switch back to reset the default apps', () => {
Expand All @@ -89,9 +95,12 @@ describe('Admin theming set default apps', () => {
})

it('See the default app is changed back to default', () => {
cy.reload()
cy.get('#nextcloud').click()
cy.url().should('match', /apps\/dashboard/)
// Check the redirect to the default app works
cy.request({ url: '/', followRedirect: false }).then((response) => {
expect(response.status).to.eq(302)
expect(response).to.have.property('headers')
expect(response.headers.location).to.contain('/apps/dashboard')
})
})
})

Expand All @@ -117,14 +126,16 @@ describe('User theming set app order', () => {
})

it('See that the dashboard app is the first one', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
// Check the app order settings UI
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})

cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-app-id', 'files')
// Check the top app menu order
cy.get('.app-menu-main .app-menu-entry').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})
})

Expand All @@ -133,17 +144,17 @@ describe('User theming set app order', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')

cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['files', 'dashboard'])
})
})

it('See the app menu order is changed', () => {
cy.reload()
cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
else cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
cy.get('.app-menu-main .app-menu-entry').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
expect(appIDs).to.deep.eq(['files', 'dashboard'])
})
})
})
Expand Down Expand Up @@ -171,20 +182,21 @@ describe('User theming set app order with default app', () => {
})

it('See files is the default app', () => {
cy.visit('/')
cy.url().should('match', /apps\/files/)

cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
// Check the redirect to the default app works
cy.request({ url: '/', followRedirect: false }).then((response) => {
expect(response.status).to.eq(302)
expect(response).to.have.property('headers')
expect(response.headers.location).to.contain('/apps/files')
})
})

it('See the app order settings: files is the first one', () => {
cy.visit('/settings/user/theming')
cy.get('[data-cy-app-order]').scrollIntoView()
cy.get('[data-cy-app-order] [data-cy-app-order-element]').should('have.length', 4).each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
else if (idx === 1) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
expect(elements).to.have.length(4)
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['files', 'dashboard', 'testapp1', 'testapp'])
})
})

Expand All @@ -200,22 +212,31 @@ describe('User theming set app order with default app', () => {
})

it('Change the order of the other apps', () => {
cy.intercept('POST', '**/apps/provisioning_api/api/v1/config/users/core/apporder').as('setAppOrder')

// Move the testapp up twice, it should be the first one after files
cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
cy.wait('@setAppOrder')
cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click()
cy.wait('@setAppOrder')

// Can't get up anymore, files is enforced as default app
cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('not.be.visible')

cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
else if (idx === 1) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'testapp')
else if (idx === 2) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
// Check the final list order
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
expect(elements).to.have.length(4)
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['files', 'testapp', 'dashboard', 'testapp1'])
})
})

it('See the app menu order is changed', () => {
cy.reload()
cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files')
else if (idx === 1) cy.wrap($el).should('have.attr', 'data-app-id', 'testapp')
else if (idx === 2) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
cy.get('.app-menu-main .app-menu-entry').then(elements => {
expect(elements).to.have.length(4)
const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
expect(appIDs).to.deep.eq(['files', 'testapp', 'dashboard', 'testapp1'])
})
})
})
Expand Down Expand Up @@ -289,14 +310,16 @@ describe('User theming reset app order', () => {
})

it('See that the dashboard app is the first one', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
// Check the app order settings UI
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})

cy.get('.app-menu-main .app-menu-entry').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-app-id', 'files')
// Check the top app menu order
cy.get('.app-menu-main .app-menu-entry').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-app-id')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})
})

Expand All @@ -310,9 +333,10 @@ describe('User theming reset app order', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').click()
cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('not.be.visible')

cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
// Check the app order settings UI
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['files', 'dashboard'])
})
})

Expand All @@ -326,9 +350,9 @@ describe('User theming reset app order', () => {
})

it('See the app order is restored', () => {
cy.get('[data-cy-app-order] [data-cy-app-order-element]').each(($el, idx) => {
if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'dashboard')
else cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'files')
cy.get('[data-cy-app-order] [data-cy-app-order-element]').then(elements => {
const appIDs = elements.map((idx, el) => el.getAttribute('data-cy-app-order-element')).get()
expect(appIDs).to.deep.eq(['dashboard', 'files'])
})
})

Expand Down
2 changes: 1 addition & 1 deletion cypress/fixtures/testapp/appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<category>games</category>
<bugs>https://github.com/nextcloud/server/issues</bugs>
<dependencies>
<nextcloud min-version="28" max-version="28"/>
<nextcloud min-version="28" max-version="29"/>
</dependencies>
<navigations>
<navigation>
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function installTestApp() {
cy.wrap(version).should('not.be.undefined')
cy.exec(`docker cp '${testAppPath}' nextcloud-cypress-tests-server:/var/www/html/apps`, { log: true })
cy.exec(`docker exec nextcloud-cypress-tests-server sed -i -e 's|-version="[0-9]\\+|-version="${version}|g' apps/testapp/appinfo/info.xml`)
cy.runOccCommand('app:enable testapp')
cy.runOccCommand('app:enable --force testapp')
})
}

Expand Down

0 comments on commit 0254af8

Please sign in to comment.