~ps-jenkins/cordova-ubuntu-tests/latestsnapshot-2.11+14.04.20131106-0ubuntu1

« back to all changes in this revision

Viewing changes to www/autotest/html/ReporterView.js

  • Committer: VĂ­ctor R. Ruiz
  • Date: 2013-07-25 13:09:34 UTC
  • Revision ID: victor.ruiz@canonical.com-20130725130934-d4q95mh8eehbv363
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
jasmine.HtmlReporter.ReporterView = function(dom) {
 
2
  this.startedAt = new Date();
 
3
  this.runningSpecCount = 0;
 
4
  this.completeSpecCount = 0;
 
5
  this.passedCount = 0;
 
6
  this.failedCount = 0;
 
7
  this.skippedCount = 0;
 
8
 
 
9
  this.createResultsMenu = function() {
 
10
    this.resultsMenu = this.createDom('span', {className: 'resultsMenu bar'},
 
11
      this.summaryMenuItem = this.createDom('a', {className: 'summaryMenuItem', href: "#"}, '0 specs'),
 
12
      ' | ',
 
13
      this.detailsMenuItem = this.createDom('a', {className: 'detailsMenuItem', href: "#"}, '0 failing'));
 
14
 
 
15
    this.summaryMenuItem.onclick = function() {
 
16
      dom.reporter.className = dom.reporter.className.replace(/ showDetails/g, '');
 
17
    };
 
18
 
 
19
    this.detailsMenuItem.onclick = function() {
 
20
      showDetails();
 
21
    };
 
22
  };
 
23
 
 
24
  this.addSpecs = function(specs, specFilter) {
 
25
    this.totalSpecCount = specs.length;
 
26
 
 
27
    this.views = {
 
28
      specs: {},
 
29
      suites: {}
 
30
    };
 
31
 
 
32
    for (var i = 0; i < specs.length; i++) {
 
33
      var spec = specs[i];
 
34
      this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom, this.views);
 
35
      if (specFilter(spec)) {
 
36
        this.runningSpecCount++;
 
37
      }
 
38
    }
 
39
  };
 
40
 
 
41
  this.specComplete = function(spec) {
 
42
    this.completeSpecCount++;
 
43
 
 
44
    if (isUndefined(this.views.specs[spec.id])) {
 
45
      this.views.specs[spec.id] = new jasmine.HtmlReporter.SpecView(spec, dom);
 
46
    }
 
47
 
 
48
    var specView = this.views.specs[spec.id];
 
49
 
 
50
    switch (specView.status()) {
 
51
      case 'passed':
 
52
        this.passedCount++;
 
53
        break;
 
54
 
 
55
      case 'failed':
 
56
        this.failedCount++;
 
57
        break;
 
58
 
 
59
      case 'skipped':
 
60
        this.skippedCount++;
 
61
        break;
 
62
    }
 
63
 
 
64
    specView.refresh();
 
65
    this.refresh();
 
66
  };
 
67
 
 
68
  this.suiteComplete = function(suite) {
 
69
    var suiteView = this.views.suites[suite.id];
 
70
    if (isUndefined(suiteView)) {
 
71
      return;
 
72
    }
 
73
    suiteView.refresh();
 
74
  };
 
75
 
 
76
  this.refresh = function() {
 
77
 
 
78
    if (isUndefined(this.resultsMenu)) {
 
79
      this.createResultsMenu();
 
80
    }
 
81
 
 
82
    // currently running UI
 
83
    if (isUndefined(this.runningAlert)) {
 
84
      this.runningAlert = this.createDom('a', {href: "?", className: "runningAlert bar"});
 
85
      dom.alert.appendChild(this.runningAlert);
 
86
    }
 
87
    this.runningAlert.innerHTML = "Running " + this.completeSpecCount + " of " + specPluralizedFor(this.totalSpecCount);
 
88
 
 
89
    // skipped specs UI
 
90
    if (isUndefined(this.skippedAlert)) {
 
91
      this.skippedAlert = this.createDom('a', {href: "?", className: "skippedAlert bar"});
 
92
    }
 
93
 
 
94
    this.skippedAlert.innerHTML = "Skipping " + this.skippedCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
 
95
 
 
96
    if (this.skippedCount === 1 && isDefined(dom.alert)) {
 
97
      dom.alert.appendChild(this.skippedAlert);
 
98
    }
 
99
 
 
100
    // passing specs UI
 
101
    if (isUndefined(this.passedAlert)) {
 
102
      this.passedAlert = this.createDom('span', {href: "?", className: "passingAlert bar"});
 
103
    }
 
104
    this.passedAlert.innerHTML = "Passing " + specPluralizedFor(this.passedCount);
 
105
 
 
106
    // failing specs UI
 
107
    if (isUndefined(this.failedAlert)) {
 
108
      this.failedAlert = this.createDom('span', {href: "?", className: "failingAlert bar"});
 
109
    }
 
110
    this.failedAlert.innerHTML = "Failing " + specPluralizedFor(this.failedCount);
 
111
 
 
112
    if (this.failedCount === 1 && isDefined(dom.alert)) {
 
113
      dom.alert.appendChild(this.failedAlert);
 
114
      dom.alert.appendChild(this.resultsMenu);
 
115
    }
 
116
 
 
117
    // summary info
 
118
    this.summaryMenuItem.innerHTML = "" + specPluralizedFor(this.runningSpecCount);
 
119
    this.detailsMenuItem.innerHTML = "" + this.failedCount + " failing";
 
120
  };
 
121
 
 
122
  this.complete = function() {
 
123
    dom.alert.removeChild(this.runningAlert);
 
124
 
 
125
    this.skippedAlert.innerHTML = "Ran " + this.runningSpecCount + " of " + specPluralizedFor(this.totalSpecCount) + " - run all";
 
126
 
 
127
    if (this.failedCount === 0) {
 
128
      dom.alert.appendChild(this.createDom('span', {className: 'passingAlert bar'}, "Passing " + specPluralizedFor(this.passedCount)));
 
129
    } else {
 
130
      showDetails();
 
131
    }
 
132
 
 
133
    dom.banner.appendChild(this.createDom('span', {className: 'duration'}, "finished in " + ((new Date().getTime() - this.startedAt.getTime()) / 1000) + "s"));
 
134
  };
 
135
 
 
136
  return this;
 
137
 
 
138
  function showDetails() {
 
139
    if (dom.reporter.className.search(/showDetails/) === -1) {
 
140
      dom.reporter.className += " showDetails";
 
141
    }
 
142
  }
 
143
 
 
144
  function isUndefined(obj) {
 
145
    return typeof obj === 'undefined';
 
146
  }
 
147
 
 
148
  function isDefined(obj) {
 
149
    return !isUndefined(obj);
 
150
  }
 
151
 
 
152
  function specPluralizedFor(count) {
 
153
    var str = count + " spec";
 
154
    if (count > 1) {
 
155
      str += "s"
 
156
    }
 
157
    return str;
 
158
  }
 
159
 
 
160
};
 
161
 
 
162
jasmine.HtmlReporterHelpers.addHelpers(jasmine.HtmlReporter.ReporterView);
 
163
 
 
164