Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress Test - Campaign #1937

Merged
merged 3 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cypress.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2022 Xibo Signage Ltd
* Copyright (C) 2022-2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -32,6 +32,7 @@ module.exports = defineConfig({
client_secret: "Pk6DdDgu2HzSoepcMHRabY60lDEvQ9ucTejYvc5dOgNVSNaOJirCUM83oAzlwe0KBiGR2Nhi6ltclyNC1rmcq0CiJZXzE42KfeatQ4j9npr6nMIQAzMal8O8RiYrIoono306CfyvSSJRfVfKExIjj0ZyE4TUrtPezJbKmvkVDzh8aj3kbanDKatirhwpfqfVdfgsqVNjzIM9ZgKHnbrTX7nNULL3BtxxNGgDMuCuvKiJFrLSyIIz1F4SNrHwHz"
},
e2e: {
experimentalSessionAndOrigin: true,
// We've imported your old cypress plugins here.
// You may want to clean this up later by importing these.
setupNodeEvents(on, config) {
Expand Down
202 changes: 90 additions & 112 deletions cypress/e2e/campaigns.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,24 @@
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
*/

describe('Campaigns', function () {
/* eslint-disable max-len */
describe('Campaigns', function() {
const testRun = Cypress._.random(0, 1e9);

var testRun = "";

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

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

/**
* Create a number of layouts
*/
function createTempLayouts(num) {
for(let index = 1; index <= num; index++) {
var rand = Cypress._.random(0, 1e9);
cy.createLayout(rand).as('testLayoutId' + index);
}
}

/**
* Delete a number of layouts
*/
function deleteTempLayouts(num) {
for(let index = 1; index <= num;index++) {
cy.get('@testLayoutId' + index).then((id) => {
cy.deleteLayout(id);
});
}
}

it('should add an empty campaign', function() {
// Create a list campaign
// Assign layout to it
// and add the id to the session
it('should add a campaign and assign a layout', function() {
cy.intercept('/campaign?draw=4&*').as('campaignGridLoad');
cy.intercept('/layout?*').as('layoutLoad');
cy.intercept('/user/pref').as('userPref');

// Intercept the POST request to get the campaign Id
cy.intercept('/campaign').as('postCampaign');

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

Expand All @@ -65,114 +51,106 @@ describe('Campaigns', function () {
// Wait for the edit form to pop open
cy.contains('.modal .modal-title', testRun);

// Wait for the intercepted POST request to complete and the response to be received
cy.wait('@postCampaign').then((interception) => {
// Access the response body and extract the ID
const id = interception.response.body.id;
// Save the ID to the Cypress.env object
Cypress.env('sessionCampaignId', id);
});

// Switch to the layouts tab.
cy.contains('.modal .nav-tabs .nav-link', 'Layouts').click();
cy.wait('@layoutLoad');
cy.wait('@userPref');

// Should have no layouts assigned
cy.get('.modal #LayoutAssignSortable').children()
.should('have.length', 0);
});

it.skip('should assign layouts to an existing campaign', function() {

// Create some layouts
createTempLayouts(2);

// Create a new campaign and then assign some layouts to it
cy.createCampaign('Cypress Test Campaign ' + testRun).then((res) => {

cy.server();
cy.route('/campaign?draw=3&*').as('campaignGridLoad');

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

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

// Should have no layouts assigned
cy.get('#campaigns tbody tr').should('have.length', 1);
cy.get('#campaigns tbody tr:nth-child(1) td:nth-child(5)').contains('0');

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

// Switch to the layouts tab.
cy.contains('.modal .nav-tabs .nav-link', 'Layouts').click();

// Assign 2 layouts
cy.get('#layoutAssignments tr:nth-child(1) a.assignItem').click();
cy.get('#layoutAssignments tr:nth-child(2) a.assignItem').click();
.should('have.length', 0);
cy.wait('@layoutLoad');
cy.wait('@userPref');

// Search for 2 layouts names 'List Campaign Layout 1' and 'List Campaign Layout 2'
cy.get('.form-inline input[name="layout"]')
.type('List Campaign Layout').trigger('change');
cy.wait('@layoutLoad');
cy.wait('@userPref');

// Assign a layout
cy.get('#layoutAssignments tr:nth-child(1) a.assignItem').click();
cy.wait('@layoutLoad');
cy.wait('@userPref');
cy.get('#layoutAssignments tr:nth-child(2) a.assignItem').click();

// Save
cy.get('.bootbox .save-button').click();

// Wait for 4th campaign grid reload
cy.wait('@campaignGridLoad');

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

// Save
cy.get('.bootbox .save-button').click();
// Should have 2 layouts assigned
cy.get('#campaigns tbody tr').should('have.length', 1);
cy.get('#campaigns tbody tr:nth-child(1) td:nth-child(5)').contains('2');
});

// Wait for 4th campaign grid reload
cy.wait('@campaignGridLoad');
it('should schedule a campaign and should set display status to green', function() {
// At this point we know the campaignId
const displayName = 'List Campaign Display 1';
const sessionCampaignId = Cypress.env('sessionCampaignId');

// Should have 2 layouts assigned
cy.get('#campaigns tbody tr').should('have.length', 1);
cy.get('#campaigns tbody tr:nth-child(1) td:nth-child(5)').contains('2');
// Schedule the campaign
cy.scheduleCampaign(sessionCampaignId, displayName).then((res) => {
cy.displaySetStatus(displayName, 1);

// Delete temp layouts
//deleteTempLayouts(2);
});
});
// Go to display grid
cy.intercept('/display?draw=3&*').as('displayGridLoad');

it('searches and delete existing campaign', function() {

// Create a new campaign and then search for it and delete it
cy.createCampaign('Cypress Test Campaign ' + testRun).then((res) => {
cy.visit('/campaign/view');
cy.visit('/display/view');

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

// Click on the first row element to open the delete modal
cy.get('#campaigns tbody tr').should('have.length', 1);
cy.get('#campaigns tr:first-child .dropdown-toggle').click();
cy.get('#campaigns tr:first-child .campaign_button_delete').click();
cy.get('.FilterDiv input[name="display"]')
.type(displayName);

// Delete test campaign
cy.get('.bootbox .save-button').click();
// Should have the display
cy.get('#displays tbody tr').should('have.length', 1);

// Check if campaign is deleted in toast message
cy.contains('Deleted Cypress Test Campaign ' + testRun);
// Check the display status is green
cy.get('#displays tbody tr:nth-child(1)').should('have.class', 'table-success'); // For class "table-success"
cy.get('#displays tbody tr:nth-child(1)').should('have.class', 'odd'); // For class "odd"
});
});

it('selects multiple campaigns and delete them', function() {

// Create a new campaign and then search for it and delete it
cy.createCampaign('Cypress Test Campaign ' + testRun).then((res) => {

cy.server();
cy.route('/campaign?draw=2&*').as('campaignGridLoad');
it('delete a campaign and check if the display status is pending', function() {
cy.intercept('/campaign?draw=2&*').as('campaignGridLoad');
cy.intercept('DELETE', '/campaign/*', (req) => {
}).as('deleteCampaign');
cy.visit('/campaign/view');

// Delete all test campaigns
cy.visit('/campaign/view');
// Filter for the created campaign
cy.get('#Filter input[name="name"]')
.type('Cypress Test Campaign ' + testRun);

// Clear filter and search for text campaigns
cy.get('#Filter input[name="name"]')
.clear()
.type('Cypress Test Campaign');
// Wait for 2nd campaign grid reload
cy.wait('@campaignGridLoad');

// Wait for 2nd campaign grid reload
cy.wait('@campaignGridLoad');
cy.get('#campaigns tbody tr').should('have.length', 1);

// Select all
cy.get('button[data-toggle="selectAll"]').click();
cy.get('#campaigns tr:first-child .dropdown-toggle').click();
cy.get('#campaigns tr:first-child .campaign_button_delete').click();

// Delete all
cy.get('.dataTables_info button[data-toggle="dropdown"]').click();
cy.get('.dataTables_info a[data-button-id="campaign_button_delete"]').click();
// Delete the campaign
cy.get('.bootbox .save-button').click();

cy.get('button.save-button').click();
// Wait for the intercepted DELETE request to complete with status 200
cy.wait('@deleteCampaign').its('response.statusCode').should('eq', 200);

// Modal should contain one successful delete at least
cy.get('.modal-body').contains(': Success');
// check the display status
cy.displayStatusEquals('List Campaign Display 1', 3).then((res) => {
expect(res.body).to.be.true;
});
});
});
6 changes: 3 additions & 3 deletions cypress/e2e/displaygroups.cy.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Copyright (c) 2022 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -40,7 +40,7 @@ describe('Display Groups', function () {
.type('Cypress Test Displaygroup ' + testRun + '_1');

// Add first by clicking next
cy.get('.modal #dialog_btn_3').click();
cy.get('.modal').contains('Next').click();

// Check if displaygroup is added in toast message
cy.contains('Added Cypress Test Displaygroup ' + testRun + '_1');
Expand Down
7 changes: 5 additions & 2 deletions cypress/e2e/layout_clock.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,19 @@ describe('Layout Designer', function() {

cy.get('[name="themeId"]').select('Dark', {force: true});
cy.get('[name="offset"]').clear().type('1').trigger('change');
cy.wait('@saveWidget');

cy.get('.widget-form .nav-link[href="#advancedTab"]').click();
cy.wait('@saveWidget');

// Type the new name in the input
cy.get('#advancedTab input[name="name"]').clear().type('newName');
cy.wait('@saveWidget');

// Set a duration
cy.get('#advancedTab input[name="useDuration"]').check();
cy.get('#advancedTab input[name="duration"]').clear().type(12).trigger('change');
cy.wait('@saveWidget');
cy.get('#advancedTab input[name="duration"]').clear().type('12').trigger('change');
cy.wait('@saveWidget');

// Change the background of the layout
cy.get('.viewer-element').click({force: true});
Expand Down
57 changes: 56 additions & 1 deletion cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
// -- This is will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
Cypress.Commands.add('login', function(callbackRoute = '/login') {
cy.visit(callbackRoute).then(function() {
cy.session('saveSession', () => {
cy.visit(callbackRoute);
cy.request({
method: 'POST',
url: '/login',
Expand Down Expand Up @@ -419,6 +420,60 @@ Cypress.Commands.add('goToLayoutAndLoadPrefs', function(layoutId) {
cy.wait('@userPrefsLoad');
});

// Schedule a layout
Cypress.Commands.add('scheduleCampaign', function(campaignId, displayName) {
cy.request({
method: 'POST',
url: '/api/scheduleCampaign',
form: true,
headers: {
Authorization: 'Bearer ' + Cypress.env('accessToken'),
},
body: {
campaignId: campaignId,
displayName: displayName,
},
}).then((res) => {
return res.body.eventId;
});
});

// Set Display Status
Cypress.Commands.add('displaySetStatus', function(displayName, statusId) {
cy.request({
method: 'POST',
url: '/api/displaySetStatus',
form: true,
headers: {
Authorization: 'Bearer ' + Cypress.env('accessToken'),
},
body: {
displayName: displayName,
statusId: statusId,
},
}).then((res) => {
return res.body;
});
});

// Check Display Status
Cypress.Commands.add('displayStatusEquals', function(displayName, statusId) {
cy.request({
method: 'GET',
url: '/api/displayStatusEquals',
form: true,
headers: {
Authorization: 'Bearer ' + Cypress.env('accessToken'),
},
body: {
displayName: displayName,
statusId: statusId,
},
}).then((res) => {
return res;
});
});

/**
* Force open toolbar menu
* @param {number} menuIdx
Expand Down
Loading
Loading