Blame view

bower_components/iron-selector/test/activate-event.html 4.46 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
  <!doctype html>
  <!--
  Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
  This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
  The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
  The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
  Code distributed by Google as part of the polymer project is also
  subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
  -->
  
  <html>
  <head>
  
    <title>iron-selector-activate-event</title>
    <meta charset="UTF-8">
  
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <script src="../../web-component-tester/browser.js"></script>
    <script src="../../test-fixture/test-fixture-mocha.js"></script>
  
    <link rel="import" href="../../test-fixture/test-fixture.html">
    <link rel="import" href="../iron-selector.html">
  
    <style>
      .iron-selected {
        background: #ccc;
      }
    </style>
  
  </head>
  <body>
  
    <test-fixture id="test">
      <template>
        <iron-selector id="selector" selected="0">
          <div>Item 0</div>
          <div>Item 1</div>
          <div>Item 2</div>
          <div>Item 3</div>
          <div>Item 4</div>
        </iron-selector>
      </template>
    </test-fixture>
  
    <script>
  
      suite('activate event', function() {
  
        var s;
  
        setup(function () {
          s = fixture('test');
        });
  
        test('activates on tap', function() {
          assert.equal(s.selected, '0');
  
          // select Item 1
          s.children[1].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
          assert.equal(s.selected, '1');
        });
  
        test('activates on tap and fires iron-activate', function(done) {
          assert.equal(s.selected, '0');
  
          // attach iron-activate listener
          s.addEventListener("iron-activate", function(event) {
            assert.equal(event.detail.selected, '1');
            assert.equal(event.detail.item, s.children[1]);
            done();
          });
  
          // select Item 1
          s.children[1].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
        });
  
        test('tap on already selected and fires iron-activate', function(done) {
          assert.equal(s.selected, '0');
  
          // attach iron-activate listener
          s.addEventListener("iron-activate", function(event) {
            assert.equal(event.detail.selected, '0');
            assert.equal(event.detail.item, s.children[0]);
            done();
          });
  
          // select Item 0
          s.children[0].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
        });
  
        test('activates on mousedown', function() {
          // set activateEvent to mousedown
          s.activateEvent = 'mousedown';
          // select Item 2
          s.children[2].dispatchEvent(new CustomEvent('mousedown', {bubbles: true}));
          assert.equal(s.selected, '2');
        });
  
        test('activates on mousedown and fires iron-activate', function(done) {
          // attach iron-activate listener
          s.addEventListener("iron-activate", function(event) {
            assert.equal(event.detail.selected, '2');
            assert.equal(event.detail.item, s.children[2]);
            done();
          });
  
          // set activateEvent to mousedown
          s.activateEvent = 'mousedown';
          // select Item 2
          s.children[2].dispatchEvent(new CustomEvent('mousedown', {bubbles: true}));
        });
  
        test('no activation', function() {
          assert.equal(s.selected, '0');
          // set activateEvent to null
          s.activateEvent = null;
          // select Item 2
          s.children[2].dispatchEvent(new CustomEvent('mousedown', {bubbles: true}));
          assert.equal(s.selected, '0');
        });
  
        test('activates on tap and preventDefault', function() {
          // attach iron-activate listener
          s.addEventListener("iron-activate", function(event) {
            event.preventDefault();
          });
          // select Item 2
          s.children[2].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
          // shouldn't got selected since we preventDefault in iron-activate
          assert.equal(s.selected, '0');
        });
  
eb240478   Luigi Serra   public room cards...
133
134
135
136
137
138
139
140
141
142
143
        test('activates after detach and re-attach', function() {
          // Detach and re-attach
          var parent = s.parentNode;
          parent.removeChild(s);
          parent.appendChild(s);
          
          // select Item 2
          s.children[2].dispatchEvent(new CustomEvent('tap', {bubbles: true}));
          assert.equal(s.selected, '2');
        });
  
73bcce88   luigser   COMPONENTS
144
145
146
147
148
149
      });
  
    </script>
  
  </body>
  </html>