From b2d999fd6835e5c59b6086c658330ce7360a780f Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Fri, 10 Nov 2023 21:28:56 +0100 Subject: [PATCH] fix(cypress): Do not install calendar app from app store for testing but use locally provided test app Signed-off-by: Ferdinand Thiessen --- .../e2e/theming/navigation-bar-settings.cy.ts | 46 +++++++-------- cypress/fixtures/testapp/appinfo/info.xml | 31 ++++++++++ cypress/fixtures/testapp/appinfo/routes.php | 11 ++++ cypress/fixtures/testapp/img/app.svg | 56 +++++++++++++++++++ .../testapp/lib/AppInfo/Application.php | 17 ++++++ .../testapp/lib/Controller/PageController.php | 26 +++++++++ cypress/fixtures/testapp/templates/main.php | 6 ++ cypress/support/commonUtils.ts | 22 ++++++++ 8 files changed, 193 insertions(+), 22 deletions(-) create mode 100644 cypress/fixtures/testapp/appinfo/info.xml create mode 100644 cypress/fixtures/testapp/appinfo/routes.php create mode 100644 cypress/fixtures/testapp/img/app.svg create mode 100644 cypress/fixtures/testapp/lib/AppInfo/Application.php create mode 100644 cypress/fixtures/testapp/lib/Controller/PageController.php create mode 100644 cypress/fixtures/testapp/templates/main.php diff --git a/cypress/e2e/theming/navigation-bar-settings.cy.ts b/cypress/e2e/theming/navigation-bar-settings.cy.ts index 26fdd576236..b15b70b0e0f 100644 --- a/cypress/e2e/theming/navigation-bar-settings.cy.ts +++ b/cypress/e2e/theming/navigation-bar-settings.cy.ts @@ -21,6 +21,7 @@ */ import { User } from '@nextcloud/cypress' +import { installTestApp, uninstallTestApp } from '../../support/commonUtils' const admin = new User('admin', 'admin') @@ -152,9 +153,9 @@ describe('User theming set app order with default app', () => { before(() => { cy.resetAdminTheming() // install a third app - cy.runOccCommand('app:install --force --allow-unstable calendar') - // set calendar as default app - cy.runOccCommand('config:system:set --value "calendar,files" defaultapp') + installTestApp() + // set files as default app + cy.runOccCommand('config:system:set --value "files" defaultapp') // Create random user for this test cy.createRandomUser().then(($user) => { @@ -165,55 +166,56 @@ describe('User theming set app order with default app', () => { after(() => { cy.deleteUser(user) - cy.runOccCommand('app:remove calendar') + uninstallTestApp() }) - it('See calendar is the default app', () => { + it('See files is the default app', () => { cy.visit('/') - cy.url().should('match', /apps\/calendar/) + 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', 'calendar') + if (idx === 0) cy.wrap($el).should('have.attr', 'data-app-id', 'files') }) }) - it('See the app order settings: calendar is the first one', () => { + 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', 3).each(($el, idx) => { - if (idx === 0) cy.wrap($el).should('have.attr', 'data-cy-app-order-element', 'calendar') + 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') }) }) it('Can not change the default app', () => { - cy.get('[data-cy-app-order] [data-cy-app-order-element="calendar"] [data-cy-app-order-button="up"]').should('not.be.visible') - cy.get('[data-cy-app-order] [data-cy-app-order-element="calendar"] [data-cy-app-order-button="down"]').should('not.be.visible') + 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="files"] [data-cy-app-order-button="down"]').should('not.be.visible') cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="up"]').should('not.be.visible') cy.get('[data-cy-app-order] [data-cy-app-order-element="dashboard"] [data-cy-app-order-button="down"]').should('be.visible') - cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="up"]').should('be.visible') - cy.get('[data-cy-app-order] [data-cy-app-order-element="files"] [data-cy-app-order-button="down"]').should('not.be.visible') + cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').should('be.visible') + cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="down"]').should('not.be.visible') }) it('Change the order of the other apps', () => { - 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="testapp"] [data-cy-app-order-button="up"]').click() + cy.get('[data-cy-app-order] [data-cy-app-order-element="testapp"] [data-cy-app-order-button="up"]').click() + 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', 'calendar') - else if (idx === 1) 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') + 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') }) }) 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', 'calendar') - else if (idx === 1) cy.wrap($el).should('have.attr', 'data-app-id', 'files') - else cy.wrap($el).should('have.attr', 'data-app-id', 'dashboard') + 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') }) }) }) diff --git a/cypress/fixtures/testapp/appinfo/info.xml b/cypress/fixtures/testapp/appinfo/info.xml new file mode 100644 index 00000000000..2e4eecfbdca --- /dev/null +++ b/cypress/fixtures/testapp/appinfo/info.xml @@ -0,0 +1,31 @@ + + + + testapp + Test App + Test App + + 0.0.1 + agpl + Ferdinand Thiessen + TestApp + games + https://github.com/nextcloud/server/issues + + + + + + Test App + testapp.page.index + + + Test App 2 + testapp.page.index + + + diff --git a/cypress/fixtures/testapp/appinfo/routes.php b/cypress/fixtures/testapp/appinfo/routes.php new file mode 100644 index 00000000000..cd54acdc083 --- /dev/null +++ b/cypress/fixtures/testapp/appinfo/routes.php @@ -0,0 +1,11 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +return [ + 'routes' => [ + ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], + ] +]; diff --git a/cypress/fixtures/testapp/img/app.svg b/cypress/fixtures/testapp/img/app.svg new file mode 100644 index 00000000000..fe370f80daf --- /dev/null +++ b/cypress/fixtures/testapp/img/app.svg @@ -0,0 +1,56 @@ + + + + + + image/svg+xml + + + + + + + + diff --git a/cypress/fixtures/testapp/lib/AppInfo/Application.php b/cypress/fixtures/testapp/lib/AppInfo/Application.php new file mode 100644 index 00000000000..7647889f784 --- /dev/null +++ b/cypress/fixtures/testapp/lib/AppInfo/Application.php @@ -0,0 +1,17 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +namespace OCA\TestApp\AppInfo; + +use OCP\AppFramework\App; + +class Application extends App { + public const APP_ID = 'testapp'; + + public function __construct() { + parent::__construct(self::APP_ID); + } +} diff --git a/cypress/fixtures/testapp/lib/Controller/PageController.php b/cypress/fixtures/testapp/lib/Controller/PageController.php new file mode 100644 index 00000000000..2a9dec885a7 --- /dev/null +++ b/cypress/fixtures/testapp/lib/Controller/PageController.php @@ -0,0 +1,26 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later + +namespace OCA\TestApp\Controller; + +use OCA\TestApp\AppInfo\Application; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\IRequest; + +class PageController extends Controller { + public function __construct(IRequest $request) { + parent::__construct(Application::APP_ID, $request); + } + + /** + * @NoAdminRequired + * @NoCSRFRequired + */ + public function index(): TemplateResponse { + return new TemplateResponse(Application::APP_ID, 'main'); + } +} diff --git a/cypress/fixtures/testapp/templates/main.php b/cypress/fixtures/testapp/templates/main.php new file mode 100644 index 00000000000..abe4bf041de --- /dev/null +++ b/cypress/fixtures/testapp/templates/main.php @@ -0,0 +1,6 @@ + +// SPDX-License-Identifier: AGPL-3.0-or-later +?> +
diff --git a/cypress/support/commonUtils.ts b/cypress/support/commonUtils.ts index 5f0feae4824..580e9b23428 100644 --- a/cypress/support/commonUtils.ts +++ b/cypress/support/commonUtils.ts @@ -35,3 +35,25 @@ export function clearState() { users.forEach((userID) => cy.runOccCommand(`user:delete '${userID}'`)) }) } + +/** + * Install the test app + */ +export function installTestApp() { + const testAppPath = 'cypress/fixtures/testapp' + cy.runOccCommand('-V').then((output) => { + const version = output.stdout.match(/(\d\d+)\.\d+\.\d+/)?.[1] + 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 's|version="[0-9]+|version="${version}|' apps/testapp/appinfo/info.xml`) + cy.runOccCommand('app:enable testapp') + }) +} + +/** + * Remove the test app + */ +export function uninstallTestApp() { + cy.runOccCommand('app:remove testapp', { failOnNonZeroExit: false }) + cy.exec('docker exec nextcloud-cypress-tests-server rm -fr apps/testapp/appinfo/info.xml') +}