From aa7febfe72572f02163d52e20d945d1f8ad848d1 Mon Sep 17 00:00:00 2001 From: Jonas Date: Tue, 7 Nov 2023 16:28:37 +0100 Subject: [PATCH] test(cypress): Add simple Cypress test for the dashboard widget Signed-off-by: Jonas --- cypress/e2e/dashboard-widget.spec.js | 49 ++++++++++++++++++++++++++++ cypress/support/commands.js | 14 ++++++++ 2 files changed, 63 insertions(+) create mode 100644 cypress/e2e/dashboard-widget.spec.js diff --git a/cypress/e2e/dashboard-widget.spec.js b/cypress/e2e/dashboard-widget.spec.js new file mode 100644 index 000000000..c9535e531 --- /dev/null +++ b/cypress/e2e/dashboard-widget.spec.js @@ -0,0 +1,49 @@ +/** + * @copyright Copyright (c) 2023 Jonas + * + * @author Jonas + * + * @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 . + * + */ + +/** + * Tests for Collectives dashboard widget. + */ + +describe('Collectives dashboard widget', function() { + if (Cypress.env('ncVersion') !== 'stable25') { + describe('Open dashboard widget', function() { + before(function() { + cy.loginAs('bob') + cy.enableDashboardWidget('collectives-recent-pages') + cy.visit('apps/collectives') + cy.deleteAndSeedCollective('Dashboard Collective1') + cy.seedPage('Page 1', '', 'Readme.md') + }) + it('Lists pages in the dashboard widget', function() { + cy.visit('/apps/dashboard/') + cy.get('.panel--header') + .contains('Recent pages') + cy.get('.panel--content').as('panelContent') + cy.get('@panelContent') + .find('li').should('contain', 'Landing page') + cy.get('@panelContent') + .find('li').should('contain', 'Page 1') + }) + }) + } +}) diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 79975e4ae..1e82e3791 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -99,6 +99,20 @@ Cypress.Commands.add('setAppEnabled', (appName, value = true) => { }) }) +/** + * Enable dashboard widget + */ +Cypress.Commands.add('enableDashboardWidget', (widgetName) => { + cy.request('/csrftoken').then(({ body }) => { + const requesttoken = body.token + const api = `${Cypress.env('baseUrl')}/index.php/apps/dashboard/layout` + return axios.post(api, + { layout: widgetName }, + { headers: { requesttoken } }, + ) + }) +}) + /** * First delete, then seed a collective (to start fresh) */