-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from nextcloud/test/cypress
Add Cypress test for personal settings
- Loading branch information
Showing
10 changed files
with
2,920 additions
and
800 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module.exports = { | ||
extends: [ | ||
'@nextcloud', | ||
'plugin:cypress/recommended', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
name: Cypress | ||
|
||
on: | ||
pull_request: | ||
paths: | ||
- '.github/workflows/**' | ||
- 'appinfo/**' | ||
- 'cypress/**' | ||
- 'l10n/**' | ||
- 'lib/**' | ||
- 'src/**' | ||
- 'templates/**' | ||
- '.php-cs-fixer.dist.php' | ||
- 'babel.config.js' | ||
- 'composer.json' | ||
- 'composer.lock' | ||
- 'cypress.json' | ||
- 'package.json' | ||
- 'package-lock.json' | ||
|
||
push: | ||
branches: | ||
- main | ||
- master | ||
- stable* | ||
|
||
permissions: | ||
contents: read | ||
|
||
concurrency: | ||
group: cypress-${{ github.head_ref || github.run_id }} | ||
cancel-in-progress: true | ||
|
||
env: | ||
APP_NAME: monthly_status_email | ||
CYPRESS_baseUrl: http://localhost:8081/index.php | ||
|
||
jobs: | ||
cypress: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: [16] | ||
php-versions: ['8.0'] | ||
databases: ['sqlite'] | ||
server-versions: ['stable25', 'master'] | ||
include: | ||
- php-versions: '7.3' | ||
server-versions: 'stable22' | ||
- php-versions: '7.4' | ||
server-versions: 'stable23' | ||
|
||
steps: | ||
- name: Set app env | ||
run: | | ||
# Split and keep last | ||
echo "APP_NAME=${GITHUB_REPOSITORY##*/}" >> $GITHUB_ENV | ||
- name: Checkout server | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: true | ||
repository: nextcloud/server | ||
ref: ${{ matrix.server-versions }} | ||
|
||
- name: Checkout app | ||
uses: actions/checkout@v3 | ||
with: | ||
path: apps/${{ env.APP_NAME }} | ||
|
||
- name: Set up php ${{ matrix.php-versions }} | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php-versions }} | ||
extensions: mbstring, iconv, fileinfo, intl, sqlite, pdo_sqlite, gd | ||
coverage: none | ||
|
||
- name: Read package.json node and npm engines version | ||
uses: skjnldsv/read-package-engines-version-actions@v2 | ||
id: versions | ||
with: | ||
path: apps/${{ env.APP_NAME }} | ||
fallbackNode: '^16' | ||
fallbackNpm: '^8' | ||
|
||
- 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: Setup NPM cache | ||
uses: actions/setup-node@v3 | ||
with: | ||
cache: 'npm' | ||
cache-dependency-path: apps/${{ env.APP_NAME }}/package-lock.json | ||
# cypress will install dependencies | ||
|
||
- name: Install dependencies & build | ||
working-directory: apps/${{ env.APP_NAME }} | ||
run: | | ||
npm ci | ||
npm run build --if-present | ||
- name: Set up Nextcloud | ||
env: | ||
DB_PORT: 4444 | ||
run: | | ||
mkdir data | ||
./occ maintenance:install --verbose --database=sqlite --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin | ||
./occ app:enable --force ${{ env.APP_NAME }} | ||
- name: Run Nextcloud | ||
run: php -S 0.0.0.0:8081 & | ||
|
||
- name: Run Cypress | ||
uses: cypress-io/github-action@v5 | ||
with: | ||
record: true | ||
wait-on: '${{ env.CYPRESS_baseUrl }}' | ||
working-directory: apps/${{ env.APP_NAME }} | ||
config: video=false,defaultCommandTimeout=20000 | ||
tag: ${{ github.event_name }} | ||
env: | ||
# https://github.com/cypress-io/github-action/issues/124 | ||
COMMIT_INFO_MESSAGE: ${{ github.event.pull_request.title }} | ||
COMMIT_INFO_SHA: ${{ github.event.pull_request.head.sha }} | ||
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }} | ||
CYPRESS_ncVersion: ${{ matrix.server-versions }} | ||
|
||
- name: Upload test failure screenshots | ||
uses: actions/upload-artifact@v3 | ||
if: failure() | ||
with: | ||
name: Upload screenshots | ||
path: apps/${{ env.APP_NAME }}/cypress/screenshots/ | ||
retention-days: 5 | ||
|
||
- name: Upload nextcloud logs | ||
uses: actions/upload-artifact@v3 | ||
if: failure() | ||
with: | ||
name: Upload nextcloud log | ||
path: data/nextcloud.log | ||
retention-days: 5 | ||
|
||
summary: | ||
permissions: | ||
contents: none | ||
runs-on: ubuntu-latest | ||
needs: cypress | ||
|
||
if: always() | ||
|
||
name: cypress-summary | ||
|
||
steps: | ||
- name: Summary status | ||
run: if ${{ needs.cypress.result != 'success' }}; then exit 1; fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const { defineConfig } = require('cypress') | ||
|
||
module.exports = defineConfig({ | ||
projectId: '6m9n96', | ||
|
||
viewportWidth: 1280, | ||
viewportHeight: 900, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
const browserify = require('@cypress/browserify-preprocessor') | ||
on('file:preprocessor', browserify()) | ||
}, | ||
|
||
baseUrl: 'http://localhost:8081/index.php/', | ||
specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}', | ||
}, | ||
retries: { | ||
runMode: 2, | ||
// do not retry in `cypress open` | ||
openMode: 0, | ||
}, | ||
numTestsKeptInMemory: 5, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { randUser } from '../utils/index.js' | ||
const user = randUser() | ||
|
||
describe('Personal settings', function() { | ||
before(function() { | ||
cy.createUser(user) | ||
}) | ||
|
||
beforeEach(function() { | ||
cy.login(user) | ||
}) | ||
|
||
it('Toggle monthly_status_email settings', function() { | ||
if (Cypress.env('ncVersion') === 'stable22') { | ||
cy.visit('/settings/user/activity') | ||
} else { | ||
cy.visit('/settings/user/notifications') | ||
} | ||
cy.get('#monthly-notifications-settings') | ||
.should('contain', 'Monthly Status Email') | ||
cy.get('#monthly-notifications-settings input#send-notifications') | ||
.should('be.checked') | ||
cy.get('#monthly-notifications-settings label[for="send-notifications"]') | ||
.click() | ||
cy.get('#monthly-notifications-settings input#send-notifications') | ||
.should('not.be.checked') | ||
|
||
cy.reload() | ||
|
||
cy.get('#monthly-notifications-settings input#send-notifications') | ||
.should('not.be.checked') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/bin/bash | ||
|
||
export CYPRESS_baseUrl=${CYPRESS_baseUrl:-https://nextcloud.local/index.php} | ||
export APP_SOURCE=$PWD/.. | ||
export LANG="en_EN.UTF-8" | ||
|
||
if ! npm exec wait-on >/dev/null; then | ||
npm install --no-save wait-on | ||
fi | ||
|
||
if npm exec wait-on -- -i 500 -t 1000 "$CYPRESS_baseUrl" 2>/dev/null; then | ||
echo Server is up at "$CYPRESS_baseUrl" | ||
fi | ||
|
||
(cd .. && npm exec cypress -- "$@") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { addCommands } from '@nextcloud/cypress' // eslint-disable-line | ||
|
||
const url = Cypress.config('baseUrl').replace(/\/index.php\/?$/g, '') | ||
Cypress.env('baseUrl', url) | ||
|
||
addCommands() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file is loaded before all e2e tests | ||
|
||
import './commands.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { User } from '@nextcloud/cypress' // eslint-disable-line | ||
|
||
export const randHash = () => Math.random().toString(36).replace(/[^a-z]+/g, '').slice(0, 10) | ||
export const randUser = () => new User(randHash()) |
Oops, something went wrong.