Skip to content

Commit

Permalink
Cypress - add/edit (xibosignage#2122)
Browse files Browse the repository at this point in the history
  • Loading branch information
ifarzana authored Oct 12, 2023
1 parent 6cd3193 commit 32a2842
Show file tree
Hide file tree
Showing 22 changed files with 2,582 additions and 104 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ jobs:
run: |
docker exec --user www-data -t cms-web /bin/bash -c "cd /var/www/cms; php vendor/bin/phpunit --log-junit results.xml"
- name: Run Cypress
continue-on-error: true
run: |
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO oauth_clients (id, secret, name, userId, authCode, clientCredentials) VALUES ('MrGPc7e3IL1hA6w13l7Ru5giygxmNiafGNhFv89d', 'Pk6DdDgu2HzSoepcMHRabY60lDEvQ9ucTejYvc5dOgNVSNaOJirCUM83oAzlwe0KBiGR2Nhi6ltclyNC1rmcq0CiJZXzE42KfeatQ4j9npr6nMIQAzMal8O8RiYrIoono306CfyvSSJRfVfKExIjj0ZyE4TUrtPezJbKmvkVDzh8aj3kbanDKatirhwpfqfVdfgsqVNjzIM9ZgKHnbrTX7nNULL3BtxxNGgDMuCuvKiJFrLSyIIz1F4SNrHwHz', 'cypress', 1, 0, 1)"
docker exec cms-db mysql -ucms -pjenkins cms -e "INSERT INTO oauth_client_scopes (clientId, scopeId) VALUES ('MrGPc7e3IL1hA6w13l7Ru5giygxmNiafGNhFv89d', 'all') ON DUPLICATE KEY UPDATE scopeId = scopeId"
docker run --ipc=host --name cms-cypress --link=cms-web:web -v $(pwd)/cypress.config.js:/app/cypress.config.js -v $(pwd)/cypress:/app/cypress ghcr.io/xibosignage/xibo-cms:cypress bash -c "CYPRESS_baseUrl=http://web /app/node_modules/.bin/cypress run --config screenshotsFolder=/app/cypress/results,video=false --reporter junit --reporter-options 'mochaFile=/app/cypress/results/results_cypress_[hash].xml,toConsole=true'; chown -R 1001:1001 /app/cypress/results"
- name: Save Cypress test results as an artifact
if: failure()
uses: actions/upload-artifact@v3
with:
name: cypress-test-results
path: cypress/results
run: exit 1
path: cypress/results
196 changes: 196 additions & 0 deletions cypress/e2e/Display/datasets.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
* Xibo 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
* any later version.
*
* Xibo 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 Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable max-len */
describe('Datasets', function() {
let testRun = '';

beforeEach(function() {
cy.login();

testRun = Cypress._.random(0, 1e9);
});

it('should add one empty dataset', function() {
cy.visit('/dataset/view');

// Click on the Add Dataset button
cy.contains('Add DataSet').click();

cy.get('.modal input#dataSet')
.type('Cypress Test Dataset ' + testRun + '_1');

// Add first by clicking next
cy.get('.modal .save-button').click();

// Check if dataset is added in toast message
cy.contains('Added Cypress Test Dataset ' + testRun + '_1');
});

it('searches and edit existing dataset', function() {
// Create a new dataset and then search for it and delete it
cy.createDataset('Cypress Test Dataset ' + testRun).then((id) => {
cy.intercept({
url: '/dataset?*',
query: {dataSet: 'Cypress Test Dataset ' + testRun},
}).as('loadGridAfterSearch');

// Intercept the PUT request
cy.intercept({
method: 'PUT',
url: '/dataset/*',
}).as('putRequest');

cy.visit('/dataset/view');

// Filter for the created dataset
cy.get('#Filter input[name="dataSet"]')
.type('Cypress Test Dataset ' + testRun);

// Wait for the grid reload
cy.wait('@loadGridAfterSearch');

// Click on the first row element to open the delete modal
cy.get('#datasets tr:first-child .dropdown-toggle').click();
cy.get('#datasets tr:first-child .dataset_button_edit').click();

cy.get('.modal input#dataSet').clear()
.type('Cypress Test Dataset Edited ' + testRun);

// edit test dataset
cy.get('.bootbox .save-button').click();

// Wait for the intercepted PUT request and check the form data
cy.wait('@putRequest').then((interception) => {
// Get the request body (form data)
const response = interception.response;
const responseData = response.body.data;

// assertion on the "dataset" value
expect(responseData.dataSet).to.eq('Cypress Test Dataset Edited ' + testRun);
});

// Delete the dataset and assert success
cy.deleteDataset(id).then((res) => {
expect(res.status).to.equal(204);
});
});
});

it.only('copy an existing dataset', function() {
// Create a new dataset and then search for it and delete it
cy.createDataset('Cypress Test Dataset ' + testRun).then((res) => {
cy.intercept({
url: '/dataset?*',
query: {dataSet: 'Cypress Test Dataset ' + testRun},
}).as('loadGridAfterSearch');

// Intercept the POST request
cy.intercept({
method: 'POST',
url: /\/dataset\/copy\/\d+/,
}).as('postRequest');

cy.visit('/dataset/view');

// Filter for the created dataset
cy.get('#Filter input[name="dataSet"]')
.type('Cypress Test Dataset ' + testRun);

// Wait for the grid reload
cy.wait('@loadGridAfterSearch');

// Click on the first row element to open the delete modal
cy.get('#datasets tr:first-child .dropdown-toggle').click();
cy.get('#datasets tr:first-child .dataset_button_copy').click();

// Delete test dataset
cy.get('.bootbox .save-button').click();

// Wait for the intercepted POST request and check the form data
cy.wait('@postRequest').then((interception) => {
// Get the request body (form data)
const response = interception.response;
const responseData = response.body.data;
expect(responseData.dataSet).to.include('Cypress Test Dataset ' + testRun + ' 2');
});
});
});

it('searches and delete existing dataset', function() {
// Create a new dataset and then search for it and delete it
cy.createDataset('Cypress Test Dataset ' + testRun).then((res) => {
cy.server();
cy.route('/dataset?draw=2&*').as('datasetGridLoad');

cy.visit('/dataset/view');

// Filter for the created dataset
cy.get('#Filter input[name="dataSet"]')
.type('Cypress Test Dataset ' + testRun);

// Wait for the grid reload
cy.wait('@datasetGridLoad');

// Click on the first row element to open the delete modal
cy.get('#datasets tr:first-child .dropdown-toggle').click();
cy.get('#datasets tr:first-child .dataset_button_delete').click();

// Delete test dataset
cy.get('.bootbox .save-button').click();

// Check if dataset is deleted in toast message
cy.get('.toast').contains('Deleted Cypress Test Dataset');
});
});

it('selects multiple datasets and delete them', function() {
// Create a new dataset and then search for it and delete it
cy.createDataset('Cypress Test Dataset ' + testRun).then((res) => {
cy.server();
cy.route('/dataset?draw=2&*').as('datasetGridLoad');

// Delete all test datasets
cy.visit('/dataset/view');

// Clear filter
cy.get('#Filter input[name="dataSet"]')
.clear()
.type('Cypress Test Dataset');

// Wait for the grid reload
cy.wait('@datasetGridLoad');

// Select all
cy.get('button[data-toggle="selectAll"]').click();

// Delete all
cy.get('.dataTables_info button[data-toggle="dropdown"]').click();
cy.get('.dataTables_info a[data-button-id="dataset_button_delete"]').click();

cy.get('input#deleteData').check();
cy.get('button.save-button').click();

// Modal should contain one successful delete at least
cy.get('.modal-body').contains(': Success');
});
});
});
114 changes: 114 additions & 0 deletions cypress/e2e/Display/dayparts.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
* Xibo 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
* any later version.
*
* Xibo 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 Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

/* eslint-disable max-len */
describe('Dayparts', function() {
let testRun = '';

beforeEach(function() {
cy.login();

testRun = Cypress._.random(0, 1e9);
});

it('should add a daypart', function() {
cy.visit('/daypart/view');

// Click on the Add Daypart button
cy.contains('Add Daypart').click();

cy.get('.modal input#name')
.type('Cypress Test Daypart ' + testRun + '_1');
cy.get(':nth-child(3) > .col-sm-10 > .input-group > .datePickerHelper').click();
// cy.get('.open > .flatpickr-time > :nth-child(1) > .arrowUp').click();
cy.get('.open > .flatpickr-time > :nth-child(1) > .numInput').type('8');
cy.get(':nth-child(4) > .col-sm-10 > .input-group > .datePickerHelper').click();
cy.get('.open > .flatpickr-time > :nth-child(1) > .numInput').type('17');

// Add first by clicking next
cy.get('.modal .save-button').click();

// Check if daypart is added in toast message
cy.contains('Added Cypress Test Daypart ' + testRun + '_1');
});

// TODO filter needed
it.skip('searches and delete existing daypart', function() {
// Create a new daypart and then search for it and delete it
cy.createDayPart('Cypress Test Daypart ' + testRun).then((res) => {
cy.server();
cy.route('/daypart?draw=2&*').as('daypartGridLoad');

cy.visit('/daypart/view');

// Filter for the created daypart
cy.get('#Filter input[name="name"]')
.type('Cypress Test Daypart ' + testRun);

// Wait for the grid reload
cy.wait('@daypartGridLoad');

// Click on the first row element to open the delete modal
cy.get('#dayparts tr:first-child .dropdown-toggle').click();
cy.get('#dayparts tr:first-child .daypart_button_delete').click();

// Delete test daypart
cy.get('.bootbox .save-button').click();

// Check if daypart is deleted in toast message
cy.get('.toast').contains('Deleted Cypress Test Daypart');
});
});

it.skip('selects multiple dayparts and delete them', function() {
// Create a new daypart and then search for it and delete it
cy.createDayPart('Cypress Test Daypart ' + testRun).then((res) => {
cy.intercept({
url: '/daypart?*',
query: {name: 'Cypress Test Daypart ' + testRun},
}).as('loadGridAfterSearch');

// Delete all test dayparts
cy.visit('/daypart/view');

// Clear filter
cy.get('#Filter input[name="name"]')
.clear()
.type('Cypress Test Daypart');

// Wait for the grid reload
cy.wait('@loadGridAfterSearch');

// Select all
cy.get('button[data-toggle="selectAll"]').click();

// Delete all
cy.get('.dataTables_info button[data-toggle="dropdown"]').click();
cy.get('.dataTables_info a[data-button-id="daypart_button_delete"]').click();

cy.get('input#deleteData').check();
cy.get('button.save-button').click();

// Modal should contain one successful delete at least
cy.get('.modal-body').contains(': Success');
});
});
});
Loading

0 comments on commit 32a2842

Please sign in to comment.