-
Notifications
You must be signed in to change notification settings - Fork 31
/
piwikProcessedReport_spec.js
327 lines (213 loc) · 10.3 KB
/
piwikProcessedReport_spec.js
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
/**
* Piwik - Open source web analytics
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html Gpl v3 or later
*/
(function () {
var Alloy = require('alloy');
function getFixtures()
{
return require('specs/fixtures/piwikProcessedReport');
}
function getSearchEngineReport()
{
return getFixtures().getSearchEngineReport();
}
function getSearchEngineEntry()
{
return getFixtures().getSearchEngineEntry();
}
function getVisitsOfDayByWeekEntry()
{
return getFixtures().getVisitsOfDayByWeekEntry();
}
function getReportWithDimensionHavingNoEntries()
{
return getFixtures().getReportWithDimensionHavingNoEntries();
}
function getReportWithDimensionHavingNoSubtableAndNoGraphs()
{
return getFixtures().getReportVisitsOfDayByWeek();
}
function getBrowserFamilyReport()
{
return getFixtures().getBrowserFamilyReport();
}
function getReportHavingNoDimension()
{
return getFixtures().getVisitsSummaryReport();
}
function loadFixture(collection, fixture)
{
collection.setSortOrder('nb_visits');
var parsedData = collection.parse(fixture, {});
collection.reset(parsedData, {});
}
describe('piwikProcessedReport Collection', function() {
var reportCollection = null;
beforeEach(function() {
reportCollection = Alloy.createCollection('piwikProcessedReport');
});
it('should not have a sort order by default', function() {
expect(reportCollection.getSortOrder()).toEqual(null);
});
it('should be able to set and get the sort order', function() {
reportCollection.setSortOrder('nb_visits');
expect(reportCollection.getSortOrder()).toEqual('nb_visits');
});
it('should return the correct number of available reports', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getNumberOfReports()).toEqual(5);
});
it('should return zero if the report has no data', function() {
loadFixture(reportCollection, getReportWithDimensionHavingNoEntries());
expect(reportCollection.getNumberOfReports()).toEqual(0);
});
it('should return the correct number of available reports when report has no dimension', function() {
loadFixture(reportCollection, getReportHavingNoDimension());
expect(reportCollection.getNumberOfReports()).toEqual(7);
});
it('should be able to recognize the report has reports if there are report data', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.hasReports()).toBeTruthy();
});
it('should be able to recognize the report has no reports if there is no report data', function() {
loadFixture(reportCollection, getReportWithDimensionHavingNoEntries());
expect(reportCollection.hasReports()).toBeFalsy();
});
it('should be able to recognize the report has reports if there are report data when report has no dimension', function() {
loadFixture(reportCollection, getReportHavingNoDimension());
expect(reportCollection.hasReports()).toBeTruthy();
});
it('should be able to recognize the report has sub tables', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.hasSubtable()).toBeTruthy();
});
it('should be able to recognize the report has no sub tables', function() {
loadFixture(reportCollection, getReportWithDimensionHavingNoSubtableAndNoGraphs());
expect(reportCollection.hasSubtable()).toBeFalsy();
});
it('should be able to return the action to load sub tables', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getActionToLoadSubTables()).toEqual('getKeywordsFromSearchEngineId');
});
it('should return null if the report has no action to load sub tables', function() {
loadFixture(reportCollection, getReportWithDimensionHavingNoSubtableAndNoGraphs());
expect(reportCollection.getActionToLoadSubTables()).toEqual(null);
});
it('should be able to return the module of the report', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getModule()).toEqual('Referers');
});
it('should be able to return the module of the report when report has no dimension', function() {
loadFixture(reportCollection, getReportHavingNoDimension());
expect(reportCollection.getModule()).toEqual('VisitsSummary');
});
it('should be able to return the name of the metric', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getMetricName()).toEqual('Visits');
});
it('should be able to return the name of the metric when report has no dimension', function() {
loadFixture(reportCollection, getReportHavingNoDimension());
expect(reportCollection.getMetricName()).toEqual('Visits');
});
it('should be able to return the report date', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getReportDate()).toEqual('Monday 1 July 2013');
});
it('should be able to return the name of the report', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getReportName()).toEqual('Search Engines');
});
it('should be able to return the static and evolution graph url', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getImageGraphUrl()).toEqual('index.php?module=API&method=ImageGraph.get&idSite=3&apiModule=Referers&apiAction=getSearchEngines&token_auth=anonymous&period=day&date=yesterday');
expect(reportCollection.getEvolutionImageGraphUrl()).toEqual('index.php?module=API&method=ImageGraph.get&idSite=3&apiModule=Referers&apiAction=getSearchEngines&token_auth=anonymous&period=day&date=2013-06-02,2013-07-01');
});
it('should return an empty string if there is no static or evolution graph url', function() {
loadFixture(reportCollection, getReportWithDimensionHavingNoSubtableAndNoGraphs());
expect(reportCollection.getImageGraphUrl()).toEqual('');
expect(reportCollection.getEvolutionImageGraphUrl()).toEqual('');
});
it('should return the metadata of the report', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getMetadata()).toEqual(getSearchEngineReport().metadata);
});
it('should return the metrics of the report', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.getMetrics()).toEqual(getSearchEngineReport().columns);
});
it('should be able to detect whether response is a valid response', function() {
expect(reportCollection.validResponse(getSearchEngineReport())).toBeTruthy();
expect(reportCollection.validResponse(null)).toBeFalsy();
});
it('should be able to detect whether the report has a dimension or not', function() {
loadFixture(reportCollection, getSearchEngineReport());
expect(reportCollection.hasDimension()).toBeTruthy();
loadFixture(reportCollection, getReportHavingNoDimension());
expect(reportCollection.hasDimension()).toBeFalsy();
});
});
describe('piwikProcessedReport Model', function() {
var searchEngineModel = null;
var visitsOfDayModel = null;
beforeEach(function() {
searchEngineModel = Alloy.createModel('piwikProcessedReport', getSearchEngineEntry());
visitsOfDayModel = Alloy.createModel('piwikProcessedReport', getVisitsOfDayByWeekEntry());
});
it('should return the title of a report entry', function() {
expect(searchEngineModel.getTitle()).toEqual('Google');
});
it('should return the value of a report entry', function() {
expect(searchEngineModel.getValue()).toEqual(16);
});
it('should return the sort order column of a report entry', function() {
expect(searchEngineModel.getSortOrder()).toEqual('nb_visits');
});
it('should be able to recognize a report entry has a logo', function() {
expect(searchEngineModel.hasLogo()).toBeTruthy();
expect(visitsOfDayModel.hasLogo()).toBeFalsy();
});
it('should return the path to the logo of a report entry', function() {
expect(searchEngineModel.getLogo()).toEqual('plugins\/Referers\/images\/searchEngines\/google.com.png');
expect(visitsOfDayModel.getLogo()).toBeNull();
});
it('should be able to detect the width and height of the logo', function() {
expect(searchEngineModel.getLogoWidth()).toEqual(14);
expect(searchEngineModel.getLogoHeight()).toEqual(16);
expect(visitsOfDayModel.getLogoWidth()).toBeNull();
expect(visitsOfDayModel.getLogoHeight()).toBeNull();
});
it('should return the id of the sub table', function() {
expect(searchEngineModel.getSubtableId()).toEqual(32);
expect(visitsOfDayModel.getSubtableId()).toBeNull();
});
});
describe('piwikProcessedReport CollectionToModel Interaction', function() {
var reportCollection = null;
beforeEach(function() {
reportCollection = Alloy.createCollection('piwikProcessedReport');
});
it('should not have a sort order by default', function() {
loadFixture(reportCollection, getSearchEngineReport());
var model = reportCollection.first();
expect(model.getTitle()).toEqual('Google');
expect(model.getValue()).toEqual(16);
expect(model.getSortOrder()).toEqual('nb_visits');
expect(model.hasLogo()).toBeTruthy();
expect(model.getLogo()).toEqual('plugins\/Referers\/images\/searchEngines\/google.com.png');
expect(model.getLogoWidth()).toBeNull();
expect(model.getLogoHeight()).toBeNull();
expect(model.getSubtableId()).toEqual(32);
});
it('should always prefer the short label of a report entry', function() {
loadFixture(reportCollection, getBrowserFamilyReport());
expect(reportCollection.first().getTitle()).toEqual('Webkit');
});
it('should convert an empty value to a hyphen', function() {
loadFixture(reportCollection, getBrowserFamilyReport());
expect(reportCollection.first().getValue()).toEqual('-');
});
});
})();