| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:html'; | 5 import 'dart:html'; |
| 6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:observatory/src/elements/source_link.dart'; | 7 import 'package:observatory/src/elements/source_link.dart'; |
| 8 import '../mocks.dart'; | 8 import '../mocks.dart'; |
| 9 | 9 |
| 10 main() { | 10 main() { |
| 11 SourceLinkElement.tag.ensureRegistration(); | 11 SourceLinkElement.tag.ensureRegistration(); |
| 12 | 12 |
| 13 const isolate = const IsolateRefMock(id: 'isolate-id'); | 13 const isolate = const IsolateRefMock(id: 'isolate-id'); |
| 14 const script_id = 'script-id'; | 14 const script_id = 'script-id'; |
| 15 const file = 'filename.dart'; | 15 const file = 'filename.dart'; |
| 16 final script = new ScriptMock(id: script_id, uri: 'package/$file', | 16 final script = new ScriptMock( |
| 17 tokenToLine: (int token) => 1, tokenToCol: (int token) => 2); | 17 id: script_id, |
| 18 final location = new SourceLocationMock(script: script, tokenPos: 0, | 18 uri: 'package/$file', |
| 19 endTokenPos: 1); | 19 tokenToLine: (int token) => 1, |
| 20 tokenToCol: (int token) => 2); |
| 21 final location = |
| 22 new SourceLocationMock(script: script, tokenPos: 0, endTokenPos: 1); |
| 20 final repository = new ScriptRepositoryMock(); | 23 final repository = new ScriptRepositoryMock(); |
| 21 test('instantiation', () { | 24 test('instantiation', () { |
| 22 final e = new SourceLinkElement(isolate, location, repository); | 25 final e = new SourceLinkElement(isolate, location, repository); |
| 23 expect(e, isNotNull, reason: 'element correctly created'); | 26 expect(e, isNotNull, reason: 'element correctly created'); |
| 24 expect(e.isolate, equals(isolate)); | 27 expect(e.isolate, equals(isolate)); |
| 25 expect(e.location, equals(location)); | 28 expect(e.location, equals(location)); |
| 26 }); | 29 }); |
| 27 test('elements created after attachment', () async { | 30 test('elements created after attachment', () async { |
| 28 bool rendered = false; | 31 bool rendered = false; |
| 29 final repository = new ScriptRepositoryMock( | 32 final repository = new ScriptRepositoryMock( |
| 30 getter: expectAsync((isolate, id) async { | 33 getter: expectAsync((isolate, id) async { |
| 31 expect(rendered, isFalse); | 34 expect(rendered, isFalse); |
| 32 expect(id, equals(script_id)); | 35 expect(id, equals(script_id)); |
| 33 return script; | 36 return script; |
| 34 }, count: 1) | 37 }, count: 1)); |
| 35 ); | |
| 36 final e = new SourceLinkElement(isolate, location, repository); | 38 final e = new SourceLinkElement(isolate, location, repository); |
| 37 document.body.append(e); | 39 document.body.append(e); |
| 38 await e.onRendered.first; | 40 await e.onRendered.first; |
| 39 rendered = true; | 41 rendered = true; |
| 40 expect(e.children.length, isNonZero, reason: 'has elements'); | 42 expect(e.children.length, isNonZero, reason: 'has elements'); |
| 41 expect(e.innerHtml.contains(isolate.id), isTrue, | 43 expect(e.innerHtml.contains(isolate.id), isTrue, |
| 42 reason: 'no message in the component'); | 44 reason: 'no message in the component'); |
| 43 expect(e.innerHtml.contains(file), isTrue, | 45 expect(e.innerHtml.contains(file), isTrue, |
| 44 reason: 'no message in the component'); | 46 reason: 'no message in the component'); |
| 45 e.remove(); | 47 e.remove(); |
| 46 await e.onRendered.first; | 48 await e.onRendered.first; |
| 47 expect(e.children.length, isZero, | 49 expect(e.children.length, isZero, reason: 'is empty'); |
| 48 reason: 'is empty'); | |
| 49 }); | 50 }); |
| 50 } | 51 } |
| OLD | NEW |