OLD | NEW |
1 <!-- | 1 <!-- |
2 Copyright 2014 The Chromium Authors. All rights reserved. | 2 Copyright 2014 The Chromium Authors. All rights reserved. |
3 Use of this source code is governed by a BSD-style license that can be | 3 Use of this source code is governed by a BSD-style license that can be |
4 found in the LICENSE file. | 4 found in the LICENSE file. |
5 --> | 5 --> |
6 | 6 |
7 <link rel="import" href="../ct-failure-group.html"> | 7 <link rel="import" href="../ct-failure-group.html"> |
8 | 8 |
9 <script> | 9 <script> |
10 (function () { | 10 (function () { |
11 | 11 |
12 var assert = chai.assert; | 12 var assert = chai.assert; |
13 | 13 |
14 describe('ct-failure-group', function() { | 14 describe('ct-failure-group', function() { |
15 | 15 |
16 beforeEach(function() { | 16 beforeEach(function() { |
17 localStorage.removeItem('CTFailureGroupAnnotations'); | 17 localStorage.removeItem('CTFailureGroupAnnotations'); |
18 }); | 18 }); |
19 | 19 |
20 var key = 0; | 20 var key = 0; |
21 function newFailureWithAnnotation(annotation) { | 21 function newFailureWithAnnotation(annotation) { |
22 return new CTFailure('step', 'reason', [ | 22 return new CTFailure('step', 'reason', [ |
23 {key: String(key++), annotation: annotation} | 23 {key: String(key++), annotation: annotation} |
24 ]); | 24 ]); |
25 } | 25 } |
26 | 26 |
27 describe('category', function() { | 27 describe('category', function() { |
28 it('should be "default" by default', function() { | 28 it('should be "default" by default', function() { |
29 var group = new CTFailureGroup([], undefined); | 29 var group = new CTFailureGroup('', [], undefined); |
30 assert.equal(group.category, 'default'); | 30 assert.equal(group.category, 'default'); |
31 }); | 31 }); |
32 | 32 |
33 it('should be "snoozed" when snoozed', function() { | 33 it('should be "snoozed" when snoozed', function() { |
34 var group = new CTFailureGroup([newFailureWithAnnotation({snoozeTime: Date
.now() + 1000 * 1000})], undefined); | 34 var group = new CTFailureGroup('', [newFailureWithAnnotation({snoozeTime:
Date.now() + 1000 * 1000})], undefined); |
35 assert.equal(group.category, 'snoozed'); | 35 assert.equal(group.category, 'snoozed'); |
36 }); | 36 }); |
37 }); | 37 }); |
38 | 38 |
39 describe('snooze', function() { | 39 describe('snooze', function() { |
40 it('should set isSnoozed', function(done) { | 40 it('should set isSnoozed', function(done) { |
41 var group = new CTFailureGroup([newFailureWithAnnotation()], undefined); | 41 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); |
42 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { | 42 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { |
43 assert.isTrue(group.isSnoozed); | 43 assert.isTrue(group.isSnoozed); |
44 done(); | 44 done(); |
45 }); | 45 }); |
46 }); | 46 }); |
47 }); | 47 }); |
48 | 48 |
49 describe('unsnooze', function() { | 49 describe('unsnooze', function() { |
50 it('should clear isSnoozed', function(done) { | 50 it('should clear isSnoozed', function(done) { |
51 var group = new CTFailureGroup([newFailureWithAnnotation()], undefined); | 51 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); |
52 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { | 52 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { |
53 group.unsnooze().then(function() { | 53 group.unsnooze().then(function() { |
54 assert.isFalse(group.isSnoozed); | 54 assert.isFalse(group.isSnoozed); |
55 done(); | 55 done(); |
56 }); | 56 }); |
57 }); | 57 }); |
58 }); | 58 }); |
59 }); | 59 }); |
60 | 60 |
61 describe('setBug', function() { | 61 describe('setBug', function() { |
62 it('should store the bug', function(done) { | 62 it('should store the bug', function(done) { |
63 var group = new CTFailureGroup([newFailureWithAnnotation()], undefined); | 63 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); |
64 group.setBug('123').then(function() { | 64 group.setBug('123').then(function() { |
65 assert.equal(group.bug, 'http://crbug.com/123'); | 65 assert.equal(group.bug, 'http://crbug.com/123'); |
66 assert.equal(group._annotation.bug, 'http://crbug.com/123'); | 66 assert.equal(group._annotation.bug, 'http://crbug.com/123'); |
67 assert.equal(group.bugLabel, 'Bug 123'); | 67 assert.equal(group.bugLabel, 'Bug 123'); |
68 done(); | 68 done(); |
69 }); | 69 }); |
70 }); | 70 }); |
71 | 71 |
72 it('should support URLs', function(done) { | 72 it('should support URLs', function(done) { |
73 var group = new CTFailureGroup([newFailureWithAnnotation()], undefined); | 73 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); |
74 group.setBug('http://foobar.com/?id=876&x=y').then(function() { | 74 group.setBug('http://foobar.com/?id=876&x=y').then(function() { |
75 assert.equal(group.bug, 'http://foobar.com/?id=876&x=y'); | 75 assert.equal(group.bug, 'http://foobar.com/?id=876&x=y'); |
76 assert.equal(group._annotation.bug, 'http://foobar.com/?id=876&x=y'); | 76 assert.equal(group._annotation.bug, 'http://foobar.com/?id=876&x=y'); |
77 assert.equal(group.bugLabel, 'Bug 876'); | 77 assert.equal(group.bugLabel, 'Bug 876'); |
78 done(); | 78 done(); |
79 }); | 79 }); |
80 }); | 80 }); |
81 }); | 81 }); |
82 | 82 |
83 describe('clearBug', function() { | 83 describe('clearBug', function() { |
84 it('should work', function(done) { | 84 it('should work', function(done) { |
85 var group = new CTFailureGroup([], undefined); | 85 var group = new CTFailureGroup('', [], undefined); |
86 group.setBug('123').then(function() { | 86 group.setBug('123').then(function() { |
87 group.clearBug().then(function() { | 87 group.clearBug().then(function() { |
88 assert.isUndefined(group.bug); | 88 assert.isUndefined(group.bug); |
89 assert.isUndefined(group.bugLabel); | 89 assert.isUndefined(group.bugLabel); |
90 assert.notProperty(group._annotation, 'bug'); | 90 assert.notProperty(group._annotation, 'bug'); |
91 done(); | 91 done(); |
92 }); | 92 }); |
93 }); | 93 }); |
94 }); | 94 }); |
95 }); | 95 }); |
96 | 96 |
97 describe('annotations', function() { | 97 describe('annotations', function() { |
98 it('should have sensible defaults', function() { | 98 it('should have sensible defaults', function() { |
99 var group = new CTFailureGroup([], undefined); | 99 var group = new CTFailureGroup('', [], undefined); |
100 assert.deepEqual(group._annotation, {}); | 100 assert.deepEqual(group._annotation, {}); |
101 assert.isFalse(group.isSnoozed); | 101 assert.isFalse(group.isSnoozed); |
102 assert.isUndefined(group.bug); | 102 assert.isUndefined(group.bug); |
103 assert.isUndefined(group.bugLabel); | 103 assert.isUndefined(group.bugLabel); |
104 }); | 104 }); |
105 | 105 |
106 it('should compute properties', function() { | 106 it('should compute properties', function() { |
107 var group = new CTFailureGroup([newFailureWithAnnotation( | 107 var group = new CTFailureGroup('', [newFailureWithAnnotation( |
108 {snoozeTime: Date.now() + 1000 * 1000, bug: 'http://crbug.com/123'})],
undefined); | 108 {snoozeTime: Date.now() + 1000 * 1000, bug: 'http://crbug.com/123'})],
undefined); |
109 assert.isTrue(group.isSnoozed); | 109 assert.isTrue(group.isSnoozed); |
110 assert.equal(group.bug, 'http://crbug.com/123'); | 110 assert.equal(group.bug, 'http://crbug.com/123'); |
111 }); | 111 }); |
112 | 112 |
113 it('should ignore snoozeTime unless it is present on all alerts', function()
{ | 113 it('should ignore snoozeTime unless it is present on all alerts', function()
{ |
114 var notSnoozedMultipleAlerts = new CTFailureGroup([ | 114 var notSnoozedMultipleAlerts = new CTFailureGroup('', [ |
115 new CTFailure('step', 'reason', [ | 115 new CTFailure('step', 'reason', [ |
116 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 116 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
117 {key: 'b',}, | 117 {key: 'b',}, |
118 ], undefined) | 118 ], undefined) |
119 ]); | 119 ]); |
120 var notSnoozedMultipleFailures = new CTFailureGroup([ | 120 var notSnoozedMultipleFailures = new CTFailureGroup('', [ |
121 new CTFailure('step', 'reason', [ | 121 new CTFailure('step', 'reason', [ |
122 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 122 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
123 ]), | 123 ]), |
124 new CTFailure('step', 'reason', [ | 124 new CTFailure('step', 'reason', [ |
125 {key: 'b'}, | 125 {key: 'b'}, |
126 ]), | 126 ]), |
127 ], undefined); | 127 ], undefined); |
128 var snoozedMultipleAlerts = new CTFailureGroup([ | 128 var snoozedMultipleAlerts = new CTFailureGroup('', [ |
129 new CTFailure('step', 'reason', [ | 129 new CTFailure('step', 'reason', [ |
130 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 130 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
131 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 131 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
132 ]) | 132 ]) |
133 ], undefined); | 133 ], undefined); |
134 var snoozedMultipleFailures = new CTFailureGroup([ | 134 var snoozedMultipleFailures = new CTFailureGroup('', [ |
135 new CTFailure('step', 'reason', [ | 135 new CTFailure('step', 'reason', [ |
136 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 136 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
137 ]), | 137 ]), |
138 new CTFailure('step', 'reason', [ | 138 new CTFailure('step', 'reason', [ |
139 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 139 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
140 ]), | 140 ]), |
141 ], undefined); | 141 ], undefined); |
142 assert.isFalse(notSnoozedMultipleAlerts.isSnoozed); | 142 assert.isFalse(notSnoozedMultipleAlerts.isSnoozed); |
143 assert.isFalse(notSnoozedMultipleFailures.isSnoozed); | 143 assert.isFalse(notSnoozedMultipleFailures.isSnoozed); |
144 assert.isTrue(snoozedMultipleAlerts.isSnoozed); | 144 assert.isTrue(snoozedMultipleAlerts.isSnoozed); |
145 assert.isTrue(snoozedMultipleFailures.isSnoozed); | 145 assert.isTrue(snoozedMultipleFailures.isSnoozed); |
146 }); | 146 }); |
147 | 147 |
148 it('should use the earliest snoozeTime of all alerts', function() { | 148 it('should use the earliest snoozeTime of all alerts', function() { |
149 var timeFuture = Date.now() + 1000 * 1000; | 149 var timeFuture = Date.now() + 1000 * 1000; |
150 var timePast = Date.now() - 1000 * 1000; | 150 var timePast = Date.now() - 1000 * 1000; |
151 | 151 |
152 var notSnoozed = new CTFailureGroup([ | 152 var notSnoozed = new CTFailureGroup('', [ |
153 new CTFailure('step', 'reason', [ | 153 new CTFailure('step', 'reason', [ |
154 {key: 'a', annotation: {snoozeTime: timeFuture}}, | 154 {key: 'a', annotation: {snoozeTime: timeFuture}}, |
155 {key: 'b', annotation: {snoozeTime: timePast}}, | 155 {key: 'b', annotation: {snoozeTime: timePast}}, |
156 ]) | 156 ]) |
157 ], undefined); | 157 ], undefined); |
158 | 158 |
159 assert.isFalse(notSnoozed.isSnoozed); | 159 assert.isFalse(notSnoozed.isSnoozed); |
160 }); | 160 }); |
161 | 161 |
162 it('should be persisted', function(done) { | 162 it('should be persisted', function(done) { |
163 var group = new CTFailureGroup([newFailureWithAnnotation(), newFailureWith
Annotation()], undefined); | 163 var group = new CTFailureGroup('', [newFailureWithAnnotation(), newFailure
WithAnnotation()], undefined); |
164 group.snoozeUntil(123).then(function() { | 164 group.snoozeUntil(123).then(function() { |
165 group.setBug('456').then(function() { | 165 group.setBug('456').then(function() { |
166 CTFailureGroup.fetchAnnotations().then(function(annotations) { | 166 CTFailureGroup.fetchAnnotations().then(function(annotations) { |
167 assert.deepEqual(annotations[group.failures[0].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); | 167 assert.deepEqual(annotations[group.failures[0].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); |
168 assert.deepEqual(annotations[group.failures[1].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); | 168 assert.deepEqual(annotations[group.failures[1].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); |
169 done(); | 169 done(); |
170 }); | 170 }); |
171 }); | 171 }); |
172 }); | 172 }); |
173 }); | 173 }); |
174 }); | 174 }); |
175 }); | 175 }); |
176 | 176 |
177 })() | 177 })() |
178 </script> | 178 </script> |
OLD | NEW |