Skip to content

Commit 187c7f6

Browse files
committed
chore: added e2e test for pro chart lock
1 parent 7a58250 commit 187c7f6

File tree

2 files changed

+122
-96
lines changed

2 files changed

+122
-96
lines changed

classes/Visualizer/Render/Library.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function getDisplayForm() {
212212
* @access private
213213
*/
214214
private function _renderProPopupBlocker() {
215-
if ( Visualizer_Module::is_pro() ) {
215+
if ( Visualizer_Module::is_pro() ) {
216216
return;
217217
}
218218
$license = get_option( 'visualizer_pro_license_data', 'free' );

tests/e2e/specs/upsell.spec.js

Lines changed: 121 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -9,99 +9,125 @@ const { test, expect } = require( '@wordpress/e2e-test-utils-playwright' );
99
const { deleteAllCharts, getAssetFilePath, CHART_JS_LABELS, selectChartAdmin } = require('../utils/common');
1010

1111
test.describe( 'Upsell', () => {
12-
test.beforeEach( async ( { admin, requestUtils, page } ) => {
13-
await deleteAllCharts( requestUtils );
14-
await admin.visitAdminPage( 'admin.php?page=visualizer' );
15-
page.setDefaultTimeout( 5000 );
16-
} );
17-
18-
test( 'chart selection on admin', async ( { admin, page } ) => {
19-
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
20-
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
21-
await page.waitForSelector('h1:text("Visualizer")');
22-
23-
expect( await page.frameLocator('iframe').locator('.pro-upsell').count() ).toBe( 11 );
24-
25-
const proUpsellElements = await page.frameLocator('iframe').locator('a.pro-upsell').all();
26-
27-
for (const element of proUpsellElements) {
28-
const href = await element.getAttribute('href');
29-
const searchParams = new URLSearchParams(href);
30-
expect( searchParams.get('utm_campaign') ).toBe('charttypes');
31-
}
32-
} );
33-
34-
test( 'chart settings on admin', async ( { admin, page } ) => {
35-
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
36-
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
37-
await page.waitForSelector('h1:text("Visualizer")');
38-
await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.pie );
39-
40-
await expect( page.frameLocator('iframe').locator( '#viz-tabs' ) ).toBeVisible();
41-
42-
expect( await page.frameLocator('iframe').locator('#vz-chart-source .viz-group-title .dashicons-lock').count() ).toBe( 5 );
43-
44-
45-
const uploadFileUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_csv .only-pro-inner a');
46-
let href = await uploadFileUpsell.getAttribute('href');
47-
let searchParams = new URLSearchParams(href);
48-
expect( searchParams.get('utm_campaign') ).toBe('import-file');
49-
50-
const remoteImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_json .only-pro-inner a').first();
51-
href = await remoteImportUpsell.getAttribute('href');
52-
searchParams = new URLSearchParams(href);
53-
expect( searchParams.get('utm_campaign') ).toBe('import-url');
54-
55-
const otherChartUpsell = page.frameLocator('iframe').locator('#vz-chart-source .viz-import-from-other .only-pro-inner a');
56-
href = await otherChartUpsell.getAttribute('href');
57-
searchParams = new URLSearchParams(href);
58-
expect( searchParams.get('utm_campaign') ).toBe('import-chart');
59-
60-
const wpImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query_wp .only-pro-inner a');
61-
href = await wpImportUpsell.getAttribute('href');
62-
searchParams = new URLSearchParams(href);
63-
expect( searchParams.get('utm_campaign') ).toBe('import-wp');
64-
await page.frameLocator('iframe').getByRole('heading', { name: /Import from WordPress/ }).click();
65-
await expect(page.frameLocator('iframe').locator('#vz-chart-source')).toContainText('Upgrade to PRO to activate this feature!');
66-
67-
const dbImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query .only-pro-inner a');
68-
href = await dbImportUpsell.getAttribute('href');
69-
searchParams = new URLSearchParams(href);
70-
expect( searchParams.get('utm_campaign') ).toBe('db-query');
71-
72-
await page.frameLocator('iframe').getByRole('heading', { name: /Import from database/ }).click();
73-
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!');
74-
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now');
75-
76-
await page.frameLocator('iframe').getByRole('link', { name: 'Settings' }).click();
77-
78-
const dataFilterConfigurationUpsell = page.frameLocator('iframe').locator('#vz-data-controls .only-pro-inner a');
79-
href = await dataFilterConfigurationUpsell.getAttribute('href');
80-
searchParams = new URLSearchParams(href);
81-
expect( searchParams.get('utm_campaign') ).toBe('data-filter-configuration');
82-
83-
const frontendActionsUpsell = page.frameLocator('iframe').locator('#vz-frontend-actions .only-pro-inner a');
84-
href = await frontendActionsUpsell.getAttribute('href');
85-
searchParams = new URLSearchParams(href);
86-
expect( searchParams.get('utm_campaign') ).toBe('frontend-actions');
87-
88-
const chartPermissionsUpsell = page.frameLocator('iframe').locator('#vz-permissions .only-pro-inner a');
89-
href = await chartPermissionsUpsell.getAttribute('href');
90-
searchParams = new URLSearchParams(href);
91-
expect( searchParams.get('utm_campaign') ).toBe('chart-permissions');
92-
await page.frameLocator('iframe').getByRole('heading', { name: /Permissions/ }).click();
93-
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!');
94-
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now');
95-
});
96-
97-
test( 'featured tab in Install Plugin (SDK)', async ( { admin, page } ) => {
98-
await admin.visitAdminPage( 'plugin-install.php' );
99-
100-
// Those should be visible only when a PRO product is installed.
101-
await expect( page.getByText('Image Optimization by Optimole') ).toBeHidden();
102-
await expect( page.locator('#the-list div').filter({ hasText: 'Otter Blocks' }).nth(1) ).toBeHidden();
103-
104-
await expect( page.getByLabel('Install Image Optimization by') ).toBeHidden();
105-
await expect( page.getByLabel('Install Otter Blocks') ).toBeHidden();
106-
});
12+
test.beforeEach( async ( { admin, requestUtils, page } ) => {
13+
await deleteAllCharts( requestUtils );
14+
await admin.visitAdminPage( 'admin.php?page=visualizer' );
15+
page.setDefaultTimeout( 5000 );
16+
} );
17+
18+
test( 'chart selection on admin', async ( { admin, page } ) => {
19+
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
20+
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
21+
await page.waitForSelector('h1:text("Visualizer")');
22+
23+
expect( await page.frameLocator('iframe').locator('.pro-upsell').count() ).toBe( 11 );
24+
25+
const proUpsellElements = await page.frameLocator('iframe').locator('a.pro-upsell').all();
26+
27+
for (const element of proUpsellElements) {
28+
const href = await element.getAttribute('href');
29+
const searchParams = new URLSearchParams(href);
30+
expect( searchParams.get('utm_campaign') ).toBe('charttypes');
31+
}
32+
} );
33+
34+
test( 'chart settings on admin', async ( { admin, page } ) => {
35+
await admin.visitAdminPage( 'admin.php?page=visualizer&vaction=addnew' );
36+
await page.waitForURL( '**/admin.php?page=visualizer&vaction=addnew' );
37+
await page.waitForSelector('h1:text("Visualizer")');
38+
await selectChartAdmin( page.frameLocator('iframe'), CHART_JS_LABELS.pie );
39+
40+
await expect( page.frameLocator('iframe').locator( '#viz-tabs' ) ).toBeVisible();
41+
42+
expect( await page.frameLocator('iframe').locator('#vz-chart-source .viz-group-title .dashicons-lock').count() ).toBe( 5 );
43+
44+
45+
const uploadFileUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_csv .only-pro-inner a');
46+
let href = await uploadFileUpsell.getAttribute('href');
47+
let searchParams = new URLSearchParams(href);
48+
expect( searchParams.get('utm_campaign') ).toBe('import-file');
49+
50+
const remoteImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_json .only-pro-inner a').first();
51+
href = await remoteImportUpsell.getAttribute('href');
52+
searchParams = new URLSearchParams(href);
53+
expect( searchParams.get('utm_campaign') ).toBe('import-url');
54+
55+
const otherChartUpsell = page.frameLocator('iframe').locator('#vz-chart-source .viz-import-from-other .only-pro-inner a');
56+
href = await otherChartUpsell.getAttribute('href');
57+
searchParams = new URLSearchParams(href);
58+
expect( searchParams.get('utm_campaign') ).toBe('import-chart');
59+
60+
const wpImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query_wp .only-pro-inner a');
61+
href = await wpImportUpsell.getAttribute('href');
62+
searchParams = new URLSearchParams(href);
63+
expect( searchParams.get('utm_campaign') ).toBe('import-wp');
64+
await page.frameLocator('iframe').getByRole('heading', { name: /Import from WordPress/ }).click();
65+
await expect(page.frameLocator('iframe').locator('#vz-chart-source')).toContainText('Upgrade to PRO to activate this feature!');
66+
67+
const dbImportUpsell = page.frameLocator('iframe').locator('#vz-chart-source .visualizer_source_query .only-pro-inner a');
68+
href = await dbImportUpsell.getAttribute('href');
69+
searchParams = new URLSearchParams(href);
70+
expect( searchParams.get('utm_campaign') ).toBe('db-query');
71+
72+
await page.frameLocator('iframe').getByRole('heading', { name: /Import from database/ }).click();
73+
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!');
74+
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now');
75+
76+
await page.frameLocator('iframe').getByRole('link', { name: 'Settings' }).click();
77+
78+
const dataFilterConfigurationUpsell = page.frameLocator('iframe').locator('#vz-data-controls .only-pro-inner a');
79+
href = await dataFilterConfigurationUpsell.getAttribute('href');
80+
searchParams = new URLSearchParams(href);
81+
expect( searchParams.get('utm_campaign') ).toBe('data-filter-configuration');
82+
83+
const frontendActionsUpsell = page.frameLocator('iframe').locator('#vz-frontend-actions .only-pro-inner a');
84+
href = await frontendActionsUpsell.getAttribute('href');
85+
searchParams = new URLSearchParams(href);
86+
expect( searchParams.get('utm_campaign') ).toBe('frontend-actions');
87+
88+
const chartPermissionsUpsell = page.frameLocator('iframe').locator('#vz-permissions .only-pro-inner a');
89+
href = await chartPermissionsUpsell.getAttribute('href');
90+
searchParams = new URLSearchParams(href);
91+
expect( searchParams.get('utm_campaign') ).toBe('chart-permissions');
92+
await page.frameLocator('iframe').getByRole('heading', { name: /Permissions/ }).click();
93+
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade to Plus plan to activate this feature!');
94+
await expect(page.frameLocator('iframe').locator('#vz-db-wizard')).toContainText('Upgrade Now');
95+
});
96+
97+
test( 'featured tab in Install Plugin (SDK)', async ( { admin, page } ) => {
98+
await admin.visitAdminPage( 'plugin-install.php' );
99+
100+
// Those should be visible only when a PRO product is installed.
101+
await expect( page.getByText('Image Optimization by Optimole') ).toBeHidden();
102+
await expect( page.locator('#the-list div').filter({ hasText: 'Otter Blocks' }).nth(1) ).toBeHidden();
103+
104+
await expect( page.getByLabel('Install Image Optimization by') ).toBeHidden();
105+
await expect( page.getByLabel('Install Otter Blocks') ).toBeHidden();
106+
});
107+
108+
test( 'pro chart license lock', async ( { admin, page } ) => {
109+
await admin.visitAdminPage('admin.php?page=visualizer');
110+
await page.waitForURL('**/admin.php?page=visualizer');
111+
112+
// Check if the popup HTML is present
113+
const popupSelector = '.vizualizer-renew-notice-popup';
114+
const popup = await page.$(popupSelector);
115+
expect(popup).not.toBeNull();
116+
117+
const heading = await page.$('h1.vizualizer-renew-notice-heading');
118+
expect(heading).not.toBeNull();
119+
120+
const message = await page.$('p.vizualizer-renew-notice-message');
121+
expect(message).not.toBeNull();
122+
123+
const renewButton = await page.$('button.vizualizer-renew-notice-renew-button');
124+
expect(renewButton).not.toBeNull();
125+
126+
const activateButton = await page.$('button.vizualizer-renew-notice-activate-button');
127+
expect(activateButton).not.toBeNull();
128+
129+
const closeButton = await page.$('button.vizualizer-renew-notice-close-icon');
130+
expect(closeButton).not.toBeNull();
131+
});
132+
107133
} );

0 commit comments

Comments
 (0)