From 2e20fdb3f000cd2d9d2fe2a63f4fb181c2092eed Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 17 May 2024 14:55:59 +0300 Subject: [PATCH 01/10] chore: replaced favicons with dashicons --- js/library.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/js/library.js b/js/library.js index 4718d915..df7233eb 100644 --- a/js/library.js +++ b/js/library.js @@ -35,11 +35,6 @@ function createPopupProBlocker() { - var link = document.createElement('link'); - link.rel = 'stylesheet'; - link.href = 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css'; - document.head.appendChild(link); - var overlay = document.createElement('div'); overlay.classList.add('vizualizer-renew-notice-overlay'); overlay.id = 'overlay-visualizer'; @@ -49,7 +44,7 @@ function createPopupProBlocker() { popup.classList.add('vizualizer-renew-notice-popup'); var closeIcon = document.createElement('i'); - closeIcon.classList.add('fas', 'fa-times', 'vizualizer-renew-notice-close-icon'); + closeIcon.classList.add('dashicons', 'dashicons-no', 'vizualizer-renew-notice-close-icon'); closeIcon.addEventListener('click', function() { document.body.removeChild(overlay); popup.style.display = 'none'; @@ -73,7 +68,7 @@ function createPopupProBlocker() { link1.href = 'https://store.themeisle.com/'; link1.target = '_blank'; var button1 = document.createElement('button'); - button1.innerHTML = ' Renew License'; + button1.innerHTML = ' Renew License'; button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button'); link1.appendChild(button1); buttonsContainer.appendChild(link1); @@ -81,7 +76,7 @@ function createPopupProBlocker() { var link2 = document.createElement('a'); link2.href = '/wp-admin/options-general.php#visualizer_pro_license'; var button2 = document.createElement('button'); - button2.innerHTML = ' Activate License'; + button2.innerHTML = ' Activate License'; button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button'); link2.appendChild(button2); buttonsContainer.appendChild(link2); From 1ea938f7b03f27a9baab6b9cc20978d14f35b6bd Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 17 May 2024 15:15:41 +0300 Subject: [PATCH 02/10] chore: added renew notice dom cleanup on close --- js/library.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/js/library.js b/js/library.js index df7233eb..263d18b2 100644 --- a/js/library.js +++ b/js/library.js @@ -43,14 +43,6 @@ function createPopupProBlocker() { var popup = document.createElement('div'); popup.classList.add('vizualizer-renew-notice-popup'); - var closeIcon = document.createElement('i'); - closeIcon.classList.add('dashicons', 'dashicons-no', 'vizualizer-renew-notice-close-icon'); - closeIcon.addEventListener('click', function() { - document.body.removeChild(overlay); - popup.style.display = 'none'; - }); - popup.appendChild(closeIcon); - var heading = document.createElement('h1'); heading.textContent = 'Alert!'; heading.classList.add('vizualizer-renew-notice-heading'); @@ -83,6 +75,17 @@ function createPopupProBlocker() { popup.appendChild(buttonsContainer); + var closeIcon = document.createElement('i'); + + closeIcon.classList.add('dashicons', 'dashicons-no', 'vizualizer-renew-notice-close-icon'); + + closeIcon.addEventListener('click', function() { + document.body.removeChild(overlay); + document.body.removeChild(popup); + }); + + popup.appendChild(closeIcon); + document.body.appendChild(popup); } From 874cf97b0d739d7485efd402d8aeb9769048c68b Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Fri, 17 May 2024 19:13:34 +0300 Subject: [PATCH 03/10] chore: added proper links for license renew on lock notice --- classes/Visualizer/Module/Admin.php | 9 +++++++++ classes/Visualizer/Plugin.php | 2 ++ js/library.js | 4 ++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index 281bcca3..d6e9a55d 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -1019,6 +1019,13 @@ public function renderLibraryPage() { } // enqueue charts array $ajaxurl = admin_url( 'admin-ajax.php' ); + $license = get_option( 'visualizer_pro_license_data', 'free' ); + $license_key = ''; + $download_id = ''; + if ( ! empty( $license ) && is_object( $license ) ) { + $license_key = $license->key; + $download_id = $license->download_id; + } wp_localize_script( 'visualizer-library', 'visualizer', @@ -1058,6 +1065,8 @@ public function renderLibraryPage() { 'conflict' => __( 'We have detected a potential conflict with another component that prevents Visualizer from functioning properly. Please disable any of the following components if they are activated on your instance: Modern Events Calendar plugin, Acronix plugin. In case the aforementioned components are not activated or you continue to see this error message, please disable all other plugins and enable them one by one to find out the component that is causing the conflict.', 'visualizer' ), ), 'is_pro_user' => Visualizer_Module::is_pro(), + 'admin_license_url' => admin_url('options-general.php#visualizer_pro_license'), + 'renew_license_url' => tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' ), ) ); // render library page diff --git a/classes/Visualizer/Plugin.php b/classes/Visualizer/Plugin.php index 49517b51..3f20628a 100644 --- a/classes/Visualizer/Plugin.php +++ b/classes/Visualizer/Plugin.php @@ -57,6 +57,8 @@ class Visualizer_Plugin { const ACTION_UPLOAD_DATA = 'visualizer-upload-data'; const ACTION_EXPORT_DATA = 'visualizer-export-data'; + const STORE_URL = 'https://store.themeisle.com/'; + /** *Action used for fetching specific users/roles for permissions. */ diff --git a/js/library.js b/js/library.js index 263d18b2..7184c45c 100644 --- a/js/library.js +++ b/js/library.js @@ -57,7 +57,7 @@ function createPopupProBlocker() { buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container'); var link1 = document.createElement('a'); - link1.href = 'https://store.themeisle.com/'; + link1.href = visualizer.renew_license_url; link1.target = '_blank'; var button1 = document.createElement('button'); button1.innerHTML = ' Renew License'; @@ -66,7 +66,7 @@ function createPopupProBlocker() { buttonsContainer.appendChild(link1); var link2 = document.createElement('a'); - link2.href = '/wp-admin/options-general.php#visualizer_pro_license'; + link2.href = visualizer.admin_license_url; var button2 = document.createElement('button'); button2.innerHTML = ' Activate License'; button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button'); From 7c53f0021aa3d88e097fd34320c1f81bbc4c3410 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Mon, 20 May 2024 13:23:31 +0300 Subject: [PATCH 04/10] chore: optimized feature lock notice rendering --- classes/Visualizer/Module/Admin.php | 10 +--- classes/Visualizer/Render/Library.php | 58 ++++++++++++++++++++ css/library.css | 3 +- js/library.js | 77 +++++---------------------- 4 files changed, 73 insertions(+), 75 deletions(-) diff --git a/classes/Visualizer/Module/Admin.php b/classes/Visualizer/Module/Admin.php index d6e9a55d..c5067585 100644 --- a/classes/Visualizer/Module/Admin.php +++ b/classes/Visualizer/Module/Admin.php @@ -1019,13 +1019,7 @@ public function renderLibraryPage() { } // enqueue charts array $ajaxurl = admin_url( 'admin-ajax.php' ); - $license = get_option( 'visualizer_pro_license_data', 'free' ); - $license_key = ''; - $download_id = ''; - if ( ! empty( $license ) && is_object( $license ) ) { - $license_key = $license->key; - $download_id = $license->download_id; - } + wp_localize_script( 'visualizer-library', 'visualizer', @@ -1065,8 +1059,6 @@ public function renderLibraryPage() { 'conflict' => __( 'We have detected a potential conflict with another component that prevents Visualizer from functioning properly. Please disable any of the following components if they are activated on your instance: Modern Events Calendar plugin, Acronix plugin. In case the aforementioned components are not activated or you continue to see this error message, please disable all other plugins and enable them one by one to find out the component that is causing the conflict.', 'visualizer' ), ), 'is_pro_user' => Visualizer_Module::is_pro(), - 'admin_license_url' => admin_url('options-general.php#visualizer_pro_license'), - 'renew_license_url' => tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' ), ) ); // render library page diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 6263ef64..09210caa 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -215,10 +215,48 @@ private function getDisplayForm() { * @access private */ private function _renderLibrary() { + $license = get_option( 'visualizer_pro_license_data', 'free' ); + $license_key = ''; + $download_id = ''; + if ( ! empty( $license ) && is_object( $license ) ) { + $license_key = $license->key; + $download_id = $license->download_id; + } + $admin_license_url = admin_url('options-general.php#visualizer_pro_license'); + $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' ); // Added by Ash/Upwork $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Added by Ash/Upwork echo $this->custom_css; + if ( ! Visualizer_Module::is_pro() ) { + echo ' +
+
+

Alert!

+

' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . '

+ + +
+ '; + } echo '
'; echo ''; $this->getDisplayForm(); @@ -251,6 +289,26 @@ private function _renderLibrary() { $this->_renderSidebar(); } echo '
'; + +// echo ' +// +//

Alert!

+//

+// In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it. +//

+// +// '; } else { echo '
'; echo '
'; diff --git a/css/library.css b/css/library.css index 5fdd3c07..621cef62 100644 --- a/css/library.css +++ b/css/library.css @@ -522,6 +522,7 @@ div#visualizer-types ul, div#visualizer-types form p { .vizualizer-renew-notice-overlay { + display: none; position: fixed; top: 0; left: 0; @@ -532,7 +533,7 @@ div#visualizer-types ul, div#visualizer-types form p { } .vizualizer-renew-notice-popup { - display: block; + display: none; position: fixed; top: 50%; left: 50%; diff --git a/js/library.js b/js/library.js index 7184c45c..55869c47 100644 --- a/js/library.js +++ b/js/library.js @@ -33,61 +33,13 @@ }); })(wp.media.view); -function createPopupProBlocker() { - - var overlay = document.createElement('div'); - overlay.classList.add('vizualizer-renew-notice-overlay'); - overlay.id = 'overlay-visualizer'; - document.body.appendChild(overlay); - - var popup = document.createElement('div'); - popup.classList.add('vizualizer-renew-notice-popup'); - - var heading = document.createElement('h1'); - heading.textContent = 'Alert!'; - heading.classList.add('vizualizer-renew-notice-heading'); - popup.appendChild(heading); - - var message = document.createElement('p'); - message.textContent = 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.'; - message.classList.add('vizualizer-renew-notice-message'); - popup.appendChild(message); - - var buttonsContainer = document.createElement('div'); - buttonsContainer.classList.add('vizualizer-renew-notice-buttons-container'); - - var link1 = document.createElement('a'); - link1.href = visualizer.renew_license_url; - link1.target = '_blank'; - var button1 = document.createElement('button'); - button1.innerHTML = ' Renew License'; - button1.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-renew-button'); - link1.appendChild(button1); - buttonsContainer.appendChild(link1); - - var link2 = document.createElement('a'); - link2.href = visualizer.admin_license_url; - var button2 = document.createElement('button'); - button2.innerHTML = ' Activate License'; - button2.classList.add('vizualizer-renew-notice-button', 'vizualizer-renew-notice-activate-button'); - link2.appendChild(button2); - buttonsContainer.appendChild(link2); - - popup.appendChild(buttonsContainer); - - var closeIcon = document.createElement('i'); - - closeIcon.classList.add('dashicons', 'dashicons-no', 'vizualizer-renew-notice-close-icon'); - - closeIcon.addEventListener('click', function() { - document.body.removeChild(overlay); - document.body.removeChild(popup); - }); - - popup.appendChild(closeIcon); - - document.body.appendChild(popup); - +function createPopupProBlocker( $ , e ) { + if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) { + $("#overlay-visualizer").css("display", "block"); + $(".vizualizer-renew-notice-popup").css("display", "block"); + return true; + } + return false; } (function ($, vmv, vu) { @@ -135,8 +87,7 @@ function createPopupProBlocker() { $('.visualizer-chart-shortcode').click(function (e) { - if ( ! visualizer.is_pro_user && e.target.classList.contains('viz-is-pro-chart') ) { - createPopupProBlocker(); + if ( createPopupProBlocker( $, e ) ) { e.preventDefault(); e.stopPropagation(); return; @@ -193,8 +144,7 @@ function createPopupProBlocker() { $('.visualizer-chart-edit').click(function (event) { - if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { - createPopupProBlocker(); + if ( createPopupProBlocker( $, event ) ) { return; } @@ -213,16 +163,14 @@ function createPopupProBlocker() { return false; }); $(".visualizer-chart-clone").on("click", function ( event ) { - if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { - createPopupProBlocker(); + if ( createPopupProBlocker( $, event ) ) { event.preventDefault(); } }); $(".visualizer-chart-export").on("click", function (event) { - if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { - createPopupProBlocker(); + if ( createPopupProBlocker( $, event ) ) { return; } @@ -247,8 +195,7 @@ function createPopupProBlocker() { }); $(".visualizer-chart-image").on("click", function (event) { - if ( ! visualizer.is_pro_user && event.target.classList.contains('viz-is-pro-chart') ) { - createPopupProBlocker(); + if ( createPopupProBlocker( $, event ) ) { return; } $('body').trigger('visualizer:action:specificchart', {action: 'image', id: $(this).attr("data-chart"), data: null, dataObj: {name: $(this).attr("data-chart-title")}}); From 94c9181cc1ef8cf4ef718ea3d13e3d937044c624 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Mon, 20 May 2024 13:32:31 +0300 Subject: [PATCH 05/10] removed leftover testing code --- classes/Visualizer/Render/Library.php | 28 ++++----------------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 09210caa..0ffeeacb 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -222,8 +222,8 @@ private function _renderLibrary() { $license_key = $license->key; $download_id = $license->download_id; } - $admin_license_url = admin_url('options-general.php#visualizer_pro_license'); - $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' .$download_id, 'visualizer_license_block' ); + $admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' ); + $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' ); // Added by Ash/Upwork $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended // Added by Ash/Upwork @@ -235,12 +235,12 @@ private function _renderLibrary() {

Alert!

' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . '

'; - -// echo ' -// -//

Alert!

-//

-// In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it. -//

-//
-// '; } else { echo '
'; echo '
'; From 565348d79d7e823fe0215054a30014221ed10951 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Mon, 20 May 2024 13:34:44 +0300 Subject: [PATCH 06/10] lint code --- classes/Visualizer/Render/Library.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 0ffeeacb..e5602dd5 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -235,7 +235,7 @@ private function _renderLibrary() {

Alert!

' . esc_html__( 'In order to edit premium charts, benefit from updates and support for Visualizer Premium plugin, please renew your license code or activate it.', 'visualizer' ) . '

'; } - /** - * Renders library content. - * - * @since 1.0.0 + * Renders pro charts blocker. * * @access private */ - private function _renderLibrary() { + private function _renderProPopupBlocker () { $license = get_option( 'visualizer_pro_license_data', 'free' ); $license_key = ''; $download_id = ''; @@ -224,10 +221,7 @@ private function _renderLibrary() { } $admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' ); $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' ); - // Added by Ash/Upwork - $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended - // Added by Ash/Upwork - echo $this->custom_css; + if ( ! Visualizer_Module::is_pro() ) { echo '
@@ -257,6 +251,23 @@ private function _renderLibrary() { }); '; } + } + /** + * Renders library content. + * + * @since 1.0.0 + * + * @access private + */ + private function _renderLibrary() { + + // Added by Ash/Upwork + $filterBy = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : null; // phpcs:ignore WordPress.Security.NonceVerification.Recommended + // Added by Ash/Upwork + echo $this->custom_css; + + $this->_renderProPopupBlocker(); + echo '
'; echo ''; $this->getDisplayForm(); From 064c73b909c170a0fa652967c2901dda115b99d5 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Mon, 20 May 2024 13:49:34 +0300 Subject: [PATCH 08/10] lint code --- classes/Visualizer/Render/Library.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index e1e05936..73bc6609 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -211,7 +211,7 @@ private function getDisplayForm() { * * @access private */ - private function _renderProPopupBlocker () { + private function _renderProPopupBlocker() { $license = get_option( 'visualizer_pro_license_data', 'free' ); $license_key = ''; $download_id = ''; From 7a582503d141f755d28f71ada1880bfc31bc1c6d Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Wed, 22 May 2024 22:18:00 +0300 Subject: [PATCH 09/10] chore: addresed pr review changes --- classes/Visualizer/Render/Library.php | 27 +++++++++++++++------------ css/library.css | 13 +++++++++++-- js/library.js | 12 ++++++------ 3 files changed, 32 insertions(+), 20 deletions(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 73bc6609..73d61080 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -212,6 +212,9 @@ private function getDisplayForm() { * @access private */ private function _renderProPopupBlocker() { + if ( Visualizer_Module::is_pro() ) { + return; + } $license = get_option( 'visualizer_pro_license_data', 'free' ); $license_key = ''; $download_id = ''; @@ -221,13 +224,11 @@ private function _renderProPopupBlocker() { } $admin_license_url = admin_url( 'options-general.php#visualizer_pro_license' ); $renew_license_url = tsdk_utmify( Visualizer_Plugin::STORE_URL . '?edd_license_key=' . $license_key . '&download_id=' . $download_id, 'visualizer_license_block' ); - - if ( ! Visualizer_Module::is_pro() ) { - echo ' + echo '
'; - } + } /** * Renders library content. diff --git a/css/library.css b/css/library.css index 621cef62..81017ca3 100644 --- a/css/library.css +++ b/css/library.css @@ -595,8 +595,17 @@ div#visualizer-types ul, div#visualizer-types form p { .vizualizer-renew-notice-close-icon { position: absolute; - top: 10px; - right: 10px; + top: -10px; + right: -70px; cursor: pointer; color: #333; + background: none; + border: none; + padding: 0; + outline: none; + /* Reset button styles */ + display: inline-block; + font: inherit; + text-align: inherit; + text-decoration: none; } diff --git a/js/library.js b/js/library.js index 55869c47..d0efddd1 100644 --- a/js/library.js +++ b/js/library.js @@ -85,11 +85,11 @@ function createPopupProBlocker( $ , e ) { $(this).parent('form').submit(); }); - $('.visualizer-chart-shortcode').click(function (e) { + $('.visualizer-chart-shortcode').click(function (event) { - if ( createPopupProBlocker( $, e ) ) { - e.preventDefault(); - e.stopPropagation(); + if ( createPopupProBlocker( $, event ) ) { + event.preventDefault(); + event.stopPropagation(); return; } @@ -98,12 +98,12 @@ function createPopupProBlocker( $ , e ) { if (window.getSelection && document.createRange) { selection = window.getSelection(); range = document.createRange(); - range.selectNodeContents(e.target); + range.selectNodeContents(event.target); selection.removeAllRanges(); selection.addRange(range); } else if (document.selection && document.body.createTextRange) { range = document.body.createTextRange(); - range.moveToElementText(e.target); + range.moveToElementText(event.target); range.select(); } }); From 187c7f6fc60eb79d14a9adc6064030cca1752f05 Mon Sep 17 00:00:00 2001 From: GrigoreMihai Date: Thu, 23 May 2024 15:33:41 +0300 Subject: [PATCH 10/10] chore: added e2e test for pro chart lock --- classes/Visualizer/Render/Library.php | 2 +- tests/e2e/specs/upsell.spec.js | 216 +++++++++++++++----------- 2 files changed, 122 insertions(+), 96 deletions(-) diff --git a/classes/Visualizer/Render/Library.php b/classes/Visualizer/Render/Library.php index 73d61080..1c61c5cc 100644 --- a/classes/Visualizer/Render/Library.php +++ b/classes/Visualizer/Render/Library.php @@ -212,7 +212,7 @@ private function getDisplayForm() { * @access private */ private function _renderProPopupBlocker() { - if ( Visualizer_Module::is_pro() ) { + if ( Visualizer_Module::is_pro() ) { return; } $license = get_option( 'visualizer_pro_license_data', 'free' ); diff --git a/tests/e2e/specs/upsell.spec.js b/tests/e2e/specs/upsell.spec.js index 9e63ffb3..170b7ef7 100644 --- a/tests/e2e/specs/upsell.spec.js +++ b/tests/e2e/specs/upsell.spec.js @@ -9,99 +9,125 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' ); const { deleteAllCharts, getAssetFilePath, CHART_JS_LABELS, selectChartAdmin } = require('../utils/common'); test.describe( 'Upsell', () => { - test.beforeEach( async ( { admin, requestUtils, page } ) => { - await deleteAllCharts( requestUtils ); - await admin.visitAdminPage( 'admin.php?page=visualizer' ); - page.setDefaultTimeout( 5000 ); - } ); - - test( 'chart selection on admin', async ( { admin, page } ) => { - await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' ); - await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' ); - await page.waitForSelector('h1:text("Visualizer")'); - - expect( await page.frameLocator('iframe').locator('.pro-upsell').count() ).toBe( 11 ); - - const proUpsellElements = await page.frameLocator('iframe').locator('a.pro-upsell').all(); - - for (const element of proUpsellElements) { - const href = await element.getAttribute('href'); - const searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('charttypes'); - } - } ); - - test( 'chart settings on admin', async ( { admin, page } ) => { - await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' ); - await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' ); - await page.waitForSelector('h1:text("Visualizer")'); - await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.pie ); - - await expect( page.frameLocator('iframe').locator( '#viz-tabs' ) ).toBeVisible(); - - expect( await page.frameLocator('iframe').locator('#vz-chart-source .viz-group-title .dashicons-lock').count() ).toBe( 5 ); - - - const uploadFileUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_csv .only-pro-inner a'); - let href = await uploadFileUpsell.getAttribute('href'); - let searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('import-file'); - - const remoteImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_json .only-pro-inner a').first(); - href = await remoteImportUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('import-url'); - - const otherChartUpsell = page.frameLocator('iframe').locator('#vz-chart-source .viz-import-from-other .only-pro-inner a'); - href = await otherChartUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('import-chart'); - - const wpImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query_wp .only-pro-inner a'); - href = await wpImportUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('import-wp'); - await page.frameLocator('iframe').getByRole('heading', { name: /Import from WordPress/ }).click(); - await expect(page.frameLocator('iframe').locator('#vz-chart-source')).toContainText('Upgrade to PRO to activate this feature!'); - - const dbImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query .only-pro-inner a'); - href = await dbImportUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('db-query'); - - await page.frameLocator('iframe').getByRole('heading', { name: /Import from database/ }).click(); - await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!'); - await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now'); - - await page.frameLocator('iframe').getByRole('link', { name: 'Settings' }).click(); - - const dataFilterConfigurationUpsell = page.frameLocator('iframe').locator('#vz-data-controls .only-pro-inner a'); - href = await dataFilterConfigurationUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('data-filter-configuration'); - - const frontendActionsUpsell = page.frameLocator('iframe').locator('#vz-frontend-actions .only-pro-inner a'); - href = await frontendActionsUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('frontend-actions'); - - const chartPermissionsUpsell = page.frameLocator('iframe').locator('#vz-permissions .only-pro-inner a'); - href = await chartPermissionsUpsell.getAttribute('href'); - searchParams = new URLSearchParams(href); - expect( searchParams.get('utm_campaign') ).toBe('chart-permissions'); - await page.frameLocator('iframe').getByRole('heading', { name: /Permissions/ }).click(); - await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!'); - await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now'); - }); - - test( 'featured tab in Install Plugin (SDK)', async ( { admin, page } ) => { - await admin.visitAdminPage( 'plugin-install.php' ); - - // Those should be visible only when a PRO product is installed. - await expect( page.getByText('Image Optimization by Optimole') ).toBeHidden(); - await expect( page.locator('#the-list div').filter({ hasText: 'Otter Blocks' }).nth(1) ).toBeHidden(); - - await expect( page.getByLabel('Install Image Optimization by') ).toBeHidden(); - await expect( page.getByLabel('Install Otter Blocks') ).toBeHidden(); - }); + test.beforeEach( async ( { admin, requestUtils, page } ) => { + await deleteAllCharts( requestUtils ); + await admin.visitAdminPage( 'admin.php?page=visualizer' ); + page.setDefaultTimeout( 5000 ); + } ); + + test( 'chart selection on admin', async ( { admin, page } ) => { + await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' ); + await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' ); + await page.waitForSelector('h1:text("Visualizer")'); + + expect( await page.frameLocator('iframe').locator('.pro-upsell').count() ).toBe( 11 ); + + const proUpsellElements = await page.frameLocator('iframe').locator('a.pro-upsell').all(); + + for (const element of proUpsellElements) { + const href = await element.getAttribute('href'); + const searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('charttypes'); + } + } ); + + test( 'chart settings on admin', async ( { admin, page } ) => { + await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' ); + await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' ); + await page.waitForSelector('h1:text("Visualizer")'); + await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.pie ); + + await expect( page.frameLocator('iframe').locator( '#viz-tabs' ) ).toBeVisible(); + + expect( await page.frameLocator('iframe').locator('#vz-chart-source .viz-group-title .dashicons-lock').count() ).toBe( 5 ); + + + const uploadFileUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_csv .only-pro-inner a'); + let href = await uploadFileUpsell.getAttribute('href'); + let searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('import-file'); + + const remoteImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_json .only-pro-inner a').first(); + href = await remoteImportUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('import-url'); + + const otherChartUpsell = page.frameLocator('iframe').locator('#vz-chart-source .viz-import-from-other .only-pro-inner a'); + href = await otherChartUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('import-chart'); + + const wpImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query_wp .only-pro-inner a'); + href = await wpImportUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('import-wp'); + await page.frameLocator('iframe').getByRole('heading', { name: /Import from WordPress/ }).click(); + await expect(page.frameLocator('iframe').locator('#vz-chart-source')).toContainText('Upgrade to PRO to activate this feature!'); + + const dbImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query .only-pro-inner a'); + href = await dbImportUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('db-query'); + + await page.frameLocator('iframe').getByRole('heading', { name: /Import from database/ }).click(); + await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!'); + await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now'); + + await page.frameLocator('iframe').getByRole('link', { name: 'Settings' }).click(); + + const dataFilterConfigurationUpsell = page.frameLocator('iframe').locator('#vz-data-controls .only-pro-inner a'); + href = await dataFilterConfigurationUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('data-filter-configuration'); + + const frontendActionsUpsell = page.frameLocator('iframe').locator('#vz-frontend-actions .only-pro-inner a'); + href = await frontendActionsUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('frontend-actions'); + + const chartPermissionsUpsell = page.frameLocator('iframe').locator('#vz-permissions .only-pro-inner a'); + href = await chartPermissionsUpsell.getAttribute('href'); + searchParams = new URLSearchParams(href); + expect( searchParams.get('utm_campaign') ).toBe('chart-permissions'); + await page.frameLocator('iframe').getByRole('heading', { name: /Permissions/ }).click(); + await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!'); + await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now'); + }); + + test( 'featured tab in Install Plugin (SDK)', async ( { admin, page } ) => { + await admin.visitAdminPage( 'plugin-install.php' ); + + // Those should be visible only when a PRO product is installed. + await expect( page.getByText('Image Optimization by Optimole') ).toBeHidden(); + await expect( page.locator('#the-list div').filter({ hasText: 'Otter Blocks' }).nth(1) ).toBeHidden(); + + await expect( page.getByLabel('Install Image Optimization by') ).toBeHidden(); + await expect( page.getByLabel('Install Otter Blocks') ).toBeHidden(); + }); + + test( 'pro chart license lock', async ( { admin, page } ) => { + await admin.visitAdminPage('admin.php?page=visualizer'); + await page.waitForURL('**/admin.php?page=visualizer'); + + // Check if the popup HTML is present + const popupSelector = '.vizualizer-renew-notice-popup'; + const popup = await page.$(popupSelector); + expect(popup).not.toBeNull(); + + const heading = await page.$('h1.vizualizer-renew-notice-heading'); + expect(heading).not.toBeNull(); + + const message = await page.$('p.vizualizer-renew-notice-message'); + expect(message).not.toBeNull(); + + const renewButton = await page.$('button.vizualizer-renew-notice-renew-button'); + expect(renewButton).not.toBeNull(); + + const activateButton = await page.$('button.vizualizer-renew-notice-activate-button'); + expect(activateButton).not.toBeNull(); + + const closeButton = await page.$('button.vizualizer-renew-notice-close-icon'); + expect(closeButton).not.toBeNull(); + }); + } );