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

Dashboard_spec.js « specs « UI « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0c4f28f08030eb4e6f1a8ae7a37c018bf91f2158 (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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*!
 * Piwik - free/libre analytics platform
 *
 * Dashboard screenshot tests.
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

// TODO: should move this & dashboard manager test to Dashboard plugin
describe("Dashboard", function () {
    this.timeout(0);

    var url = "?module=Widgetize&action=iframe&idSite=1&period=year&date=2012-08-09&moduleToWidgetize=Dashboard&"
            + "actionToWidgetize=index&idDashboard=5";

    var removeAllExtraDashboards = function (done) {
        testEnvironment.callController("Dashboard.getAllDashboards", {}, function (err, dashboards) {
            dashboards = (dashboards || []).filter(function (dash) {
                return parseInt(dash.iddashboard) > 5;
            });

            var removeDashboard = function (i) {
                if (i >= dashboards.length) {
                    done();
                    return;
                }

                console.log("Removing dashboard ID = " + dashboards[i].iddashboard);
                testEnvironment.callController("Dashboard.removeDashboard", {idDashboard: dashboards[i].iddashboard}, function () {
                    removeDashboard(i + 1);
                });
            };

            removeDashboard(0);
        });
    };

    var setup = function (done) {
        // make sure live widget doesn't refresh constantly for UI tests
        testEnvironment.overrideConfig('General', 'live_widget_refresh_after_seconds', 1000000);
        testEnvironment.save();

        // save empty layout for dashboard ID = 5
        var layout = [
            [
                {
                    uniqueId: "widgetVisitsSummarygetEvolutionGraphforceView1viewDataTablegraphEvolution",
                    parameters: {module: "VisitsSummary", action: "getEvolutionGraph", columns: "nb_visits"}
                }
            ],
            [],
            []
        ];

        // TODO: should probably include an async lib
        testEnvironment.callController("Dashboard.saveLayout", {name: 'D4', layout: JSON.stringify(layout), idDashboard: 5, idSite: 2}, function () {
            // reset default widget selection
            testEnvironment.callController("Dashboard.saveLayoutAsDefault", {layout: 0}, function () {
                removeAllExtraDashboards(done);
            });
        });
    };

    before(setup);
    after(setup);

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

    it("should move a widget when widget is drag & dropped", function (done) {
        expect.screenshot("widget_move").to.be.capture(function (page) {
            page.mousedown('.widgetTop');
            page.mouseMove('#dashboardWidgetsArea > .col:eq(2)');
            page.mouseup('#dashboardWidgetsArea > .col:eq(2)');
        }, done);
    });

    it("should refresh widget when widget refresh icon clicked", function (done) {
        expect.screenshot("widget_move_refresh").to.be.capture(function (page) {
            page.mouseMove('.widgetTop');
            page.click('.button#refresh');
            page.mouseMove('.dashboard-manager'); // let widget top hide again
        }, done);
    });

    it("should minimise widget when widget minimise icon clicked", function (done) {
        expect.screenshot("widget_minimised").to.be.capture(function (page) {
            page.mouseMove('.widgetTop');
            page.click('.button#minimise');
        }, done);
    });

    it("should unminimise widget when widget maximise icon is clicked after being minimised", function (done) {
        expect.screenshot("widget_move_unminimised").to.be.capture(function (page) {
            page.mouseMove('.widgetTop');
            page.click('.button#maximise');
            page.mouseMove('.dashboard-manager'); // let widget top hide again
        }, done);
    });

    it("should maximise widget when widget maximise icon is clicked", function (done) {
        expect.screenshot("widget_maximise").to.be.capture(function (page) {
            page.mouseMove('.widgetTop');
            page.click('.button#maximise');
        }, done);
    });

    it("should close maximise dialog when minimise icon is clicked", function (done) {
        expect.screenshot("widget_move_unmaximise").to.be.capture(function (page) {
            page.mouseMove('.widgetTop');
            page.click('.button#minimise');
            page.mouseMove('.dashboard-manager'); // let widget top hide again
        }, done);
    });

    it("should add a widget when a widget is selected in the dashboard manager", function (done) {
        expect.screenshot("widget_add_widget").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');

            page.mouseMove('.widgetpreview-categorylist>li:contains(Live!)'); // have to mouse move twice... otherwise Live! will just be highlighted
            page.click('.widgetpreview-categorylist>li:contains(Live!)');

            page.mouseMove('.widgetpreview-categorylist>li:contains(Times):first');
            page.click('.widgetpreview-categorylist>li:contains(Times):first');

            page.mouseMove('.widgetpreview-widgetlist>li:contains(Visits per local time)');
            page.click('.widgetpreview-widgetlist>li:contains(Visits per local time)');
        }, done);
    });

    it("should remove widget when remove widget icon is clicked", function (done) {
        expect.screenshot("widget_move_removed").to.be.capture(function (page) {
            var widget = '[id="widgetVisitTimegetVisitInformationPerLocalTime"]';

            page.mouseMove(widget + ' .widgetTop');
            page.click(widget + ' .button#close');

            page.click('.modal.open .modal-footer a:contains(Yes)');
            page.mouseMove('.dashboard-manager');
        }, done);
    });

    it("should change dashboard layout when new layout is selected", function (done) {
        expect.screenshot("change_layout").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=showChangeDashboardLayoutDialog]');
            page.click('.modal.open div[layout=50-50]');
            page.click('.modal.open .modal-footer a:contains(Save)');
        }, done);
    });

    it("should rename dashboard when dashboard rename process completed", function (done) {
        expect.screenshot("rename").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=renameDashboard]');
            page.evaluate(function () {
                $('#newDashboardName:visible').val('newname'); // don't use sendKeys or click, since in this test it appears to trigger a seg fault on travis
                $('.modal.open .modal-footer a:contains(Save):visible').click();
            });
        }, done);
    });

    it("should copy dashboard successfully when copy dashboard process completed", function (done) {
        expect.screenshot("copied").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=copyDashboardToUser]');
            page.evaluate(function () {
                $('[id=copyDashboardName]:last').val('');
            });
            page.sendKeys('[id=copyDashboardName]:last', 'newdash');
            page.evaluate(function () {
                $('[id=copyDashboardUser]:last').val('superUserLogin');
            });
            page.click('.modal.open .modal-footer a:contains(Ok)');

            page.load(url.replace("idDashboard=5", "idDashboard=6"));
        }, done);
    });

    it("should reset dashboard when reset dashboard process completed", function (done) {
        expect.screenshot("reset").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=resetDashboard]');
            page.click('.modal.open .modal-footer a:contains(Yes)', 4000);
            page.mouseMove('.dashboard-manager');
        }, done);
    });

    it("should remove dashboard when remove dashboard process completed", function (done) {
        expect.screenshot("removed").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=removeDashboard]');
            page.click('.modal.open .modal-footer a:contains(Yes)');
            page.mouseMove('.dashboard-manager');
            page.evaluate(function () {
                $('.widgetTop').removeClass('widgetTopHover');
            });
        }, done);
    });

    it.skip("should not fail when default widget selection changed", function (done) {
        expect.screenshot("default_widget_selection_changed").to.be.capture(function (page) {
            page.load(url);
            page.click('.dashboard-manager .title');
            page.click('li[data-action=setAsDefaultWidgets]');
            page.click('.modal.open .modal-footer a:contains(Yes)');
        }, done);
    });

    it.skip("should create new dashboard with new default widget selection when create dashboard process completed", function (done) {
        expect.screenshot("create_new").to.be.capture(function (page) {
            page.click('.dashboard-manager .title');
            page.click('li[data-action=createDashboard]');
            page.sendKeys('#createDashboardName:visible', 'newdash2');
            page.click('.modal.open .modal-footer a:contains(Ok)');
            // toggle map widget to prevent failures
            page.mouseMove('#widgetUserCountryMapvisitorMap .widgetTop', 3000);
            page.click('#widgetUserCountryMapvisitorMap #minimise');
        }, done);
    });

});