File size: 5,279 Bytes
c938f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*!
 * Matomo - free/libre analytics platform
 *
 * SitesManager screenshot tests.
 *
 * @link    https://matomo.org
 * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

describe('BotTrackingSiteWithoutData', function () {
    this.fixture = 'Piwik\\Tests\\Fixtures\\OneVisit';

    const generalParams = 'idSite=1&period=day&date=today';
    const urlBase = `module=CoreHome&action=index&${generalParams}`;
    const urlOverview = `?${urlBase}#?${generalParams}&category=General_AIAssistants&subcategory=BotTracking_AIChatbotsOverview`;
    const urlRealtime = `?${urlBase}#?${generalParams}&category=General_AIAssistants&subcategory=BotTracking_AIChatbotsRealtime`;
    const urlContentRequests = `?${urlBase}#?${generalParams}&category=General_AIAssistants&subcategory=BotTracking_AIChatbotsContentRequests`;

    before(function () {
        testEnvironment.detectedContentDetections = ['WordPress', 'AmazonCloudFront'];
        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 a message if no bot data has been recently tracked', async function () {
        await page.goto(urlOverview);
        await page.waitForSelector('.bot-tracking-no-recent-requests-message');

        const notification = await page.$('.bot-tracking-no-recent-requests-message');

        expect(await notification.getProperty('textContent')).to.match(/No data collected/i);
    });

    it('should show the same message on the Content Requests page', async function () {
        await page.goto(urlContentRequests);
        await page.waitForSelector('.bot-tracking-no-recent-requests-message');

        const notification = await page.$('.bot-tracking-no-recent-requests-message');

        expect(await notification.getProperty('textContent')).to.match(/No data collected/i);

        // Back to the overview so the click-through flow below starts from the same place.
        await page.goto(urlOverview);
        await page.waitForSelector('.bot-tracking-no-recent-requests-message');
    });

    it('should show the same message on the Real-time page', async function () {
        await page.goto(urlRealtime);
        await page.waitForSelector('.bot-tracking-no-recent-requests-message');

        const notification = await page.$('.bot-tracking-no-recent-requests-message');

        expect(await notification.getProperty('textContent')).to.match(/No data collected/i);

        // Back to the overview so the click-through flow below starts from the same place.
        await page.goto(urlOverview);
        await page.waitForSelector('.bot-tracking-no-recent-requests-message');
    });

    it('should show the no data page', async function () {
        await page.click('.bot-tracking-no-recent-requests-message a');
        await page.waitForSelector('.tracking-method-list');

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

    it('should show details for the recommended tracking method', async function () {
        await page.click('.tracking-method-detection .btn');
        await page.waitForSelector('.tracking-method-details');

        expect(await page.$('.tracking-method-details p')).to.be.ok;
    });

    it('should show details for all other available tracking methods', async function () {
        await page.click('.tracking-method-back');
        await page.waitForSelector('.tracking-method-list');

        const methodCount = (await page.$$('.tracking-method-list .list-entry a')).length;

        // only support link should be skipped
        const methodChecksExpected = methodCount - 1;
        let methodsChecked = 0;

        for (let methodNum = 1; methodNum <= methodCount; methodNum++) {
            const method = await page.$(`.tracking-method-list .list-entry:nth-of-type(${methodNum}) a`);
            const hrefProp = await method.getProperty('href');
            const href = await hrefProp.jsonValue();

            if (!href.includes('#')) {
                // skip click on external links (detections without details)
                continue;
            }

            await method.click();
            await page.waitForSelector('.tracking-method-details');

            expect(await page.$('.tracking-method-details p')).to.be.ok;
            methodsChecked++;

            await page.click('.tracking-method-back');
            await page.waitForSelector('.tracking-method-list');
        }

        expect(methodsChecked).to.equal(
          methodChecksExpected,
          `Expected ${methodChecksExpected} tracking methods with details, found ${methodsChecked}`
        )
    });

    it('should link back to the overview', async function () {
        await page.click('.tracking-method-skip a');
        await page.waitForSelector('.matomo-widget');
        await page.waitForNetworkIdle();

        const widgets = await page.$$('.matomo-widget');
        expect(widgets.length).to.be.greaterThan(0);
    });
});