Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Overlay_spec.js « UI « tests « Overlay « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 828f095259e3ee4164c57e42902e2f31bcb7baa2 (plain)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/*!
 * Matomo - free/libre analytics platform
 *
 * Overlay screenshot tests.
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
describe("Overlay", function () {
    this.timeout(0);

    async function removeOptOutIframe(page) {
        const frame = page.frames().find(f => f.name() === 'overlayIframe');
        if (frame) {
            await frame.evaluate(function () {
                $('iframe#optOutIframe').remove();
            });
        }
    }

    function getUrl (useTokenAuth, withSegment) {
        var baseUrl = '?module=Overlay&period=year&date=today&idSite=3';
        var hash = '#?l=' + encodeURIComponent(testEnvironment.overlayUrl).replace(/[%]/g, "$");

        if (useTokenAuth === true) {
            baseUrl += '&token_auth=a4ca4238a0b923820dcc509a6f75849f';
            testEnvironment.testUseMockAuth = 0;
            testEnvironment.overrideConfig('General', 'enable_framed_pages', 1);
            testEnvironment.save();
        }

        if (withSegment) {
            return baseUrl + '&segment=' + encodeURIComponent('visitIp==50.112.3.5') + hash;
        }

        return baseUrl + hash;
    }

    before(async function () {
        await testEnvironment.callApi("SitesManager.addSiteAliasUrls", {idSite: 3, urls: [config.piwikUrl, '127.0.0.1']});
    });

    after(async function () {
        testEnvironment.testUseMockAuth = 1;
        if (testEnvironment.configOverride.General && testEnvironment.configOverride.General.enable_framed_pages) {
            delete testEnvironment.configOverride.General.enable_framed_pages;
        }
        testEnvironment.save();

        await testEnvironment.callApi("SitesManager.setSiteAliasUrls", {idSite: 3, urls: []});
    });

    var testCases = [false, true];
    for (var index = 0; index < testCases.length; index++) {
        (function(useTokenAuth) {

            var descAppendix = useTokenAuth ? ' (with auth_token)' : '';

            it("should load correctly" + descAppendix, async function () {
                await page.goto(getUrl(useTokenAuth));

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('loaded');
            });

            it("should show clicks when hover over link in iframe" + descAppendix, async function () {

                const frame = page.frames().find(f => f.name() === 'overlayIframe');
                await (await frame.$('.btn.btn-large')).hover();
                await page.waitForTimeout(250);

                await frame.evaluate(function () {
                    $('div#PIS_StatusBar').each(function () {
                        var html = $(this).html();
                        html = html.replace(/localhost\:[0-9]+/g, 'localhost');
                        $(this).html(html);
                    });
                });
                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('page_link_clicks');
            });

            it("should show stats for new links when dropdown opened" + descAppendix, async function () {
                await page.reload();
                const frame = page.frames().find(f => f.name() === 'overlayIframe');
                await (await frame.$('.dropdown-toggle')).click();

                await page.waitForTimeout(2000);

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('page_new_links');
            });

            it("should change page when clicking on internal iframe link" + descAppendix, async function () {
                const frame = page.frames().find(f => f.name() === 'overlayIframe');
                await (await frame.$('ul.nav>li:nth-child(2)>a')).click();
                await page.waitForNetworkIdle();

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('page_change');
            });

            it("should change date range when period changed" + descAppendix, async function () {
                await page.waitForSelector('#overlayDateRangeSelect');
                await page.webpage.evaluate(function () {
                    $('#overlayDateRangeSelect').val('day;yesterday').trigger('change');
                });

                await page.waitForSelector('.overlayMainMetrics,.overlayNoData');
                await page.waitForNetworkIdle();

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('period_change');
            });

            it("should open row evolution popup when row evolution link clicked" + descAppendix, async function () {
                await page.evaluate(function () {
                    $('#overlayRowEvolution').click();
                });
                await page.waitForTimeout(500); // for modal to appear
                await page.waitForNetworkIdle();
                await page.evaluate(function () {
                    $('.jqplot-xaxis').hide(); // xaxis will change every day so hide it
                });

                await page.evaluate(function () {
                    $('.ui-dialog .ui-dialog-title,.ui-dialog h2').each(function () {
                        var html = $(this).html();
                        // ensure to use localhost as url for screenshots
                        html = html.split('127.0.0.1').join('localhost')
                        $(this).html(html);
                    });
                });
                await page.waitForTimeout(500);

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('row_evolution');
            });

            it("should open transitions popup when transitions link clicked" + descAppendix, async function () {
                await page.click('button.ui-dialog-titlebar-close');
                await page.waitForSelector('#overlayTransitions');
                await page.click('#overlayTransitions');
                await page.waitForNetworkIdle();
                await page.waitForTimeout(2000);

                await page.evaluate(function () {
                    $('.Transitions_Text').each(function () {
                        var html = $(this).html();
                        // ensure to use localhost as url for screenshots
                        html = html.split('127.<wbr>​0.<wbr>​0.<wbr>​1').join('localhost')
                        $(this).html(html);
                    });
                });

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('transitions');
            });

            it("should load an overlay with segment" + descAppendix, async function () {
                await page.goto(getUrl(useTokenAuth, true));
                await page.waitForNetworkIdle();

                await page.waitForTimeout(2000);

                const frame = page.frames().find(f => f.name() === 'overlayIframe');
                await frame.waitForSelector('.PIS_LinkTag');

                await removeOptOutIframe(page);
                expect(await page.screenshot({fullPage: true})).to.matchImage('loaded_with_segment');
            });
        })(testCases[index]);
    }

    it("should load overlay correctly when coming from an widgetized action report", async function () {
        testEnvironment.testUseMockAuth = 0;
        testEnvironment.overrideConfig('General', 'enable_framed_pages', 1);
        testEnvironment.overrideConfig('General', 'enable_framed_allow_write_admin_token_auth', 1);
        testEnvironment.save();

        await page.goto('?module=Widgetize&action=iframe&disableLink=0&widget=1&moduleToWidgetize=Actions&actionToWidgetize=getPageUrls&idSite=3&period=year&date=today&disableLink=1&widget=1&flat=1&token_auth=a4ca4238a0b923820dcc509a6f75849f', {waitUntil: 'networkidle0'});
        await page.waitForNetworkIdle();

        const row = await page.jQuery('.dataTable tbody tr:first', { waitFor: true });
        await row.hover();

        const icon = await page.waitForSelector('.dataTable tbody tr a.actionOverlay');

        const [popup] = await Promise.all([
            new Promise(resolve => page.once('popup', resolve)),
            await icon.click()
        ]);

        await popup.waitForTimeout(2500);

        await removeOptOutIframe(popup);
        expect(await popup.screenshot({fullPage: true})).to.matchImage('loaded_from_actions');
    });

});