diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index 0ffbef90ed..491a1a5acc 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -50,11 +50,6 @@ jobs: cypress: runs-on: ubuntu-latest - # Specify which version of browser we are testing. - # This prevent hard to track error when the default browser is upgraded and break our tests. - # But this means that we have to regularly update this line. - # https://hub.docker.com/r/cypress/browsers/tags - container: node18.12.0-chrome106-ff106 needs: init strategy: @@ -81,9 +76,6 @@ jobs: # cypress env ci-build-id: ${{ github.sha }}-${{ github.run_number }} tag: ${{ github.event_name }} - # Currently testing on Firefox as chrome does not upload files correctly. - # https://docs.cypress.io/guides/continuous-integration/github-actions#Basic-Setup - browser: firefox env: # Needs to be prefixed with CYPRESS_ CYPRESS_BRANCH: ${{ env.BRANCH }} diff --git a/cypress/e2e/locations.cy.js b/cypress/e2e/locations.cy.js index 4f3ca8eb86..0b7d37517b 100644 --- a/cypress/e2e/locations.cy.js +++ b/cypress/e2e/locations.cy.js @@ -19,41 +19,38 @@ * along with this program. If not, see . * */ -import { randHash } from '../utils' - -const alice = `alice_${randHash()}` +import { uploadTestMedia } from './photosUtils' +import { navigateToLocation, runOccCommand } from './locationsUtils' const resizeObserverLoopErrRe = /^[^(ResizeObserver loop limit exceeded)]/ Cypress.on('uncaught:exception', (err) => { - /* returning false here prevents Cypress from failing the test */ - if (resizeObserverLoopErrRe.test(err.message)) { - return false - } + /* returning false here prevents Cypress from failing the test */ + if (resizeObserverLoopErrRe.test(err.message)) { + return false + } }) describe('Manage locations', () => { - before(function () { - cy.logout() - cy.nextcloudCreateUser(alice, 'password') - - cy.login(alice, 'password') - cy.uploadTestMedia() - cy.runOccCommand(`photos:map-media-to-location --user ${alice}`) - - // wait a bit for things to be settled - cy.wait(1000) - }) - - beforeEach(() => { - cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/locations`) - }) - - it('Check that we detect some locations out of the existing files', () => { - cy.get('ul.collections__list li').should('have.length', 4) - }) - - it('Navigate to location and check that it contains some files', () => { - cy.navigateToLocation('Lauris') - cy.get('.collection li a.file').should('have.length', 1) - }) + before(function() { + cy.createRandomUser() + .then((user) => { + uploadTestMedia(user) + runOccCommand(`photos:map-media-to-location --user ${user.userId}`) + cy.login(user) + cy.visit('/apps/photos') + }) + }) + + beforeEach(() => { + cy.visit('apps/photos/locations') + }) + + it('Check that we detect some locations out of the existing files', () => { + cy.get('ul.collections__list li').should('have.length', 4) + }) + + it('Navigate to location and check that it contains some files', () => { + navigateToLocation('Lauris') + cy.get('[data-test="media"]').should('have.length', 1) + }) }) diff --git a/cypress/e2e/locationsUtils.ts b/cypress/e2e/locationsUtils.ts new file mode 100644 index 0000000000..4223fbf4a4 --- /dev/null +++ b/cypress/e2e/locationsUtils.ts @@ -0,0 +1,34 @@ +/** + * @copyright Copyright (c) 2023 Louis Chmn + * + * @author Louis Chmn + * + * @license AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +export function navigateToCollection(collectionType: string, collectionName: string) { + cy.get('.app-navigation__list').contains(collectionType).click() + cy.get('ul.collections__list').contains(collectionName).click() +} + +export function navigateToLocation(locationName: string) { + navigateToCollection('Places', locationName) +} + +export function runOccCommand(command: string) { + cy.exec(`docker exec --user www-data nextcloud-cypress-tests-photos php ./occ ${command}`) +} diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index dfc5196eb7..ab4e0c8d21 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -113,7 +113,3 @@ Cypress.Commands.add('uploadContent', (user, blob, mimeType, target) => { } }) }) - -Cypress.Commands.add('runOccCommand', (command: string) => { - cy.exec(`docker exec --user www-data nextcloud-cypress-tests-server php ./occ ${command}`) -})