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

Overlay_spec.js « specs « UI « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 578ddf3bba0b8bb29487d45fdedeb78dd2c8df97 (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
    /*!
 * Piwik - free/libre analytics platform
 *
 * Overlay screenshot tests.
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

// TODO: should be stored in Overlay plugin
describe("Overlay", function () {
    this.retries(3);

    this.timeout(0);

    var url = null;
    var urlWithSegment;

    function removeOptOutIframe(page) {
        page.evaluate(function () {
            $('iframe#optOutIframe', $('iframe').contents()).remove();
        });
    }

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

        url = baseUrl + hash;
        urlWithSegment = baseUrl + '&segment=' + encodeURIComponent('visitIp==20.56.34.67') + hash;

        testEnvironment.callApi("SitesManager.addSiteAliasUrls", {idSite: 3, urls: [config.piwikUrl]}, done);
    });

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

    it("should load correctly", function (done) {
        expect.screenshot("loaded").to.be.capture(function (page) {
            page.load(url);

            removeOptOutIframe(page);
        }, done);
    });

    it("should show clicks when hover over link in iframe", function (done) {
        expect.screenshot("page_link_clicks").to.be.capture(function (page) {
            var pos = page.webpage.evaluate(function () {
                var iframe = $('iframe'),
                    innerOffset = $('.btn.btn-large', iframe.contents()).offset();
                return {
                    x: iframe.offset().left + innerOffset.left,
                    y: iframe.offset().top + innerOffset.top
                };
            });
            page.sendMouseEvent('mousemove', pos);

            page.evaluate(function () {
                $('div#PIS_StatusBar', $('iframe').contents()).each(function () {
                    var html = $(this).html();
                    html = html.replace(/localhost\:[0-9]+/g, 'localhost');
                    $(this).html(html);
                });
            });

            removeOptOutIframe(page);
        }, done);
    });

    it("should show stats for new links when dropdown opened", function (done) {
        expect.screenshot("page_new_links").to.be.capture(function (page) {
            var pos = page.webpage.evaluate(function () {
                var iframe = $('iframe'),
                    innerOffset = $('.dropdown-toggle', iframe.contents()).offset();
                return {
                    x: iframe.offset().left + innerOffset.left + 32, // position is incorrect for some reason w/o adding pixels
                    y: iframe.offset().top + innerOffset.top
                };
            });
            page.sendMouseEvent('click', pos);
            page.wait(2000);

            removeOptOutIframe(page);
        }, done);
    });

    it("should change page when clicking on internal iframe link", function (done) {
        expect.screenshot("page_change").to.be.capture(function (page) {
            var pos = page.webpage.evaluate(function () {
                var iframe = $('iframe'),
                    innerOffset = $('ul.nav>li:nth-child(2)>a', iframe.contents()).offset();
                return {
                    x: iframe.offset().left + innerOffset.left + 32, // position is incorrect for some reason w/o adding pixels
                    y: iframe.offset().top + innerOffset.top
                };
            });
            page.sendMouseEvent('click', pos);

            removeOptOutIframe(page);
        }, done);
    });

    it("should change date range when period changed", function (done) {
        expect.screenshot("period_change").to.be.capture(function (page) {
            page.evaluate(function () {
                $('#overlayDateRangeSelect').val('day;yesterday').trigger('change');
            });

            removeOptOutIframe(page);
        }, done);
    });

    it("should open row evolution popup when row evolution link clicked", function (done) {
        expect.screenshot("row_evolution").to.be.capture(function (page) {
            page.evaluate(function () {
                $('#overlayRowEvolution').click();
            }, 500);
            page.evaluate(function () {
                $('.jqplot-xaxis').hide(); // xaxis will change every day so hide it
            });

            removeOptOutIframe(page);
        }, done);
    });

    it("should open transitions popup when transitions link clicked", function (done) {
        expect.screenshot("transitions").to.be.capture(function (page) {
            page.evaluate(function () {
                $('button.ui-dialog-titlebar-close').click();
            }, 500);
            page.evaluate(function () {
                $('#overlayTransitions').click();
            }, 500);

            removeOptOutIframe(page);
        }, done);
    });

    it("should load an overlay with segment", function (done) {
        expect.screenshot("loaded_with_segment").to.be.capture(function (page) {
            page.load(urlWithSegment);

            removeOptOutIframe(page);
        }, done);
    });
});