| 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('', new CTSheriffFailureGroupData([])); |
| 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('', new CTSheriffFailureGroupData( |
| 35 [newFailureWithAnnotation({snoozeTime: Date.now() + 1000 * 1000})])); |
| 35 assert.equal(group.category, 'snoozed'); | 36 assert.equal(group.category, 'snoozed'); |
| 36 }); | 37 }); |
| 37 }); | 38 }); |
| 38 | 39 |
| 39 describe('snooze', function() { | 40 describe('snooze', function() { |
| 40 it('should set isSnoozed', function(done) { | 41 it('should set isSnoozed', function(done) { |
| 41 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); | 42 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([newFailu
reWithAnnotation()])); |
| 42 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { | 43 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { |
| 43 assert.isTrue(group.isSnoozed); | 44 assert.isTrue(group.isSnoozed); |
| 44 done(); | 45 done(); |
| 45 }); | 46 }); |
| 46 }); | 47 }); |
| 47 }); | 48 }); |
| 48 | 49 |
| 49 describe('unsnooze', function() { | 50 describe('unsnooze', function() { |
| 50 it('should clear isSnoozed', function(done) { | 51 it('should clear isSnoozed', function(done) { |
| 51 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); | 52 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([newFailu
reWithAnnotation()])); |
| 52 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { | 53 group.snoozeUntil(Date.now() + 1000 * 1000).then(function() { |
| 53 group.unsnooze().then(function() { | 54 group.unsnooze().then(function() { |
| 54 assert.isFalse(group.isSnoozed); | 55 assert.isFalse(group.isSnoozed); |
| 55 done(); | 56 done(); |
| 56 }); | 57 }); |
| 57 }); | 58 }); |
| 58 }); | 59 }); |
| 59 }); | 60 }); |
| 60 | 61 |
| 61 describe('setBug', function() { | 62 describe('setBug', function() { |
| 62 it('should store the bug', function(done) { | 63 it('should store the bug', function(done) { |
| 63 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); | 64 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([newFailu
reWithAnnotation()])); |
| 64 group.setBug('123').then(function() { | 65 group.setBug('123').then(function() { |
| 65 assert.equal(group.bug, 'http://crbug.com/123'); | 66 assert.equal(group.bug, 'http://crbug.com/123'); |
| 66 assert.equal(group._annotation.bug, 'http://crbug.com/123'); | 67 assert.equal(group._annotation.bug, 'http://crbug.com/123'); |
| 67 assert.equal(group.bugLabel, 'Bug 123'); | 68 assert.equal(group.bugLabel, 'Bug 123'); |
| 68 done(); | 69 done(); |
| 69 }); | 70 }); |
| 70 }); | 71 }); |
| 71 | 72 |
| 72 it('should support URLs', function(done) { | 73 it('should support URLs', function(done) { |
| 73 var group = new CTFailureGroup('', [newFailureWithAnnotation()], undefined
); | 74 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([newFailu
reWithAnnotation()])); |
| 74 group.setBug('http://foobar.com/?id=876&x=y').then(function() { | 75 group.setBug('http://foobar.com/?id=876&x=y').then(function() { |
| 75 assert.equal(group.bug, 'http://foobar.com/?id=876&x=y'); | 76 assert.equal(group.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._annotation.bug, 'http://foobar.com/?id=876&x=y'); |
| 77 assert.equal(group.bugLabel, 'Bug 876'); | 78 assert.equal(group.bugLabel, 'Bug 876'); |
| 78 done(); | 79 done(); |
| 79 }); | 80 }); |
| 80 }); | 81 }); |
| 81 }); | 82 }); |
| 82 | 83 |
| 83 describe('clearBug', function() { | 84 describe('clearBug', function() { |
| 84 it('should work', function(done) { | 85 it('should work', function(done) { |
| 85 var group = new CTFailureGroup('', [], undefined); | 86 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([])); |
| 86 group.setBug('123').then(function() { | 87 group.setBug('123').then(function() { |
| 87 group.clearBug().then(function() { | 88 group.clearBug().then(function() { |
| 88 assert.isUndefined(group.bug); | 89 assert.isUndefined(group.bug); |
| 89 assert.isUndefined(group.bugLabel); | 90 assert.isUndefined(group.bugLabel); |
| 90 assert.notProperty(group._annotation, 'bug'); | 91 assert.notProperty(group._annotation, 'bug'); |
| 91 done(); | 92 done(); |
| 92 }); | 93 }); |
| 93 }); | 94 }); |
| 94 }); | 95 }); |
| 95 }); | 96 }); |
| 96 | 97 |
| 97 describe('annotations', function() { | 98 describe('annotations', function() { |
| 98 it('should have sensible defaults', function() { | 99 it('should have sensible defaults', function() { |
| 99 var group = new CTFailureGroup('', [], undefined); | 100 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([])); |
| 100 assert.deepEqual(group._annotation, {}); | 101 assert.deepEqual(group._annotation, {}); |
| 101 assert.isFalse(group.isSnoozed); | 102 assert.isFalse(group.isSnoozed); |
| 102 assert.isUndefined(group.bug); | 103 assert.isUndefined(group.bug); |
| 103 assert.isUndefined(group.bugLabel); | 104 assert.isUndefined(group.bugLabel); |
| 104 }); | 105 }); |
| 105 | 106 |
| 106 it('should compute properties', function() { | 107 it('should compute properties', function() { |
| 107 var group = new CTFailureGroup('', [newFailureWithAnnotation( | 108 var group = new CTFailureGroup('', new CTSheriffFailureGroupData([newFailu
reWithAnnotation( |
| 108 {snoozeTime: Date.now() + 1000 * 1000, bug: 'http://crbug.com/123'})],
undefined); | 109 {snoozeTime: Date.now() + 1000 * 1000, bug: 'http://crbug.com/123'})])
); |
| 109 assert.isTrue(group.isSnoozed); | 110 assert.isTrue(group.isSnoozed); |
| 110 assert.equal(group.bug, 'http://crbug.com/123'); | 111 assert.equal(group.bug, 'http://crbug.com/123'); |
| 111 }); | 112 }); |
| 112 | 113 |
| 113 it('should ignore snoozeTime unless it is present on all alerts', function()
{ | 114 it('should ignore snoozeTime unless it is present on all alerts', function()
{ |
| 114 var notSnoozedMultipleAlerts = new CTFailureGroup('', [ | 115 var notSnoozedMultipleAlerts = new CTFailureGroup('', new CTSheriffFailure
GroupData([ |
| 115 new CTFailure('step', 'reason', [ | 116 new CTFailure('step', 'reason', [ |
| 116 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 117 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 117 {key: 'b',}, | 118 {key: 'b',}, |
| 118 ], undefined) | 119 ]) |
| 119 ]); | 120 ])); |
| 120 var notSnoozedMultipleFailures = new CTFailureGroup('', [ | 121 var notSnoozedMultipleFailures = new CTFailureGroup('', new CTSheriffFailu
reGroupData([ |
| 121 new CTFailure('step', 'reason', [ | 122 new CTFailure('step', 'reason', [ |
| 122 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 123 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 123 ]), | 124 ]), |
| 124 new CTFailure('step', 'reason', [ | 125 new CTFailure('step', 'reason', [ |
| 125 {key: 'b'}, | 126 {key: 'b'}, |
| 126 ]), | 127 ]), |
| 127 ], undefined); | 128 ])); |
| 128 var snoozedMultipleAlerts = new CTFailureGroup('', [ | 129 var snoozedMultipleAlerts = new CTFailureGroup('', new CTSheriffFailureGro
upData([ |
| 129 new CTFailure('step', 'reason', [ | 130 new CTFailure('step', 'reason', [ |
| 130 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 131 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 131 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 132 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 132 ]) | 133 ]) |
| 133 ], undefined); | 134 ])); |
| 134 var snoozedMultipleFailures = new CTFailureGroup('', [ | 135 var snoozedMultipleFailures = new CTFailureGroup('', new CTSheriffFailureG
roupData([ |
| 135 new CTFailure('step', 'reason', [ | 136 new CTFailure('step', 'reason', [ |
| 136 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 137 {key: 'a', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 137 ]), | 138 ]), |
| 138 new CTFailure('step', 'reason', [ | 139 new CTFailure('step', 'reason', [ |
| 139 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, | 140 {key: 'b', annotation: {snoozeTime: Date.now() + 1000 * 1000}}, |
| 140 ]), | 141 ]), |
| 141 ], undefined); | 142 ])); |
| 142 assert.isFalse(notSnoozedMultipleAlerts.isSnoozed); | 143 assert.isFalse(notSnoozedMultipleAlerts.isSnoozed); |
| 143 assert.isFalse(notSnoozedMultipleFailures.isSnoozed); | 144 assert.isFalse(notSnoozedMultipleFailures.isSnoozed); |
| 144 assert.isTrue(snoozedMultipleAlerts.isSnoozed); | 145 assert.isTrue(snoozedMultipleAlerts.isSnoozed); |
| 145 assert.isTrue(snoozedMultipleFailures.isSnoozed); | 146 assert.isTrue(snoozedMultipleFailures.isSnoozed); |
| 146 }); | 147 }); |
| 147 | 148 |
| 148 it('should use the earliest snoozeTime of all alerts', function() { | 149 it('should use the earliest snoozeTime of all alerts', function() { |
| 149 var timeFuture = Date.now() + 1000 * 1000; | 150 var timeFuture = Date.now() + 1000 * 1000; |
| 150 var timePast = Date.now() - 1000 * 1000; | 151 var timePast = Date.now() - 1000 * 1000; |
| 151 | 152 |
| 152 var notSnoozed = new CTFailureGroup('', [ | 153 var notSnoozed = new CTFailureGroup('', new CTSheriffFailureGroupData([ |
| 153 new CTFailure('step', 'reason', [ | 154 new CTFailure('step', 'reason', [ |
| 154 {key: 'a', annotation: {snoozeTime: timeFuture}}, | 155 {key: 'a', annotation: {snoozeTime: timeFuture}}, |
| 155 {key: 'b', annotation: {snoozeTime: timePast}}, | 156 {key: 'b', annotation: {snoozeTime: timePast}}, |
| 156 ]) | 157 ]) |
| 157 ], undefined); | 158 ])); |
| 158 | 159 |
| 159 assert.isFalse(notSnoozed.isSnoozed); | 160 assert.isFalse(notSnoozed.isSnoozed); |
| 160 }); | 161 }); |
| 161 | 162 |
| 162 it('should be persisted', function(done) { | 163 it('should be persisted', function(done) { |
| 163 var group = new CTFailureGroup('', [newFailureWithAnnotation(), newFailure
WithAnnotation()], undefined); | 164 var group = new CTFailureGroup('', new CTSheriffFailureGroupData( |
| 165 [newFailureWithAnnotation(), newFailureWithAnnotation()])); |
| 164 group.snoozeUntil(123).then(function() { | 166 group.snoozeUntil(123).then(function() { |
| 165 group.setBug('456').then(function() { | 167 group.setBug('456').then(function() { |
| 166 CTFailureGroup.fetchAnnotations().then(function(annotations) { | 168 CTFailureGroup.fetchAnnotations().then(function(annotations) { |
| 167 assert.deepEqual(annotations[group.failures[0].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); | 169 assert.deepEqual(annotations[group.data.failures[0].keys()[0]], {sno
ozeTime: 123, bug: 'http://crbug.com/456'}); |
| 168 assert.deepEqual(annotations[group.failures[1].keys()[0]], {snoozeTi
me: 123, bug: 'http://crbug.com/456'}); | 170 assert.deepEqual(annotations[group.data.failures[1].keys()[0]], {sno
ozeTime: 123, bug: 'http://crbug.com/456'}); |
| 169 done(); | 171 done(); |
| 170 }); | 172 }); |
| 171 }); | 173 }); |
| 172 }); | 174 }); |
| 173 }); | 175 }); |
| 174 }); | 176 }); |
| 175 }); | 177 }); |
| 176 | 178 |
| 177 })() | 179 })() |
| 178 </script> | 180 </script> |
| OLD | NEW |