Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(857)

Side by Side Diff: test/iron_iconset_svg_test.dart

Issue 1418513006: update elements and fix some bugs (Closed) Base URL: git@github.com:dart-lang/polymer_elements.git@master
Patch Set: code review updates Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/iron_icon_test.html ('k') | test/iron_iconset_svg_test.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 @TestOn('browser') 4 @TestOn('browser')
5 library polymer_elements.test.iron_iconset_svg_test; 5 library polymer_elements.test.iron_iconset_svg_test;
6 6
7 import 'dart:html';
8 import 'package:polymer_interop/polymer_interop.dart';
7 import 'package:polymer_elements/iron_iconset_svg.dart'; 9 import 'package:polymer_elements/iron_iconset_svg.dart';
10 import 'package:polymer_elements/iron_meta.dart';
8 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
9 import 'package:web_components/web_components.dart'; 12 import 'package:web_components/web_components.dart';
10 import 'common.dart'; 13 import 'common.dart';
11 14
12 /// Used imports: [IronIconsetSvg] 15 /// Used imports: [IronIconsetSvg]
13 main() async { 16 main() async {
14 await initWebComponents(); 17 await initWebComponents();
15 18
16 group('<iron-iconset>', () { 19 group('<iron-iconset>', () {
17 group('basic behavior', () { 20 group('basic behavior', () {
18 var iconset; 21 IronIconsetSvg iconset;
19 var meta; 22 IronMeta meta;
20 23
21 setUp(() { 24 setUp(() {
22 var elements = fixture('TrivialIconsetSvg'); 25 var elements = fixture('TrivialIconsetSvg');
23 iconset = elements[0]; 26 iconset = elements[0];
24 meta = elements[1]; 27 meta = elements[1];
25 }); 28 });
26 29
27 test('it can be accessed via iron-meta', () { 30 test('it can be accessed via iron-meta', () {
28 expect(meta.byKey('foo'), iconset); 31 expect(meta.byKey('foo'), iconset);
29 }); 32 });
33
34 test('it does not have a size', () {
35 var rect = iconset.getBoundingClientRect();
36 expect(rect.width, 0);
37 expect(rect.height, 0);
38 });
39
40 test('it fires an iron-iconset-added event on the window', () {
41 return window.on['iron-iconset-added'].first.then((ev) {
42 ev = convertToDart(ev);
43 expect(ev, isNotNull);
44 expect(ev.detail, iconset);
45 });
46 });
30 }); 47 });
48
31 group('when paired with a size and SVG definition', () { 49 group('when paired with a size and SVG definition', () {
32 var iconset; 50 IronIconsetSvg iconset;
33 var div; 51 var div;
34 52
35 setUp(() { 53 setUp(() {
36 var elements = fixture('StandardIconsetSvg'); 54 var elements = fixture('StandardIconsetSvg');
37 iconset = elements[0]; 55 iconset = elements[0];
38 div = elements[1]; 56 div = elements[1];
39 }); 57 });
40 58
59 test('it does not have a size', () {
60 var rect = iconset.getBoundingClientRect();
61 expect(rect.width, 0);
62 expect(rect.height, 0);
63 });
64
41 test('appends a child to the target element', () { 65 test('appends a child to the target element', () {
42 expect(div.children.length, 0); 66 expect(div.children.length, 0);
43 iconset.applyIcon(div, 'circle'); 67 iconset.applyIcon(div, 'circle');
44 expect(div.children.length, 1); 68 expect(div.children.length, 1);
45 }); 69 });
46 70
47 test('can be queried for all available icons', () { 71 test('can be queried for all available icons', () {
48 expect(iconset.getIconNames(), ['my-icons:circle', 'my-icons:square']); 72 expect(iconset.getIconNames(),
73 ['my-icons:circle', 'my-icons:square', 'my-icons:rect']);
49 }); 74 });
50 75
51 test('supports any icon defined in the svg', () { 76 test('supports any icon defined in the svg', () {
52 var lastSvgIcon; 77 var lastSvgIcon;
53 iconset.getIconNames().forEach((iconName) { 78 iconset.getIconNames().forEach((iconName) {
54 iconset.applyIcon(div, iconName.split(':').removeLast()); 79 iconset.applyIcon(div, iconName.split(':').removeLast());
55 expect(div.children.first, isNot(lastSvgIcon)); 80 expect(div.children.first, isNot(lastSvgIcon));
56 lastSvgIcon = div.children.first; 81 lastSvgIcon = div.children.first;
57 }); 82 });
58 }); 83 });
84
85 test('prefers a viewBox attribute over the iconset size', () {
86 iconset.applyIcon(div, 'rect');
87 expect(div.children.first.getAttribute('viewBox'), '0 0 50 25');
88 });
89
90 test('uses the iconset size when viewBox is not defined on the element',
91 () {
92 iconset.applyIcon(div, 'circle');
93 expect(div.children.first.getAttribute('viewBox'), '0 0 20 20');
94 });
59 }); 95 });
60 }); 96 });
61 } 97 }
OLDNEW
« no previous file with comments | « test/iron_icon_test.html ('k') | test/iron_iconset_svg_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698