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

Marketplace_spec.js « specs « UI « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: dab2e3a5e65d27e4b82a5c68b03cb772c2717e95 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*!
 * Piwik - free/libre analytics platform
 *
 * Screenshot tests for main, top and admin menus.
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

describe("Marketplace", function () {
    this.timeout(0);

    this.fixture = "Piwik\\Plugins\\Marketplace\\tests\\Fixtures\\SimpleFixtureTrackFewVisits";

    var urlBase = '?module=Marketplace&action=overview&';
    var paidPluginsUrl = urlBase + 'show=premium';
    var themesUrl = urlBase + 'show=themes';
    var pluginsUrl = urlBase;

    var noLicense = 'noLicense';
    var expiredLicense = 'expiredLicense';
    var exceededLicense = 'exceededLicense';
    var validLicense = 'validLicense';

    function loadPluginDetailPage(page, pluginName, isFreePlugin)
    {
        page.load(isFreePlugin ? pluginsUrl : paidPluginsUrl);
        page.click('.card-title [piwik-plugin-name="' + pluginName + '"]');
    }

    function captureSelector(done, screenshotName, test, selector)
    {
        expect.screenshot(screenshotName).to.be.captureSelector(selector, test, done);
    }

    function captureMarketplace(done, screenshotName, test, selector)
    {
        if (!selector) {
            selector = '';
        }

        captureSelector(done, screenshotName, test, '.marketplace' + selector);
    }

    function captureWithNotification(done, screenshotName, test)
    {
        captureMarketplace(done, screenshotName, test, ',#notificationContainer');
    }

    function captureWithDialog(done, screenshotName, test)
    {
        captureSelector(done, screenshotName, test, '.ui-dialog:visible');
    }

    function assumePaidPluginsActivated()
    {
        testEnvironment.mockMarketplaceAssumePluginNamesActivated = ['CustomPlugin1','CustomPlugin2','PaidPlugin1','PaidPlugin2'];
        testEnvironment.save();
    }

    function setEnvironment(mode, consumer)
    {
        if (mode === 'user') {
            testEnvironment.idSitesViewAccess = [1];
        } else {
            // superuser
            testEnvironment.idSitesViewAccess = [];
        }

        if (mode === 'multiUserEnvironment') {
            testEnvironment.overrideConfig('General', 'multi_server_environment', '1');
        } else {
            testEnvironment.overrideConfig('General', 'multi_server_environment', '0');
        }

        testEnvironment.overrideConfig('General', 'enable_plugins_admin', '1');

        delete testEnvironment.mockMarketplaceAssumePluginNamesActivated;

        testEnvironment.consumer = consumer;
        testEnvironment.mockMarketplaceApiService = 1;
        testEnvironment.save();
    }

    ['superuser', 'user', 'multiUserEnvironment'].forEach(function (mode) {

        if (mode !== 'user') {
            it('should show available updates in plugins page', function (done) {
                setEnvironment(mode, noLicense);

                captureSelector(done, 'updates_' + mode, function (page) {
                    page.load('?module=CorePluginsAdmin&action=plugins&idSite=1&period=day&date=yesterday&activated=');
                }, '#content .card:first');
            });
        }

        it(mode + ' for a user without license key should be able to open paid plugins', function (done) {
            setEnvironment(mode, noLicense);

            captureMarketplace(done, 'paid_plugins_no_license_' + mode, function (page) {
                page.load(paidPluginsUrl);
            });
        });

        it(mode + ' for a user with license key should be able to open paid plugins', function (done) {
            setEnvironment(mode, validLicense);

            captureMarketplace(done, 'paid_plugins_with_license_' + mode, function (page) {
                page.load(paidPluginsUrl);
            });
        });

        it(mode + ' for a user with exceeded license key should be able to open paid plugins', function (done) {
            setEnvironment(mode, exceededLicense);
            assumePaidPluginsActivated();

            captureMarketplace(done, 'paid_plugins_with_exceeded_license_' + mode, function (page) {
                page.load(paidPluginsUrl);
            });
        });

        it('should show themes page', function (done) {
            setEnvironment(mode, validLicense);

            captureMarketplace(done, 'themes_with_valid_license_' + mode, function (page) {
                page.load(themesUrl);
            });
        });

        it('should show free plugin details', function (done) {
            setEnvironment(mode, noLicense);

            captureWithDialog(done, 'free_plugin_details_' + mode, function (page) {
                var isFree = true;
                loadPluginDetailPage(page, 'TreemapVisualization', isFree);
            });
        });

        it('should show paid plugin details when having no license', function (done) {
            setEnvironment(mode, noLicense);

            captureWithDialog(done, 'paid_plugin_details_no_license_' + mode, function (page) {
                assumePaidPluginsActivated();
                var isFree = false;
                loadPluginDetailPage(page, 'PaidPlugin1', isFree);
            });
        });

        it('should show paid plugin details when having valid license', function (done) {
            setEnvironment(mode, validLicense);

            captureWithDialog(done, 'paid_plugin_details_valid_license_' + mode + '_installed', function (page) {
                assumePaidPluginsActivated();
                var isFree = false;
                loadPluginDetailPage(page, 'PaidPlugin1', isFree);
            });
        });

        it('should show paid plugin details when having valid license', function (done) {
            setEnvironment(mode, exceededLicense);

            captureWithDialog(done, 'paid_plugin_details_exceeded_license_' + mode, function (page) {
                assumePaidPluginsActivated();
                var isFree = false;
                loadPluginDetailPage(page, 'PaidPlugin1', isFree);
            });
        });
    });

    var mode = 'superuser';

    it('should show a dialog showing a list of all possible plugins to install', function (done) {
        setEnvironment(mode, validLicense);

        captureSelector(done, mode + '_install_all_paid_plugins_at_once', function (page) {
            page.load(pluginsUrl);
            page.click('.installAllPaidPlugins');
        }, '.modal.open');
    });

    it('should show an error message when invalid license key entered', function (done) {
        setEnvironment(mode, noLicense);

        captureWithNotification(done, mode + '_invalid_license_key_entered', function (page) {
            page.load(pluginsUrl);
            page.sendKeys('#license_key', 'invalid');
            page.click('.marketplace-paid-intro'); // click outside so change event is triggered
            page.click('#submit_license_key input');
        });
    });

    it('should show a confirmation before removing a license key', function (done) {
        setEnvironment(mode, validLicense);

        captureSelector(done, mode + '_remove_license_key_confirmation', function (page) {
            page.load(pluginsUrl);
            page.click('#remove_license_key input');
        }, '.modal.open');
    });

    it('should show a confirmation before removing a license key', function (done) {
        setEnvironment(mode, noLicense);

        captureMarketplace(done, mode + '_remove_license_key_confirmed', function (page) {
            page.click('.modal.open .modal-footer a:contains(Yes)')
        });
    });

    it('should show a success message when valid license key entered', function (done) {
        setEnvironment(mode, noLicense);

        captureMarketplace(done, mode + '_valid_license_key_entered', function (page) {
            page.load(pluginsUrl);
            page.sendKeys('#license_key', 'valid');
            page.execCallback(function () {
                setEnvironment(mode, validLicense);
            });
            page.click('#submit_license_key input');
        });
    });

    it('should hide activate / deactivate buttons if plugins admin is disabled', function (done) {
        setEnvironment(mode, noLicense);
        testEnvironment.overrideConfig('General', 'enable_plugins_admin', '0');
        testEnvironment.save();

        captureMarketplace(done, mode + '_enable_plugins_admin', function (page) {
            page.load(pluginsUrl);
        });
    });

    it('should hide activate / deactivate buttons if plugins admin is disabled when also multi server environment is enabled', function (done) {
        setEnvironment('multiUserEnvironment', noLicense);
        testEnvironment.overrideConfig('General', 'enable_plugins_admin', '0');
        testEnvironment.save();

        captureMarketplace(done, mode + '_enable_plugins_admin_with_multiserver_enabled', function (page) {
            page.load(pluginsUrl);
        });
    });

    [expiredLicense, exceededLicense, validLicense, noLicense].forEach(function (consumer) {
        it('should show a subscription overview for ' + consumer, function (done) {
            setEnvironment('superuser', consumer);

            captureSelector(done, 'subscription_overview_' + consumer, function (page) {
                page.load('?module=Marketplace&action=subscriptionOverview');
            }, '#content');
        });
    });

    [noLicense, expiredLicense, exceededLicense].forEach(function (consumer) {
        // when there is no license it should not show a warning! as it could be due to network problems etc
        it('should show a warning if license is ' + consumer, function (done) {
            setEnvironment('superuser', consumer);

            assumePaidPluginsActivated();

            captureSelector(done, 'notification_plugincheck_' + consumer, function (page) {
                page.load('?module=UsersManager&action=index');
            }, '#notificationContainer');
        });
    });

});