Blame view

bower_components/paper-tabs/test/basic.html 6.15 KB
73bcce88   luigser   COMPONENTS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  <!doctype html>
  <!--
  @license
  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>paper-tabs-basic</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
  
      <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
      <script src="../../web-component-tester/browser.js"></script>
73bcce88   luigser   COMPONENTS
21
22
  
      <link rel="import" href="../paper-tabs.html">
e619a3b0   Luigi Serra   Controllet cross ...
23
      <link rel="import" href="../../iron-test-helpers/iron-test-helpers.html">
a1a3bc73   Luigi Serra   graphs updates
24
      
73bcce88   luigser   COMPONENTS
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    </head>
    <body>
  
      <test-fixture id="basic">
        <template>
          <paper-tabs>
            <paper-tab>ITEM ONE</paper-tab>
            <paper-tab>ITEM TWO</paper-tab>
            <paper-tab>ITEM THREE</paper-tab>
          </paper-tabs>
        </template>
      </test-fixture>
  
      <test-fixture id="HiddenTabs">
        <template>
          <paper-tabs hidden>
            <paper-tab>ITEM ONE</paper-tab>
            <paper-tab>ITEM TWO</paper-tab>
          </paper-tabs>
        </template>
      </test-fixture>
  
      <script>
  
        function checkSelectionBar(tabs, tab) {
          var tabRect = tab.getBoundingClientRect();
          var rect = Polymer.dom(tabs.root).querySelector('#selectionBar').getBoundingClientRect();
          assert.equal(Math.round(tabRect.left), Math.round(rect.left));
        }
  
        suite('defaults', function() {
  
          var tabs;
  
          setup(function () {
            tabs = fixture('basic');
          });
  
          test('to nothing selected', function() {
            assert.equal(tabs.selected, undefined);
          });
  
          test('no tabs have iron-selected class', function() {
            Array.prototype.forEach.call(tabs.querySelectorAll('paper-tab'), function(tab) {
              assert.isFalse(tab.classList.contains('iron-selected'));
            });
          });
  
          test('to false as noink', function() {
            assert.equal(tabs.noink, false);
          });
  
          test('to false as noBar', function() {
            assert.equal(tabs.noBar, false);
          });
  
          test('to false as noSlide', function() {
            assert.equal(tabs.noSlide, false);
          });
  
          test('to false as scrollable', function() {
            assert.equal(tabs.scrollable, false);
          });
  
          test('to false as disableDrag', function() {
            assert.equal(tabs.disableDrag, false);
          });
  
          test('to false as hideScrollButtons', function() {
            assert.equal(tabs.hideScrollButtons, false);
          });
  
          test('to false as alignBottom', function() {
            assert.equal(tabs.alignBottom, false);
          });
  
          test('has role tablist', function() {
            assert.equal(tabs.getAttribute('role'), 'tablist');
          });
        });
  
        suite('hidden tabs', function() {
          var tabs;
  
          setup(function() {
            tabs = fixture('HiddenTabs');
          });
  
          test('choose the correct bar position once made visible', function() {
            tabs.removeAttribute('hidden');
            tabs.selected = 0;
            expect(tabs._width).to.be.greaterThan(0);
            expect(tabs._left).to.be.equal(0);
          });
        });
  
        suite('set the selected attribute', function() {
  
          var tabs, index = 0;
  
          setup(function () {
            tabs = fixture('basic');
            tabs.selected = index;
          });
  
          test('selected value', function() {
            assert.equal(tabs.selected, index);
          });
  
          test('selected tab has iron-selected class', function() {
            var tab = tabs.querySelectorAll('paper-tab')[index];
            assert.isTrue(tab.classList.contains('iron-selected'));
          });
  
          test('selected tab has selection bar position at the bottom of the tab', function(done) {
            setTimeout(function() {
              checkSelectionBar(tabs, tabs.querySelectorAll('paper-tab')[index]);
              done();
            }, 1000);
          });
  
        });
  
        suite('select tab via click', function() {
  
          var tabs, index = 1;
e619a3b0   Luigi Serra   Controllet cross ...
151
          var tab;
73bcce88   luigser   COMPONENTS
152
153
154
  
          setup(function () {
            tabs = fixture('basic');
e619a3b0   Luigi Serra   Controllet cross ...
155
            tab = tabs.querySelectorAll('paper-tab')[index];
73bcce88   luigser   COMPONENTS
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
            tab.dispatchEvent(new CustomEvent('click', {bubbles: true}));
          });
  
          test('selected value', function() {
            assert.equal(tabs.selected, index);
          });
  
          test('selected tab has iron-selected class', function() {
            var tab = tabs.querySelectorAll('paper-tab')[index];
            assert.isTrue(tab.classList.contains('iron-selected'));
          });
  
          test('selected tab has selection bar position at the bottom of the tab', function(done) {
            setTimeout(function() {
              checkSelectionBar(tabs, tabs.querySelectorAll('paper-tab')[index]);
              done();
            }, 1000);
          });
  
e619a3b0   Luigi Serra   Controllet cross ...
175
176
177
178
179
180
181
182
183
184
185
186
          test('pressing enter on tab causes a click', function(done) {
            var clickCount = 0;
            tab.addEventListener('click', function onTabClick() {
              clickCount++;
              tab.removeEventListener('click', onTabClick);
  
              expect(clickCount).to.be.equal(1);
              done();
            });
  
            MockInteractions.pressEnter(tab);
          });
73bcce88   luigser   COMPONENTS
187
188
        });
  
a1a3bc73   Luigi Serra   graphs updates
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
        suite('noink attribute', function() {
          var tabs;
  
          setup(function () {
            tabs = fixture('basic');
          });
  
          test('noink attribute propagates to all descendant tabs', function() {
            tabs.noink = true;
            Array.prototype.slice.apply(tabs.querySelectorAll('paper-tab')).forEach(function(tab) {
              assert.isTrue(tab.noink);
            });
  
            tabs.noink = false;
            Array.prototype.slice.apply(tabs.querySelectorAll('paper-tab')).forEach(function(tab) {
              assert.isFalse(tab.noink);
            });
          });
        });
  
73bcce88   luigser   COMPONENTS
209
210
211
212
      </script>
  
    </body>
  </html>