Skip to content

Commit

Permalink
test(cypress): Add simple Cypress test for the dashboard widget
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Nov 7, 2023
1 parent ac9098c commit aa7febf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
49 changes: 49 additions & 0 deletions cypress/e2e/dashboard-widget.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* @copyright Copyright (c) 2023 Jonas <[email protected]>
*
* @author Jonas <[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/>.
*
*/

/**
* 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')
})
})
}
})
14 changes: 14 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down

0 comments on commit aa7febf

Please sign in to comment.