Skip to content

Commit

Permalink
Refactor UI tests into one suite and update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Sep 22, 2023
1 parent 8a08698 commit 04f8462
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 129 deletions.
2 changes: 1 addition & 1 deletion javascripts/googleAnalyticsImporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
(async () => {
const response = await fetch(window.piwik.piwik_url + '/index.php?' + new URLSearchParams(searchParams));
const data = await response.json();
if ($('.site-without-data').length && data.isGASite) {
if ($('#site-without-data').length && data.isGASite) {
displayPendingNotification('', 'successMessage');
} else if (data.displayPending) {
displayPendingNotification(data.availableDate, 'infoMessage');
Expand Down
50 changes: 0 additions & 50 deletions tests/Fixtures/EmptySiteWithSiteContentDetectionGA.php

This file was deleted.

50 changes: 0 additions & 50 deletions tests/Fixtures/EmptySiteWithSiteContentDetectionGA4.php

This file was deleted.

25 changes: 0 additions & 25 deletions tests/UI/EmptySite_GA4_spec.js

This file was deleted.

48 changes: 45 additions & 3 deletions tests/UI/EmptySite_GA_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,58 @@
describe("EmptySite_GA", function () {
this.timeout(0);

this.fixture = "Piwik\\Plugins\\GoogleAnalyticsImporter\\tests\\Fixtures\\EmptySiteWithSiteContentDetectionGA";
this.fixture = "Piwik\\Tests\\Fixtures\\EmptySite";

const generalParams = 'idSite=1&period=day&date=2010-01-03';

it('should show no data screen with GA import and with ga3 offset banner', async function () {
before(function () {
testEnvironment.detectedContentDetections = [];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();
});

after(function () {
// unset all detections so fake class is no longer used
delete testEnvironment.detectedContentDetections;
delete testEnvironment.connectedConsentManagers;
testEnvironment.save();
});

it('should show no data screen with GA import recommended', async function () {
testEnvironment.detectedContentDetections = ['GoogleAnalytics3', 'Cloudflare'];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

const urlToTest = "?" + generalParams + "&module=CoreHome&action=index";
await page.goto(urlToTest);

const pageElement = await page.$('.page');
expect(await pageElement.screenshot()).to.matchImage('emptySiteDashboard');
expect(await pageElement.screenshot()).to.matchImage('list');
});

it('should show import details with ga3 offset banner', async function () {
await page.evaluate(() => $('#start-tracking-detection a[href="#googleanalyticsimporter"]')[0].click());

const pageElement = await page.$('.page');
expect(await pageElement.screenshot()).to.matchImage('details_ga3');
});

it('should show no data screen with GA import recommended', async function () {
testEnvironment.detectedContentDetections = ['GoogleAnalytics4', 'Cloudflare'];
testEnvironment.connectedConsentManagers = [];
testEnvironment.save();

const urlToTest = "?" + generalParams + "&module=CoreHome&action=index";
await page.goto(urlToTest);

const pageElement = await page.$('.page');
expect(await pageElement.screenshot()).to.matchImage('list');
});

it('should show import details', async function () {
await page.evaluate(() => $('#start-tracking-detection a[href="#googleanalyticsimporter"]')[0].click());

const pageElement = await page.$('.page');
expect(await pageElement.screenshot()).to.matchImage('details_ga4');
});
});
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 04f8462

Please sign in to comment.