Initial OpenECOMP SDC commit
[sdc.git] / catalog-fe / src / test / jasmine-standalone-2.0.0 / lib / jasmine-2.0.0 / jasmine-html.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 /*
22 Copyright (c) 2008-2013 Pivotal Labs
23
24 Permission is hereby granted, free of charge, to any person obtaining
25 a copy of this software and associated documentation files (the
26 "Software"), to deal in the Software without restriction, including
27 without limitation the rights to use, copy, modify, merge, publish,
28 distribute, sublicense, and/or sell copies of the Software, and to
29 permit persons to whom the Software is furnished to do so, subject to
30 the following conditions:
31
32 The above copyright notice and this permission notice shall be
33 included in all copies or substantial portions of the Software.
34
35 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
36 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
37 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
38 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
39 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
40 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
41 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 */
43 jasmineRequire.html = function(j$) {
44   j$.ResultsNode = jasmineRequire.ResultsNode();
45   j$.HtmlReporter = jasmineRequire.HtmlReporter(j$);
46   j$.QueryString = jasmineRequire.QueryString();
47   j$.HtmlSpecFilter = jasmineRequire.HtmlSpecFilter();
48 };
49
50 jasmineRequire.HtmlReporter = function(j$) {
51
52   var noopTimer = {
53     start: function() {},
54     elapsed: function() { return 0; }
55   };
56
57   function HtmlReporter(options) {
58     var env = options.env || {},
59       getContainer = options.getContainer,
60       createElement = options.createElement,
61       createTextNode = options.createTextNode,
62       onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {},
63       timer = options.timer || noopTimer,
64       results = [],
65       specsExecuted = 0,
66       failureCount = 0,
67       pendingSpecCount = 0,
68       htmlReporterMain,
69       symbols;
70
71     this.initialize = function() {
72       htmlReporterMain = createDom("div", {className: "html-reporter"},
73         createDom("div", {className: "banner"},
74           createDom("span", {className: "title"}, "Jasmine"),
75           createDom("span", {className: "version"}, j$.version)
76         ),
77         createDom("ul", {className: "symbol-summary"}),
78         createDom("div", {className: "alert"}),
79         createDom("div", {className: "results"},
80           createDom("div", {className: "failures"})
81         )
82       );
83       getContainer().appendChild(htmlReporterMain);
84
85       symbols = find(".symbol-summary");
86     };
87
88     var totalSpecsDefined;
89     this.jasmineStarted = function(options) {
90       totalSpecsDefined = options.totalSpecsDefined || 0;
91       timer.start();
92     };
93
94     var summary = createDom("div", {className: "summary"});
95
96     var topResults = new j$.ResultsNode({}, "", null),
97       currentParent = topResults;
98
99     this.suiteStarted = function(result) {
100       currentParent.addChild(result, "suite");
101       currentParent = currentParent.last();
102     };
103
104     this.suiteDone = function(result) {
105       if (currentParent == topResults) {
106         return;
107       }
108
109       currentParent = currentParent.parent;
110     };
111
112     this.specStarted = function(result) {
113       currentParent.addChild(result, "spec");
114     };
115
116     var failures = [];
117     this.specDone = function(result) {
118       if (result.status != "disabled") {
119         specsExecuted++;
120       }
121
122       symbols.appendChild(createDom("li", {
123           className: result.status,
124           id: "spec_" + result.id,
125           title: result.fullName
126         }
127       ));
128
129       if (result.status == "failed") {
130         failureCount++;
131
132         var failure =
133           createDom("div", {className: "spec-detail failed"},
134             createDom("div", {className: "description"},
135               createDom("a", {title: result.fullName, href: specHref(result)}, result.fullName)
136             ),
137             createDom("div", {className: "messages"})
138           );
139         var messages = failure.childNodes[1];
140
141         for (var i = 0; i < result.failedExpectations.length; i++) {
142           var expectation = result.failedExpectations[i];
143           messages.appendChild(createDom("div", {className: "result-message"}, expectation.message));
144           messages.appendChild(createDom("div", {className: "stack-trace"}, expectation.stack));
145         }
146
147         failures.push(failure);
148       }
149
150       if (result.status == "pending") {
151         pendingSpecCount++;
152       }
153     };
154
155     this.jasmineDone = function() {
156       var banner = find(".banner");
157       banner.appendChild(createDom("span", {className: "duration"}, "finished in " + timer.elapsed() / 1000 + "s"));
158
159       var alert = find(".alert");
160
161       alert.appendChild(createDom("span", { className: "exceptions" },
162         createDom("label", { className: "label", 'for': "raise-exceptions" }, "raise exceptions"),
163         createDom("input", {
164           className: "raise",
165           id: "raise-exceptions",
166           type: "checkbox"
167         })
168       ));
169       var checkbox = find("input");
170
171       checkbox.checked = !env.catchingExceptions();
172       checkbox.onclick = onRaiseExceptionsClick;
173
174       if (specsExecuted < totalSpecsDefined) {
175         var skippedMessage = "Ran " + specsExecuted + " of " + totalSpecsDefined + " specs - run all";
176         alert.appendChild(
177           createDom("span", {className: "bar skipped"},
178             createDom("a", {href: "?", title: "Run all specs"}, skippedMessage)
179           )
180         );
181       }
182       var statusBarMessage = "" + pluralize("spec", specsExecuted) + ", " + pluralize("failure", failureCount);
183       if (pendingSpecCount) { statusBarMessage += ", " + pluralize("pending spec", pendingSpecCount); }
184
185       var statusBarClassName = "bar " + ((failureCount > 0) ? "failed" : "passed");
186       alert.appendChild(createDom("span", {className: statusBarClassName}, statusBarMessage));
187
188       var results = find(".results");
189       results.appendChild(summary);
190
191       summaryList(topResults, summary);
192
193       function summaryList(resultsTree, domParent) {
194         var specListNode;
195         for (var i = 0; i < resultsTree.children.length; i++) {
196           var resultNode = resultsTree.children[i];
197           if (resultNode.type == "suite") {
198             var suiteListNode = createDom("ul", {className: "suite", id: "suite-" + resultNode.result.id},
199               createDom("li", {className: "suite-detail"},
200                 createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
201               )
202             );
203
204             summaryList(resultNode, suiteListNode);
205             domParent.appendChild(suiteListNode);
206           }
207           if (resultNode.type == "spec") {
208             if (domParent.getAttribute("class") != "specs") {
209               specListNode = createDom("ul", {className: "specs"});
210               domParent.appendChild(specListNode);
211             }
212             specListNode.appendChild(
213               createDom("li", {
214                   className: resultNode.result.status,
215                   id: "spec-" + resultNode.result.id
216                 },
217                 createDom("a", {href: specHref(resultNode.result)}, resultNode.result.description)
218               )
219             );
220           }
221         }
222       }
223
224       if (failures.length) {
225         alert.appendChild(
226           createDom('span', {className: "menu bar spec-list"},
227             createDom("span", {}, "Spec List | "),
228             createDom('a', {className: "failures-menu", href: "#"}, "Failures")));
229         alert.appendChild(
230           createDom('span', {className: "menu bar failure-list"},
231             createDom('a', {className: "spec-list-menu", href: "#"}, "Spec List"),
232             createDom("span", {}, " | Failures ")));
233
234         find(".failures-menu").onclick = function() {
235           setMenuModeTo('failure-list');
236         };
237         find(".spec-list-menu").onclick = function() {
238           setMenuModeTo('spec-list');
239         };
240
241         setMenuModeTo('failure-list');
242
243         var failureNode = find(".failures");
244         for (var i = 0; i < failures.length; i++) {
245           failureNode.appendChild(failures[i]);
246         }
247       }
248     };
249
250     return this;
251
252     function find(selector) {
253       return getContainer().querySelector(selector);
254     }
255
256     function createDom(type, attrs, childrenVarArgs) {
257       var el = createElement(type);
258
259       for (var i = 2; i < arguments.length; i++) {
260         var child = arguments[i];
261
262         if (typeof child === 'string') {
263           el.appendChild(createTextNode(child));
264         } else {
265           if (child) {
266             el.appendChild(child);
267           }
268         }
269       }
270
271       for (var attr in attrs) {
272         if (attr == "className") {
273           el[attr] = attrs[attr];
274         } else {
275           el.setAttribute(attr, attrs[attr]);
276         }
277       }
278
279       return el;
280     }
281
282     function pluralize(singular, count) {
283       var word = (count == 1 ? singular : singular + "s");
284
285       return "" + count + " " + word;
286     }
287
288     function specHref(result) {
289       return "?spec=" + encodeURIComponent(result.fullName);
290     }
291
292     function setMenuModeTo(mode) {
293       htmlReporterMain.setAttribute("class", "html-reporter " + mode);
294     }
295   }
296
297   return HtmlReporter;
298 };
299
300 jasmineRequire.HtmlSpecFilter = function() {
301   function HtmlSpecFilter(options) {
302     var filterString = options && options.filterString() && options.filterString().replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
303     var filterPattern = new RegExp(filterString);
304
305     this.matches = function(specName) {
306       return filterPattern.test(specName);
307     };
308   }
309
310   return HtmlSpecFilter;
311 };
312
313 jasmineRequire.ResultsNode = function() {
314   function ResultsNode(result, type, parent) {
315     this.result = result;
316     this.type = type;
317     this.parent = parent;
318
319     this.children = [];
320
321     this.addChild = function(result, type) {
322       this.children.push(new ResultsNode(result, type, this));
323     };
324
325     this.last = function() {
326       return this.children[this.children.length - 1];
327     };
328   }
329
330   return ResultsNode;
331 };
332
333 jasmineRequire.QueryString = function() {
334   function QueryString(options) {
335
336     this.setParam = function(key, value) {
337       var paramMap = queryStringToParamMap();
338       paramMap[key] = value;
339       options.getWindowLocation().search = toQueryString(paramMap);
340     };
341
342     this.getParam = function(key) {
343       return queryStringToParamMap()[key];
344     };
345
346     return this;
347
348     function toQueryString(paramMap) {
349       var qStrPairs = [];
350       for (var prop in paramMap) {
351         qStrPairs.push(encodeURIComponent(prop) + "=" + encodeURIComponent(paramMap[prop]));
352       }
353       return "?" + qStrPairs.join('&');
354     }
355
356     function queryStringToParamMap() {
357       var paramStr = options.getWindowLocation().search.substring(1),
358         params = [],
359         paramMap = {};
360
361       if (paramStr.length > 0) {
362         params = paramStr.split('&');
363         for (var i = 0; i < params.length; i++) {
364           var p = params[i].split('=');
365           var value = decodeURIComponent(p[1]);
366           if (value === "true" || value === "false") {
367             value = JSON.parse(value);
368           }
369           paramMap[decodeURIComponent(p[0])] = value;
370         }
371       }
372
373       return paramMap;
374     }
375
376   }
377
378   return QueryString;
379 };