From e2f16ac3175df5fca0431718777fcc95537c224c Mon Sep 17 00:00:00 2001 From: Bogdan Preda Date: Wed, 20 Mar 2024 19:50:46 +0200 Subject: [PATCH 1/3] fix: e2e tests in pro version Codeinwp/visualizer-pro#418 --- classes/Visualizer/Render/Layout.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/classes/Visualizer/Render/Layout.php b/classes/Visualizer/Render/Layout.php index 1d23261f..5d00ca66 100644 --- a/classes/Visualizer/Render/Layout.php +++ b/classes/Visualizer/Render/Layout.php @@ -872,7 +872,11 @@ class="dashicons dashicons-lock"> - + From 088980241bc1606d4fec691f8f5291bb9b41ae3f Mon Sep 17 00:00:00 2001 From: Bogdan Preda Date: Thu, 21 Mar 2024 12:56:03 +0200 Subject: [PATCH 2/3] chore: add e2e test for upsell --- classes/Visualizer/Render/Layout.php | 1 - cypress/integration/default/free-upsell.js | 134 +++++++++++++++++++++ 2 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/default/free-upsell.js diff --git a/classes/Visualizer/Render/Layout.php b/classes/Visualizer/Render/Layout.php index 5d00ca66..32f14b59 100644 --- a/classes/Visualizer/Render/Layout.php +++ b/classes/Visualizer/Render/Layout.php @@ -925,7 +925,6 @@ class="dashicons dashicons-lock"> - diff --git a/cypress/integration/default/free-upsell.js b/cypress/integration/default/free-upsell.js new file mode 100644 index 00000000..56f434f5 --- /dev/null +++ b/cypress/integration/default/free-upsell.js @@ -0,0 +1,134 @@ +describe('Test Free - upsells', function() { + before(function () { + + // login to WP + cy.visit('wp-login.php'); + cy.get('#user_login').clear().type(Cypress.env('login')); + cy.get('#user_pass').clear().type(Cypress.env('pass')); + cy.get('#wp-submit').click(); + }); + + it('Check upsell links', function() { + cy.visit(Cypress.env('urls').library ); + cy.get('.visualizer-chart > .visualizer-chart-canvas > .visualizer-notfound > h2 > .add-new-h2').click() + cy.wait( Cypress.env('wait') ); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + cy.wrap($body).find('#toolbar input[type="submit"]').click(); + cy.wait( Cypress.env('wait') ); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check Import form other chart upsell. + const other_import = cy.wrap($body).find('.viz-import-from-other'); + other_import.click(); + other_import.should('have.class', 'only-pro-feature'); + const other_import_upsell_url = cy.wrap($body).find('.viz-import-from-other .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const other_import_search_params = new URLSearchParams(href); + expect(other_import_search_params.get('utm_campaign')).to.equal('import-chart'); + }); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check import form WordPress upsell. + const wp_import = cy.wrap($body).find('.visualizer_source_query_wp'); + wp_import.click(); + wp_import.should('have.class', 'only-pro-feature'); + const wp_import_upsell_url = cy.wrap($body).find('.visualizer_source_query_wp .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const wp_import_search_params = new URLSearchParams(href); + expect(wp_import_search_params.get('utm_campaign')).to.equal('import-wp'); + }); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check import form database upsell. + const db_import = cy.wrap($body).find('.visualizer_source_query'); + db_import.click(); + db_import.should('have.class', 'only-pro-feature'); + const db_import_upsell_url = cy.wrap($body).find('.visualizer_source_query .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const db_import_search_params = new URLSearchParams(href); + expect(db_import_search_params.get('utm_campaign')).to.equal('db-query'); + }); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check import form manual data upsell. + const manual_import = cy.wrap($body).find('.visualizer_source_manual'); + manual_import.click(); + manual_import.should('have.class', 'only-pro-feature'); + const manual_import_upsell_url = cy.wrap($body).find('.visualizer_source_manual .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const manual_import_search_params = new URLSearchParams(href); + expect(manual_import_search_params.get('utm_campaign')).to.equal('manual-data'); + }); + }); + }); + + it('Check Settings upsell links', function() { + cy.visit(Cypress.env('urls').library ); + cy.get('.visualizer-chart > .visualizer-chart-canvas > .visualizer-notfound > h2 > .add-new-h2').click() + cy.wait( Cypress.env('wait') ); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + cy.wrap($body).find('#toolbar input[type="submit"]').click(); + cy.wait( Cypress.env('wait') ); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + cy.wrap($body).find('#viz-tab-advanced').click(); + cy.wait( Cypress.env('wait') ); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check setting chart data filter configuration upsell. + const data_control = cy.wrap($body).find('#vz-data-controls'); + data_control.click(); + data_control.should('have.class', 'only-pro-feature'); + const data_control_upsell_url = cy.wrap($body).find('#vz-data-controls .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const data_control_search_params = new URLSearchParams(href); + expect(data_control_search_params.get('utm_campaign')).to.equal('data-filter-configuration'); + }); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check setting frontend actions upsell. + const frontend_actions = cy.wrap($body).find('#vz-frontend-actions'); + frontend_actions.click(); + frontend_actions.should('have.class', 'only-pro-feature'); + const frontend_actions_upsell_url = cy.wrap($body).find('#vz-frontend-actions .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const frontend_actions_search_params = new URLSearchParams(href); + expect(frontend_actions_search_params.get('utm_campaign')).to.equal('frontend-actions'); + }); + }); + + cy.get('iframe') + .then(function ($iframe) { + const $body = $iframe.contents().find('body'); + // Check setting permissions upsell. + const permissions = cy.wrap($body).find('#vz-permissions'); + permissions.click(); + permissions.should('have.class', 'only-pro-feature'); + const permissions_upsell_url = cy.wrap($body).find('#vz-permissions .viz-group-content .only-pro-content .only-pro-container .only-pro-inner a').should('have.attr', 'href').then((href) => { + const permissions_search_params = new URLSearchParams(href); + expect(permissions_search_params.get('utm_campaign')).to.equal('chart-permissions'); + }); + }); + }); +}); From 315255682866218a208d6808afd197e821dee93f Mon Sep 17 00:00:00 2001 From: Bogdan Preda Date: Thu, 21 Mar 2024 14:05:22 +0200 Subject: [PATCH 3/3] chore: improve test and ensure is not dependent --- cypress/integration/default/free-upsell.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/cypress/integration/default/free-upsell.js b/cypress/integration/default/free-upsell.js index 56f434f5..e77e65fb 100644 --- a/cypress/integration/default/free-upsell.js +++ b/cypress/integration/default/free-upsell.js @@ -8,11 +8,13 @@ describe('Test Free - upsells', function() { cy.get('#wp-submit').click(); }); - it('Check upsell links', function() { + beforeEach(() => { cy.visit(Cypress.env('urls').library ); - cy.get('.visualizer-chart > .visualizer-chart-canvas > .visualizer-notfound > h2 > .add-new-h2').click() + cy.get('.add-new-h2.add-new-chart').first().click(); cy.wait( Cypress.env('wait') ); + }); + it('Check upsell links', function() { cy.get('iframe') .then(function ($iframe) { const $body = $iframe.contents().find('body'); @@ -74,10 +76,6 @@ describe('Test Free - upsells', function() { }); it('Check Settings upsell links', function() { - cy.visit(Cypress.env('urls').library ); - cy.get('.visualizer-chart > .visualizer-chart-canvas > .visualizer-notfound > h2 > .add-new-h2').click() - cy.wait( Cypress.env('wait') ); - cy.get('iframe') .then(function ($iframe) { const $body = $iframe.contents().find('body');