PageRenderTime 31ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/prueba_app/www/spec/lib/jasmine-1.2.0/jasmine-html.js

https://gitlab.com/JuniorMeza/Pruebadeapp
JavaScript | 616 lines | 484 code | 123 blank | 9 comment | 94 complexity | 4b49962a205889352a4f1d63d5acf7a0 MD5 | raw file
  1. jasmine.HtmlReporterHelpers = {};
  2. jasmine.HtmlReporterHelpers.createDom = function(type, attrs, childrenVarArgs) {
  3. var el = document.createElement(type);
  4. for (var i = 2; i < arguments.length; i++) {
  5. var child = arguments[i];
  6. if (typeof child === 'string') {
  7. el.appendChild(document.createTextNode(child));
  8. } else {
  9. if (child) {
  10. el.appendChild(child);
  11. }
  12. }
  13. }
  14. for (var attr in attrs) {
  15. if (attr == "className") {
  16. el[attr] = attrs[attr];
  17. } else {
  18. el.setAttribute(attr, attrs[attr]);
  19. }
  20. }
  21. return el;
  22. };
  23. jasmine.HtmlReporterHelpers.getSpecStatus = function(child) {
  24. var results = child.results();
  25. var status = results.passed() ? 'passed' : 'failed';
  26. if (results.skipped) {
  27. status = 'skipped';
  28. }
  29. return status;
  30. };
  31. jasmine.HtmlReporterHelpers.appendToSummary = function(child, childElement) {
  32. var parentDiv = this.dom.summary;
  33. var parentSuite = (typeof child.parentSuite == 'undefined') ? 'suite' : 'parentSuite';
  34. var parent = child[parentSuite];
  35. if (parent) {
  36. if (typeof this.views.suites[parent.id] == 'undefined') {
  37. this.views.suites[parent.id] = new jasmine.HtmlReporter.SuiteView(parent, this.dom, this.views);
  38. }
  39. parentDiv = this.views.suites[parent.id].element;
  40. }
  41. parentDiv.appendChild(childElement);
  42. };
  43. jasmine.HtmlReporterHelpers.addHelpers = function(ctor) {
  44. for(var fn in jasmine.HtmlReporterHelpers) {
  45. ctor.prototype[fn] = jasmine.HtmlReporterHelpers[fn];
  46. }
  47. };
  48. jasmine.HtmlReporter = function(_doc) {
  49. var self = this;
  50. var doc = _doc || window.document;
  51. var reporterView;
  52. var dom = {};
  53. // Jasmine Reporter Public Interface
  54. self.logRunningSpecs = false;
  55. self.reportRunnerStarting = function(runner) {
  56. var specs = runner.specs() || [];
  57. if (specs.length == 0) {
  58. return;
  59. }
  60. createReporterDom(runner.env.versionString());
  61. doc.body.appendChild(dom.reporter);
  62. reporterView = new jasmine.HtmlReporter.ReporterView(dom);
  63. reporterView.addSpecs(specs, self.specFilter);
  64. };
  65. self.reportRunnerResults = function(runner) {
  66. reporterView && reporterView.complete();
  67. };
  68. self.reportSuiteResults = function(suite) {
  69. reporterView.suiteComplete(suite);
  70. };
  71. self.reportSpecStarting = function(spec) {
  72. if (self.logRunningSpecs) {
  73. self.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
  74. }
  75. };
  76. self.reportSpecResults = function(spec) {
  77. reporterView.specComplete(spec);
  78. };
  79. self.log = function() {
  80. var console = jasmine.getGlobal().console;
  81. if (console && console.log) {
  82. if (console.log.apply) {
  83. console.log.apply(console, arguments);
  84. } else {
  85. console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
  86. }
  87. }
  88. };
  89. self.specFilter = function(spec) {
  90. if (!focusedSpecName()) {
  91. return true;
  92. }
  93. return spec.getFullName().indexOf(focusedSpecName()) === 0;
  94. };
  95. return self;
  96. function focusedSpecName() {
  97. var specName;
  98. (function memoizeFocusedSpec() {
  99. if (specName) {
  100. return;
  101. }
  102. var paramMap = [];
  103. var params = doc.location.search.substring(1).split('&');
  104. for (var i = 0; i < params.length; i++) {
  105. var p = params[i].split('=');
  106. paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
  107. }
  108. specName = paramMap.spec;
  109. })();
  110. return specName;
  111. }
  112. function createReporterDom(version) {
  113. dom.reporter = self.createDom('div', { id: 'HTMLReporter', className: 'jasmine_reporter' },
  114. dom.banner = self.createDom('div', { className: 'banner' },
  115. self.createDom('span', { className: 'title' }, "Jasmine "),
  116. self.createDom('span', { className: 'version' }, version)),
  117. dom.symbolSummary = self.createDom('ul', {className: 'symbolSummary'}),
  118. dom.alert = self.createDom('div', {className: 'alert'}),
  119. dom.results = self.createDom('div', {className: 'results'},
  120. dom.summary = self.createDom('div', { className: 'summary' }),
  121. dom.details = self.createDom('div', { id: 'details' }))
  122. );
  123. }
  124. };
  125. jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter);jasmine.HtmlReporter.ReporterView = function(dom) {
  126. this.startedAt = new Date();
  127. this.runningSpecCount = 0;
  128. this.completeSpecCount = 0;
  129. this.passedCount = 0;
  130. this.failedCount = 0;
  131. this.skippedCount = 0;
  132. this.createResultsMenu = function() {
  133. this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
  134. this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
  135. ' | ',
  136. this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
  137. this.summaryMenuItem.onclick = function() {
  138. dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
  139. };
  140. this.detailsMenuItem.onclick = function() {
  141. showDetails();
  142. };
  143. };
  144. this.addSpecs = function(specs, specFilter) {
  145. this.totalSpecCount = specs.length;
  146. this.views = {
  147. specs: {},
  148. suites: {}
  149. };
  150. for (var i = 0; i < specs.length; i++) {
  151. var spec = specs[i];
  152. this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
  153. if (specFilter(spec)) {
  154. this.runningSpecCount++;
  155. }
  156. }
  157. };
  158. this.specComplete = function(spec) {
  159. this.completeSpecCount++;
  160. if (isUndefined(this.views.specs[spec.id])) {
  161. this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
  162. }
  163. var specView = this.views.specs[spec.id];
  164. switch (specView.status()) {
  165. case 'passed':
  166. this.passedCount++;
  167. break;
  168. case 'failed':
  169. this.failedCount++;
  170. break;
  171. case 'skipped':
  172. this.skippedCount++;
  173. break;
  174. }
  175. specView.refresh();
  176. this.refresh();
  177. };
  178. this.suiteComplete = function(suite) {
  179. var suiteView = this.views.suites[suite.id];
  180. if (isUndefined(suiteView)) {
  181. return;
  182. }
  183. suiteView.refresh();
  184. };
  185. this.refresh = function() {
  186. if (isUndefined(this.resultsMenu)) {
  187. this.createResultsMenu();
  188. }
  189. // currently running UI
  190. if (isUndefined(this.runningAlert)) {
  191. this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
  192. dom.alert.appendChild(this.runningAlert);
  193. }
  194. this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
  195. // skipped specs UI
  196. if (isUndefined(this.skippedAlert)) {
  197. this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
  198. }
  199. this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
  200. if (this.skippedCount === 1 && isDefined(dom.alert)) {
  201. dom.alert.appendChild(this.skippedAlert);
  202. }
  203. // passing specs UI
  204. if (isUndefined(this.passedAlert)) {
  205. this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
  206. }
  207. this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
  208. // failing specs UI
  209. if (isUndefined(this.failedAlert)) {
  210. this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
  211. }
  212. this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
  213. if (this.failedCount === 1 && isDefined(dom.alert)) {
  214. dom.alert.appendChild(this.failedAlert);
  215. dom.alert.appendChild(this.resultsMenu);
  216. }
  217. // summary info
  218. this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
  219. this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
  220. };
  221. this.complete = function() {
  222. dom.alert.removeChild(this.runningAlert);
  223. this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
  224. if (this.failedCount === 0) {
  225. dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
  226. } else {
  227. showDetails();
  228. }
  229. dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
  230. };
  231. return this;
  232. function showDetails() {
  233. if (dom.reporter.className.search(/showDetails/) === -1) {
  234. dom.reporter.className += " showDetails";
  235. }
  236. }
  237. function isUndefined(obj) {
  238. return typeof obj === 'undefined';
  239. }
  240. function isDefined(obj) {
  241. return !isUndefined(obj);
  242. }
  243. function specPluralizedFor(count) {
  244. var str = count + " spec";
  245. if (count > 1) {
  246. str += "s"
  247. }
  248. return str;
  249. }
  250. };
  251. jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
  252. jasmine.HtmlReporter.SpecView = function(spec, dom, views) {
  253. this.spec = spec;
  254. this.dom = dom;
  255. this.views = views;
  256. this.symbol = this.createDom('li', { className: 'pending' });
  257. this.dom.symbolSummary.appendChild(this.symbol);
  258. this.summary = this.createDom('div', { className: 'specSummary' },
  259. this.createDom('a', {
  260. className: 'description',
  261. href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
  262. title: this.spec.getFullName()
  263. }, this.spec.description)
  264. );
  265. this.detail = this.createDom('div', { className: 'specDetail' },
  266. this.createDom('a', {
  267. className: 'description',
  268. href: '?spec=' + encodeURIComponent(this.spec.getFullName()),
  269. title: this.spec.getFullName()
  270. }, this.spec.getFullName())
  271. );
  272. };
  273. jasmine.HtmlReporter.SpecView.prototype.status = function() {
  274. return this.getSpecStatus(this.spec);
  275. };
  276. jasmine.HtmlReporter.SpecView.prototype.refresh = function() {
  277. this.symbol.className = this.status();
  278. switch (this.status()) {
  279. case 'skipped':
  280. break;
  281. case 'passed':
  282. this.appendSummaryToSuiteDiv();
  283. break;
  284. case 'failed':
  285. this.appendSummaryToSuiteDiv();
  286. this.appendFailureDetail();
  287. break;
  288. }
  289. };
  290. jasmine.HtmlReporter.SpecView.prototype.appendSummaryToSuiteDiv = function() {
  291. this.summary.className += ' ' + this.status();
  292. this.appendToSummary(this.spec, this.summary);
  293. };
  294. jasmine.HtmlReporter.SpecView.prototype.appendFailureDetail = function() {
  295. this.detail.className += ' ' + this.status();
  296. var resultItems = this.spec.results().getItems();
  297. var messagesDiv = this.createDom('div', { className: 'messages' });
  298. for (var i = 0; i < resultItems.length; i++) {
  299. var result = resultItems[i];
  300. if (result.type == 'log') {
  301. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
  302. } else if (result.type == 'expect' && result.passed && !result.passed()) {
  303. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
  304. if (result.trace.stack) {
  305. messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
  306. }
  307. }
  308. }
  309. if (messagesDiv.childNodes.length > 0) {
  310. this.detail.appendChild(messagesDiv);
  311. this.dom.details.appendChild(this.detail);
  312. }
  313. };
  314. jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SpecView);jasmine.HtmlReporter.SuiteView = function(suite, dom, views) {
  315. this.suite = suite;
  316. this.dom = dom;
  317. this.views = views;
  318. this.element = this.createDom('div', { className: 'suite' },
  319. this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(this.suite.getFullName()) }, this.suite.description)
  320. );
  321. this.appendToSummary(this.suite, this.element);
  322. };
  323. jasmine.HtmlReporter.SuiteView.prototype.status = function() {
  324. return this.getSpecStatus(this.suite);
  325. };
  326. jasmine.HtmlReporter.SuiteView.prototype.refresh = function() {
  327. this.element.className += " " + this.status();
  328. };
  329. jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.SuiteView);
  330. /* @deprecated Use jasmine.HtmlReporter instead
  331. */
  332. jasmine.TrivialReporter = function(doc) {
  333. this.document = doc || document;
  334. this.suiteDivs = {};
  335. this.logRunningSpecs = false;
  336. };
  337. jasmine.TrivialReporter.prototype.createDom = function(type, attrs, childrenVarArgs) {
  338. var el = document.createElement(type);
  339. for (var i = 2; i < arguments.length; i++) {
  340. var child = arguments[i];
  341. if (typeof child === 'string') {
  342. el.appendChild(document.createTextNode(child));
  343. } else {
  344. if (child) { el.appendChild(child); }
  345. }
  346. }
  347. for (var attr in attrs) {
  348. if (attr == "className") {
  349. el[attr] = attrs[attr];
  350. } else {
  351. el.setAttribute(attr, attrs[attr]);
  352. }
  353. }
  354. return el;
  355. };
  356. jasmine.TrivialReporter.prototype.reportRunnerStarting = function(runner) {
  357. var showPassed, showSkipped;
  358. this.outerDiv = this.createDom('div', { id: 'TrivialReporter', className: 'jasmine_reporter' },
  359. this.createDom('div', { className: 'banner' },
  360. this.createDom('div', { className: 'logo' },
  361. this.createDom('span', { className: 'title' }, "Jasmine"),
  362. this.createDom('span', { className: 'version' }, runner.env.versionString())),
  363. this.createDom('div', { className: 'options' },
  364. "Show ",
  365. showPassed = this.createDom('input', { id: "__jasmine_TrivialReporter_showPassed__", type: 'checkbox' }),
  366. this.createDom('label', { "for": "__jasmine_TrivialReporter_showPassed__" }, " passed "),
  367. showSkipped = this.createDom('input', { id: "__jasmine_TrivialReporter_showSkipped__", type: 'checkbox' }),
  368. this.createDom('label', { "for": "__jasmine_TrivialReporter_showSkipped__" }, " skipped")
  369. )
  370. ),
  371. this.runnerDiv = this.createDom('div', { className: 'runner running' },
  372. this.createDom('a', { className: 'run_spec', href: '?' }, "run all"),
  373. this.runnerMessageSpan = this.createDom('span', {}, "Running..."),
  374. this.finishedAtSpan = this.createDom('span', { className: 'finished-at' }, ""))
  375. );
  376. this.document.body.appendChild(this.outerDiv);
  377. var suites = runner.suites();
  378. for (var i = 0; i < suites.length; i++) {
  379. var suite = suites[i];
  380. var suiteDiv = this.createDom('div', { className: 'suite' },
  381. this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, "run"),
  382. this.createDom('a', { className: 'description', href: '?spec=' + encodeURIComponent(suite.getFullName()) }, suite.description));
  383. this.suiteDivs[suite.id] = suiteDiv;
  384. var parentDiv = this.outerDiv;
  385. if (suite.parentSuite) {
  386. parentDiv = this.suiteDivs[suite.parentSuite.id];
  387. }
  388. parentDiv.appendChild(suiteDiv);
  389. }
  390. this.startedAt = new Date();
  391. var self = this;
  392. showPassed.onclick = function(evt) {
  393. if (showPassed.checked) {
  394. self.outerDiv.className += ' show-passed';
  395. } else {
  396. self.outerDiv.className = self.outerDiv.className.replace(/ show-passed/, '');
  397. }
  398. };
  399. showSkipped.onclick = function(evt) {
  400. if (showSkipped.checked) {
  401. self.outerDiv.className += ' show-skipped';
  402. } else {
  403. self.outerDiv.className = self.outerDiv.className.replace(/ show-skipped/, '');
  404. }
  405. };
  406. };
  407. jasmine.TrivialReporter.prototype.reportRunnerResults = function(runner) {
  408. var results = runner.results();
  409. var className = (results.failedCount > 0) ? "runner failed" : "runner passed";
  410. this.runnerDiv.setAttribute("class", className);
  411. //do it twice for IE
  412. this.runnerDiv.setAttribute("className", className);
  413. var specs = runner.specs();
  414. var specCount = 0;
  415. for (var i = 0; i < specs.length; i++) {
  416. if (this.specFilter(specs[i])) {
  417. specCount++;
  418. }
  419. }
  420. var message = "" + specCount + " spec" + (specCount == 1 ? "" : "s" ) + ", " + results.failedCount + " failure" + ((results.failedCount == 1) ? "" : "s");
  421. message += " in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s";
  422. this.runnerMessageSpan.replaceChild(this.createDom('a', { className: 'description', href: '?'}, message), this.runnerMessageSpan.firstChild);
  423. this.finishedAtSpan.appendChild(document.createTextNode("Finished at " + new Date().toString()));
  424. };
  425. jasmine.TrivialReporter.prototype.reportSuiteResults = function(suite) {
  426. var results = suite.results();
  427. var status = results.passed() ? 'passed' : 'failed';
  428. if (results.totalCount === 0) { // todo: change this to check results.skipped
  429. status = 'skipped';
  430. }
  431. this.suiteDivs[suite.id].className += " " + status;
  432. };
  433. jasmine.TrivialReporter.prototype.reportSpecStarting = function(spec) {
  434. if (this.logRunningSpecs) {
  435. this.log('>> Jasmine Running ' + spec.suite.description + ' ' + spec.description + '...');
  436. }
  437. };
  438. jasmine.TrivialReporter.prototype.reportSpecResults = function(spec) {
  439. var results = spec.results();
  440. var status = results.passed() ? 'passed' : 'failed';
  441. if (results.skipped) {
  442. status = 'skipped';
  443. }
  444. var specDiv = this.createDom('div', { className: 'spec ' + status },
  445. this.createDom('a', { className: 'run_spec', href: '?spec=' + encodeURIComponent(spec.getFullName()) }, "run"),
  446. this.createDom('a', {
  447. className: 'description',
  448. href: '?spec=' + encodeURIComponent(spec.getFullName()),
  449. title: spec.getFullName()
  450. }, spec.description));
  451. var resultItems = results.getItems();
  452. var messagesDiv = this.createDom('div', { className: 'messages' });
  453. for (var i = 0; i < resultItems.length; i++) {
  454. var result = resultItems[i];
  455. if (result.type == 'log') {
  456. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage log'}, result.toString()));
  457. } else if (result.type == 'expect' && result.passed && !result.passed()) {
  458. messagesDiv.appendChild(this.createDom('div', {className: 'resultMessage fail'}, result.message));
  459. if (result.trace.stack) {
  460. messagesDiv.appendChild(this.createDom('div', {className: 'stackTrace'}, result.trace.stack));
  461. }
  462. }
  463. }
  464. if (messagesDiv.childNodes.length > 0) {
  465. specDiv.appendChild(messagesDiv);
  466. }
  467. this.suiteDivs[spec.suite.id].appendChild(specDiv);
  468. };
  469. jasmine.TrivialReporter.prototype.log = function() {
  470. var console = jasmine.getGlobal().console;
  471. if (console && console.log) {
  472. if (console.log.apply) {
  473. console.log.apply(console, arguments);
  474. } else {
  475. console.log(arguments); // ie fix: console.log.apply doesn't exist on ie
  476. }
  477. }
  478. };
  479. jasmine.TrivialReporter.prototype.getLocation = function() {
  480. return this.document.location;
  481. };
  482. jasmine.TrivialReporter.prototype.specFilter = function(spec) {
  483. var paramMap = {};
  484. var params = this.getLocation().search.substring(1).split('&');
  485. for (var i = 0; i < params.length; i++) {
  486. var p = params[i].split('=');
  487. paramMap[decodeURIComponent(p[0])] = decodeURIComponent(p[1]);
  488. }
  489. if (!paramMap.spec) {
  490. return true;
  491. }
  492. return spec.getFullName().indexOf(paramMap.spec) === 0;
  493. };