Debian Codegraph @

closure-library/closure/goog/ui/tabbarrenderer_test.js

raw
1 // Copyright 2008 The Closure Library Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS-IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 goog.provide('goog.ui.TabBarRendererTest');
16 goog.setTestOnly('goog.ui.TabBarRendererTest');
17
18 goog.require('goog.a11y.aria.Role');
19 goog.require('goog.dom');
20 goog.require('goog.dom.TagName');
21 goog.require('goog.dom.classlist');
22 goog.require('goog.testing.jsunit');
23 goog.require('goog.testing.ui.rendererasserts');
24 goog.require('goog.ui.Container');
25 goog.require('goog.ui.TabBar');
26 goog.require('goog.ui.TabBarRenderer');
27
28 var sandbox;
29 var renderer;
30 var tabBar;
31
32 function setUp() {
33 sandbox = goog.dom.getElement('sandbox');
34 renderer = goog.ui.TabBarRenderer.getInstance();
35 tabBar = new goog.ui.TabBar();
36 }
37
38 function tearDown() {
39 tabBar.dispose();
40 goog.dom.removeChildren(sandbox);
41 }
42
43 function testConstructor() {
44 assertNotNull('Renderer must not be null', renderer);
45 }
46
47 function testGetCssClass() {
48 assertEquals(
49 'getCssClass() must return expected value',
50 goog.ui.TabBarRenderer.CSS_CLASS, renderer.getCssClass());
51 }
52
53 function testGetAriaRole() {
54 assertEquals(
55 'getAriaRole() must return expected value', goog.a11y.aria.Role.TAB_LIST,
56 renderer.getAriaRole());
57 }
58
59 function testCreateDom() {
60 var element = renderer.createDom(tabBar);
61 assertNotNull('Created element must not be null', element);
62 assertEquals('Created element must be a DIV',
63 String(goog.dom.TagName.DIV), element.tagName);
64 assertSameElements(
65 'Created element must have expected class names',
66 ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-top'],
67 goog.dom.classlist.get(element));
68 }
69
70 function testDecorate() {
71 sandbox.innerHTML = '<div id="start" class="goog-tab-bar-start"></div>';
72 var element = renderer.decorate(tabBar, goog.dom.getElement('start'));
73 assertNotNull('Decorated element must not be null', element);
74 assertEquals(
75 'Decorated element must be as expected', goog.dom.getElement('start'),
76 element);
77 // Due to a bug in ContainerRenderer, the "-vertical" class isn't applied.
78 // TODO(attila): Fix this!
79 assertSameElements(
80 'Decorated element must have expected class names',
81 ['goog-tab-bar', 'goog-tab-bar-start'], goog.dom.classlist.get(element));
82 }
83
84 function testSetStateFromClassName() {
85 renderer.setStateFromClassName(
86 tabBar, 'goog-tab-bar-bottom', renderer.getCssClass());
87 assertEquals(
88 'Location must be BOTTOM', goog.ui.TabBar.Location.BOTTOM,
89 tabBar.getLocation());
90 assertEquals(
91 'Orientation must be HORIZONTAL',
92 goog.ui.Container.Orientation.HORIZONTAL, tabBar.getOrientation());
93
94 renderer.setStateFromClassName(
95 tabBar, 'goog-tab-bar-end', renderer.getCssClass());
96 assertEquals(
97 'Location must be END', goog.ui.TabBar.Location.END,
98 tabBar.getLocation());
99 assertEquals(
100 'Orientation must be VERTICAL', goog.ui.Container.Orientation.VERTICAL,
101 tabBar.getOrientation());
102
103 renderer.setStateFromClassName(
104 tabBar, 'goog-tab-bar-top', renderer.getCssClass());
105 assertEquals(
106 'Location must be TOP', goog.ui.TabBar.Location.TOP,
107 tabBar.getLocation());
108 assertEquals(
109 'Orientation must be HORIZONTAL',
110 goog.ui.Container.Orientation.HORIZONTAL, tabBar.getOrientation());
111
112 renderer.setStateFromClassName(
113 tabBar, 'goog-tab-bar-start', renderer.getCssClass());
114 assertEquals(
115 'Location must be START', goog.ui.TabBar.Location.START,
116 tabBar.getLocation());
117 assertEquals(
118 'Orientation must be VERTICAL', goog.ui.Container.Orientation.VERTICAL,
119 tabBar.getOrientation());
120 }
121
122 function testGetClassNames() {
123 assertSameElements(
124 'Class names for TOP location must be as expected',
125 ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-top'],
126 renderer.getClassNames(tabBar));
127
128 tabBar.setLocation(goog.ui.TabBar.Location.START);
129 assertSameElements(
130 'Class names for START location must be as expected',
131 ['goog-tab-bar', 'goog-tab-bar-vertical', 'goog-tab-bar-start'],
132 renderer.getClassNames(tabBar));
133
134 tabBar.setLocation(goog.ui.TabBar.Location.BOTTOM);
135 assertSameElements(
136 'Class names for BOTTOM location must be as expected',
137 ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-bottom'],
138 renderer.getClassNames(tabBar));
139
140 tabBar.setLocation(goog.ui.TabBar.Location.END);
141 assertSameElements(
142 'Class names for END location must be as expected',
143 ['goog-tab-bar', 'goog-tab-bar-vertical', 'goog-tab-bar-end'],
144 renderer.getClassNames(tabBar));
145 }
146
147 function testDoesntCallGetCssClassInConstructor() {
148 goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor(
149 goog.ui.TabBarRenderer);
150 }