Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Cypress

on:
pull_request:
push:
branches:
- master
- stable*

env:
APP_NAME: photos
BRANCH: ${{ github.base_ref }}
CYPRESS_baseUrl: http://127.0.0.1:8082/index.php
TESTING: true

jobs:
init:
runs-on: ubuntu-latest

steps:
- name: Checkout app
uses: actions/checkout@v3

- name: Read package.json node and npm engines version
uses: skjnldsv/[email protected]
id: versions
with:
fallbackNode: '^12'
fallbackNpm: '^6'

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@v3
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"

- name: Install dependencies & build app
run: |
npm ci
TESTING=true npm run build --if-present

- name: Save context
uses: actions/cache@v3
with:
key: cypress-context-${{ github.run_id }}
path: /home/runner/work/photos

cypress:
runs-on: ubuntu-latest
needs: init

strategy:
fail-fast: false
matrix:
# run multiple copies of the current job in parallel
containers: [1, 2, 3, 4, 5, 6, 7, 8]

name: runner ${{ matrix.containers }}

steps:
- name: Restore context
uses: actions/cache@v3
with:
key: cypress-context-${{ github.run_id }}
path: /home/runner/work/photos

- name: Setup server
run: |
cd cypress
docker-compose up -d

- name: Wait for server
run: npm run wait-on $CYPRESS_baseUrl

- name: Enable app & configure server
run: |
cd cypress
docker-compose exec --env APP_NAME=${{ env.APP_NAME }} --env BRANCH=${{ env.BRANCH }} -T nextcloud bash /initserver.sh

- name: Cypress run
uses: cypress-io/github-action@v4
with:
record: true
parallel: true
# cypress env
ci-build-id: ${{ github.sha }}-${{ github.run_number }}
tag: ${{ github.event_name }}
env:
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# https://github.com/cypress-io/github-action/issues/124
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }}
TESTING: true

- name: Upload snapshots
uses: actions/upload-artifact@v3
if: always()
with:
name: snapshots
path: cypress/snapshots

summary:
runs-on: ubuntu-latest
needs: [init, cypress]

if: always()

name: cypress-summary

steps:
- name: Summary status
run: if ${{ needs.init.result != 'success' || ( needs.cypress.result != 'success' && needs.cypress.result != 'skipped' ) }}; then exit 1; fi
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ coverage/
vendor
.php_cs.cache
.php-cs-fixer.cache

cypress/videos
cypress/snapshots
cypress/downloads
17 changes: 17 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
'path' => '',
]
],
['name' => 'page#index', 'url' => '/sharedalbums/{path}', 'verb' => 'GET', 'postfix' => 'sharedalbums',
'requirements' => [
'path' => '.*',
],
'defaults' => [
'path' => '',
]
],
['name' => 'page#index', 'url' => '/folders/{path}', 'verb' => 'GET', 'postfix' => 'folders',
'requirements' => [
'path' => '.*',
Expand Down Expand Up @@ -110,5 +118,14 @@
'path' => '',
],
],

[
'name' => 'preview#index',
'url' => '/api/v1/preview/{fileId}',
'verb' => 'GET',
'requirements' => [
'fileId' => '.*',
]
],
]
];
26 changes: 26 additions & 0 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { defineConfig } = require("cypress");
const browserify = require('@cypress/browserify-preprocessor')

module.exports = defineConfig({
viewportWidth: 1280,
viewportHeight: 720,
defaultCommandTimeout: 6000,
retries: 1,

env: {
failSilently: false,
type: 'actual',
},

screenshotsFolder: 'cypress/snapshots/actual',
trashAssetsBeforeRuns: true,

e2e: {
baseUrl: 'http://localhost:8082/index.php',

setupNodeEvents(on, config) {
// Fix browserslist extend https://github.com/cypress-io/cypress/issues/2983#issuecomment-570616682
on('file:preprocessor', browserify())
},
},
});
11 changes: 11 additions & 0 deletions cypress/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
env: {
'cypress/globals': true,
},
plugins: [
'cypress',
],
extends: [
'plugin:cypress/recommended',
],
};
18 changes: 18 additions & 0 deletions cypress/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

services:
nextcloud:
image: ghcr.io/nextcloud/continuous-integration-shallow-server

ports:
- 8082:80

environment:
CYPRESS_baseUrl: "http://127.0.0.1:8082/index.php"
BRANCH: "${BRANCH:-master}"

volumes:
# Using fallback to make sure this script doesn't mess
# with the mounting if APP_NAME is not provided.
- ../:/var/www/html/apps/${APP_NAME:-photos}
- ./initserver.sh:/initserver.sh
102 changes: 102 additions & 0 deletions cypress/e2e/albums.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* @copyright Copyright (c) 2022 Louis Chmn <[email protected]>
*
* @author Louis Chmn <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>.
*
*/
import { randHash } from '../utils'
const randUser = randHash()

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

describe('Manage albums', () => {
before(function () {
cy.logout()
cy.nextcloudCreateUser(randUser, 'password')

cy.login(randUser, 'password')
cy.uploadTestMedia()

// wait a bit for things to be settled
cy.wait(1000)
})

beforeEach(() => {
cy.visit(`${Cypress.env('baseUrl')}/index.php/apps/photos/albums`)
cy.createAnAlbumFromAlbums('albums_test')
cy.addFilesToAlbumFromAlbum('albums_test', [0, 1, 2])
})

afterEach(() => {
cy.deleteAnAlbumFromAlbumContent()
cy.contains("There is no album yet!").click()
})

it('Add and remove a file to an album from an album', () => {
cy.selectMedia([0])
cy.removeSelectionFromAlbum()
})

it('Add and remove multiple files to an album from an album', () => {
cy.selectMedia([0, 1])
cy.removeSelectionFromAlbum()
})

it('Favorite a file from an album', () => {
cy.selectMedia([0])
cy.favoriteSelection()
cy.get('[data-test="media"]').eq(0).find('[aria-label="The file is in the favorites"]')
cy.unfavoriteSelection()
cy.unselectMedia([0])
cy.get('[aria-label="The file is in the favorites"]').should('not.exist')
})

it('Favorite multiple files from an album', () => {
cy.selectMedia([1, 2])
cy.favoriteSelection()
cy.get('[data-test="media"]').eq(1).find('[aria-label="The file is in the favorites"]')
cy.get('[data-test="media"]').eq(2).find('[aria-label="The file is in the favorites"]')
cy.unfavoriteSelection()
cy.unselectMedia([1, 2])
cy.get('[aria-label="The file is in the favorites"]').should('not.exist')
})

it('Download a file from an album', () => {
cy.selectMedia([0])
cy.downloadSelection()
cy.unselectMedia([0])
})

it('Download multiple files from an album', () => {
cy.selectMedia([1, 2])
cy.downloadSelection()
cy.unselectMedia([1, 2])
})

it('Download all files from an album', () => {
cy.selectMedia([1, 2])
cy.downloadSelection()
cy.unselectMedia([1, 2])
})
})
Loading