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

Side by Side Diff: third_party/polymer/components-chromium/core-selector/test/multi.html

Issue 1215543002: Remove Polymer 0.5. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix unit test Created 5 years, 5 months 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
OLDNEW
(Empty)
1 <!doctype html>
2 <!--
3 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.g ithub.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRI BUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATEN TS.txt
9 -->
10 <html>
11 <head>
12 <meta charset="UTF-8">
13 <title>core-selector-multi</title>
14
15 <script src="../../webcomponentsjs/webcomponents.js"></script>
16 <script src="../../web-component-tester/browser.js"></script>
17
18 <link rel="import" href="../core-selector.html">
19
20 <style>
21 .core-selected {
22 background: #ccc;
23 }
24 </style>
25
26 </head>
27 <body>
28
29 <core-selector id="selector" multi>
30 <div>Item 1</div>
31 <div>Item 2</div>
32 <div>Item 3</div>
33 <div>Item 4</div>
34 <div>Item 5</div>
35 </core-selector>
36
37 <script>
38
39 var s = document.querySelector('#selector');
40
41 suite('multi', function() {
42
43 test('honors the multi attribute', function() {
44 assert.isTrue(s.multi);
45 });
46
47 test('has sane defaults', function() {
48 assert.equal(s.selected, null);
49 assert.equal(s.selectedClass, 'core-selected');
50 assert.equal(s.valueattr, 'name');
51 assert.equal(s.items.length, 5);
52 });
53
54 test('allows multi-selection', function(done) {
55 // setup listener for core-select event
56 var selectEventCounter = 0;
57 s.addEventListener('core-select', function(e) {
58 if (e.detail.isSelected) {
59 selectEventCounter++;
60 } else {
61 selectEventCounter--;
62 }
63 });
64 // set selected
65 s.selected = [0, 2];
66 asyncPlatformFlush(function() {
67 // check core-select event
68 assert.equal(selectEventCounter, 2);
69 // check selected class
70 assert.isTrue(s.children[0].classList.contains('core-selected'));
71 assert.isTrue(s.children[2].classList.contains('core-selected'));
72 // check selectedItem
73 assert.equal(s.selectedItem.length, 2);
74 assert.equal(s.selectedItem[0], s.children[0]);
75 assert.equal(s.selectedItem[1], s.children[2]);
76 // tap on already selected element should unselect it
77 s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
78 // check selected
79 assert.equal(s.selected.length, 1);
80 asyncPlatformFlush(function() {
81 assert.equal(selectEventCounter, 1);
82 assert.isFalse(s.children[0].classList.contains('core-selected'));
83 // add selected
84 s.selected.push(3);
85 s.selected.push(4);
86 // check core-select event
87 asyncPlatformFlush(function() {
88 assert.equal(selectEventCounter, 3);
89 done();
90 });
91 });
92 });
93 });
94
95 test('toggle multi to false', function(done) {
96 // set selected
97 s.selected = [0, 2];
98 var first = s.selected[0];
99 // set mutli to false, so to make it single-selection
100 s.multi = false;
101 asyncPlatformFlush(function() {
102 // selected should not be an array
103 assert.isNotArray(s.selected);
104 // selected should be the first value in the old array
105 assert.equal(s.selected, first);
106 done();
107 });
108 });
109
110 });
111
112 </script>
113
114 </body>
115 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698