Blame view

bower_components/paper-dropdown-menu/test/paper-dropdown-menu.html 5.83 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
  <!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>
    <meta charset="UTF-8">
    <title>paper-dropdown-menu basic tests</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  
    <script src="../../webcomponentsjs/webcomponents-lite.js"></script>
    <script src="../../web-component-tester/browser.js"></script>
    <script src="../../test-fixture/test-fixture-mocha.js"></script>
    <script src="../../iron-test-helpers/mock-interactions.js"></script>
  
c5169e0e   Renato De Donato   a new hope
22
    <link rel="import" href="../../paper-menu/paper-menu.html">
73bcce88   luigser   COMPONENTS
23
24
25
26
27
28
29
30
31
32
    <link rel="import" href="../../paper-item/paper-item.html">
    <link rel="import" href="../../test-fixture/test-fixture.html">
    <link rel="import" href="../paper-dropdown-menu.html">
  
  </head>
  <body>
  
    <test-fixture id="TrivialDropdownMenu">
      <template>
        <paper-dropdown-menu no-animations>
c5169e0e   Renato De Donato   a new hope
33
          <paper-menu class="dropdown-content">
73bcce88   luigser   COMPONENTS
34
35
            <paper-item>Foo</paper-item>
            <paper-item>Bar</paper-item>
c5169e0e   Renato De Donato   a new hope
36
          </paper-menu>
73bcce88   luigser   COMPONENTS
37
38
39
40
41
42
43
        </paper-dropdown-menu>
      </template>
    </test-fixture>
  
    <test-fixture id="PreselectedDropdownMenu">
      <template>
        <paper-dropdown-menu no-animations>
c5169e0e   Renato De Donato   a new hope
44
          <paper-menu class="dropdown-content" selected="1">
73bcce88   luigser   COMPONENTS
45
46
            <paper-item>Foo</paper-item>
            <paper-item>Bar</paper-item>
c5169e0e   Renato De Donato   a new hope
47
          </paper-menu>
73bcce88   luigser   COMPONENTS
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
        </paper-dropdown-menu>
      </template>
    </test-fixture>
  
    <script>
  
      suite('<paper-dropdown-menu>', function() {
        var dropdownMenu;
  
        setup(function() {
          dropdownMenu = fixture('TrivialDropdownMenu');
          content = Polymer.dom(dropdownMenu).querySelector('.dropdown-content');
        });
  
        test('opens when tapped', function(done) {
          var contentRect = content.getBoundingClientRect();
  
          expect(contentRect.width).to.be.equal(0);
          expect(contentRect.height).to.be.equal(0);
  
          MockInteractions.tap(dropdownMenu);
          expect(dropdownMenu.opened).to.be.equal(true);
  
          Polymer.Base.async(function() {
            contentRect = content.getBoundingClientRect();
  
            expect(dropdownMenu.opened).to.be.equal(true);
  
            expect(contentRect.width).to.be.greaterThan(0);
            expect(contentRect.height).to.be.greaterThan(0);
            done();
          });
        });
  
        test('closes when an item is activated', function(done) {
          MockInteractions.tap(dropdownMenu);
  
          Polymer.Base.async(function() {
            var firstItem = Polymer.dom(content).querySelector('paper-item');
  
            MockInteractions.tap(firstItem);
  
            Polymer.Base.async(function() {
              expect(dropdownMenu.opened).to.be.equal(false);
              done();
            });
          });
        });
  
        test('sets selected item to the activated item', function(done) {
          MockInteractions.tap(dropdownMenu);
  
          Polymer.Base.async(function() {
            var firstItem = Polymer.dom(content).querySelector('paper-item');
  
            MockInteractions.tap(firstItem);
  
            Polymer.Base.async(function() {
              expect(dropdownMenu.selectedItem).to.be.equal(firstItem);
              done();
            });
          });
        });
  
        suite('when a value is preselected', function() {
          setup(function() {
            dropdownMenu = fixture('PreselectedDropdownMenu');
          });
  
          test('the input area shows the correct selection', function() {
73bcce88   luigser   COMPONENTS
118
119
120
121
            var secondItem = Polymer.dom(dropdownMenu).querySelectorAll('paper-item')[1];
            expect(dropdownMenu.selectedItem).to.be.equal(secondItem);
          });
        });
e619a3b0   Luigi Serra   Controllet cross ...
122
123
124
125
126
127
128
129
130
131
  
        suite('deselecting', function() {
          var menu;
  
          setup(function() {
            dropdownMenu = fixture('PreselectedDropdownMenu');
            menu = Polymer.dom(dropdownMenu).querySelector('.dropdown-content');
          });
  
          test('an `iron-deselect` event clears the current selection', function() {
e619a3b0   Luigi Serra   Controllet cross ...
132
133
134
135
            menu.selected = null;
            expect(dropdownMenu.selectedItem).to.be.equal(null);
          });
        });
eb240478   Luigi Serra   public room cards...
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
  
        suite('validation', function() {
          test('a non required dropdown is valid regardless of its selection', function() {
            var dropdownMenu = fixture('TrivialDropdownMenu');
            menu = Polymer.dom(dropdownMenu).querySelector('.dropdown-content');
  
            // no selection.
            expect(dropdownMenu.validate()).to.be.true;
            expect(dropdownMenu.invalid).to.be.false;
            expect(dropdownMenu.value).to.not.be.ok;
  
            // some selection.
            menu.selected = 1;
            expect(dropdownMenu.validate()).to.be.true;
            expect(dropdownMenu.invalid).to.be.false;
            expect(dropdownMenu.value).to.be.equal('Bar');
          });
  
          test('a required dropdown is invalid without a selection', function() {
            var dropdownMenu = fixture('TrivialDropdownMenu');
            dropdownMenu.required = true;
  
            // no selection.
            expect(dropdownMenu.validate()).to.be.false;
            expect(dropdownMenu.invalid).to.be.true;
            expect(dropdownMenu.value).to.not.be.ok;
          });
  
          test('a required dropdown is valid with a selection', function() {
            var dropdownMenu = fixture('PreselectedDropdownMenu');
eb240478   Luigi Serra   public room cards...
166
            dropdownMenu.required = true;
c5169e0e   Renato De Donato   a new hope
167
            
eb240478   Luigi Serra   public room cards...
168
169
170
171
172
            expect(dropdownMenu.validate()).to.be.true;
            expect(dropdownMenu.invalid).to.be.false;
            expect(dropdownMenu.value).to.be.equal('Bar');
          });
        });
73bcce88   luigser   COMPONENTS
173
174
175
176
177
      });
    </script>
  
  </body>
  </html>