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 import 'dart:html'; | 4 import 'dart:html'; |
5 import 'package:unittest/unittest.dart'; | 5 import 'package:unittest/unittest.dart'; |
6 import 'package:observatory/mocks.dart'; | |
7 import 'package:observatory/models.dart' as M; | 6 import 'package:observatory/models.dart' as M; |
8 import 'package:observatory/src/elements/source_link.dart'; | 7 import 'package:observatory/src/elements/source_link.dart'; |
| 8 import '../mocks.dart'; |
9 | 9 |
10 main() { | 10 main() { |
11 SourceLinkElement.tag.ensureRegistration(); | 11 SourceLinkElement.tag.ensureRegistration(); |
12 | 12 |
13 final M.IsolateRef isolate = const IsolateRefMock(id: 'isolate-id'); | 13 const isolate = const IsolateRefMock(id: 'isolate-id'); |
14 final M.Script script = new ScriptMock(id: 'script-id', | 14 const file = 'filename.dart'; |
15 uri: 'package/filename.dart', | 15 final script = new ScriptMock(id: 'script-id', uri: 'package/$file', |
16 tokenToLine: (int token) => 1, | 16 tokenToLine: (int token) => 1, tokenToCol: (int token) => 2); |
17 tokenToCol: (int token) => 2); | 17 final location = new SourceLocationMock(script: script, tokenPos: 0, |
18 final M.SourceLocation location = new SourceLocationMock(script: script, | 18 endTokenPos: 1); |
19 tokenPos: 0, endTokenPos: 1); | |
20 M.ScriptRepository repository; | 19 M.ScriptRepository repository; |
21 setUp(() { | 20 setUp(() { |
22 repository = new ScriptRepositoryMock({ 'script-id': script }); | 21 repository = new ScriptRepositoryMock({ 'script-id': script }); |
23 }); | 22 }); |
24 test('instantiation', () { | 23 test('instantiation', () { |
25 final SourceLinkElement e = new SourceLinkElement(isolate, location, | 24 final e = new SourceLinkElement(isolate, location, repository); |
26 repository); | |
27 expect(e, isNotNull, reason: 'element correctly created'); | 25 expect(e, isNotNull, reason: 'element correctly created'); |
28 expect(e.isolate, equals(isolate)); | 26 expect(e.isolate, equals(isolate)); |
29 expect(e.location, equals(location)); | 27 expect(e.location, equals(location)); |
30 }); | 28 }); |
31 test('elements created after attachment', () async { | 29 test('elements created after attachment', () async { |
32 final SourceLinkElement e = new SourceLinkElement(isolate, location, | 30 final e = new SourceLinkElement(isolate, location, repository); |
33 repository); | |
34 document.body.append(e); | 31 document.body.append(e); |
35 await e.onRendered.first; | 32 await e.onRendered.first; |
36 expect(e.children.length, isNonZero, reason: 'has elements'); | 33 expect(e.children.length, isNonZero, reason: 'has elements'); |
37 expect(e.innerHtml.contains(isolate.id), isTrue, | 34 expect(e.innerHtml.contains(isolate.id), isTrue, |
38 reason: 'no message in the component'); | 35 reason: 'no message in the component'); |
39 expect(e.innerHtml.contains('filename.dart'), isTrue, | 36 expect(e.innerHtml.contains(file), isTrue, |
40 reason: 'no message in the component'); | 37 reason: 'no message in the component'); |
41 e.remove(); | 38 e.remove(); |
42 await e.onRendered.first; | 39 await e.onRendered.first; |
43 expect(e.children.length, isZero, | 40 expect(e.children.length, isZero, |
44 reason: 'is empty'); | 41 reason: 'is empty'); |
45 }); | 42 }); |
46 } | 43 } |
OLD | NEW |