tabbarrenderer_test.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. goog.provide('goog.ui.TabBarRendererTest');
  15. goog.setTestOnly('goog.ui.TabBarRendererTest');
  16. goog.require('goog.a11y.aria.Role');
  17. goog.require('goog.dom');
  18. goog.require('goog.dom.TagName');
  19. goog.require('goog.dom.classlist');
  20. goog.require('goog.testing.jsunit');
  21. goog.require('goog.testing.ui.rendererasserts');
  22. goog.require('goog.ui.Container');
  23. goog.require('goog.ui.TabBar');
  24. goog.require('goog.ui.TabBarRenderer');
  25. var sandbox;
  26. var renderer;
  27. var tabBar;
  28. function setUp() {
  29. sandbox = goog.dom.getElement('sandbox');
  30. renderer = goog.ui.TabBarRenderer.getInstance();
  31. tabBar = new goog.ui.TabBar();
  32. }
  33. function tearDown() {
  34. tabBar.dispose();
  35. goog.dom.removeChildren(sandbox);
  36. }
  37. function testConstructor() {
  38. assertNotNull('Renderer must not be null', renderer);
  39. }
  40. function testGetCssClass() {
  41. assertEquals(
  42. 'getCssClass() must return expected value',
  43. goog.ui.TabBarRenderer.CSS_CLASS, renderer.getCssClass());
  44. }
  45. function testGetAriaRole() {
  46. assertEquals(
  47. 'getAriaRole() must return expected value', goog.a11y.aria.Role.TAB_LIST,
  48. renderer.getAriaRole());
  49. }
  50. function testCreateDom() {
  51. var element = renderer.createDom(tabBar);
  52. assertNotNull('Created element must not be null', element);
  53. assertEquals('Created element must be a DIV',
  54. String(goog.dom.TagName.DIV), element.tagName);
  55. assertSameElements(
  56. 'Created element must have expected class names',
  57. ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-top'],
  58. goog.dom.classlist.get(element));
  59. }
  60. function testDecorate() {
  61. sandbox.innerHTML = '<div id="start" class="goog-tab-bar-start"></div>';
  62. var element = renderer.decorate(tabBar, goog.dom.getElement('start'));
  63. assertNotNull('Decorated element must not be null', element);
  64. assertEquals(
  65. 'Decorated element must be as expected', goog.dom.getElement('start'),
  66. element);
  67. // Due to a bug in ContainerRenderer, the "-vertical" class isn't applied.
  68. // TODO(attila): Fix this!
  69. assertSameElements(
  70. 'Decorated element must have expected class names',
  71. ['goog-tab-bar', 'goog-tab-bar-start'], goog.dom.classlist.get(element));
  72. }
  73. function testSetStateFromClassName() {
  74. renderer.setStateFromClassName(
  75. tabBar, 'goog-tab-bar-bottom', renderer.getCssClass());
  76. assertEquals(
  77. 'Location must be BOTTOM', goog.ui.TabBar.Location.BOTTOM,
  78. tabBar.getLocation());
  79. assertEquals(
  80. 'Orientation must be HORIZONTAL',
  81. goog.ui.Container.Orientation.HORIZONTAL, tabBar.getOrientation());
  82. renderer.setStateFromClassName(
  83. tabBar, 'goog-tab-bar-end', renderer.getCssClass());
  84. assertEquals(
  85. 'Location must be END', goog.ui.TabBar.Location.END,
  86. tabBar.getLocation());
  87. assertEquals(
  88. 'Orientation must be VERTICAL', goog.ui.Container.Orientation.VERTICAL,
  89. tabBar.getOrientation());
  90. renderer.setStateFromClassName(
  91. tabBar, 'goog-tab-bar-top', renderer.getCssClass());
  92. assertEquals(
  93. 'Location must be TOP', goog.ui.TabBar.Location.TOP,
  94. tabBar.getLocation());
  95. assertEquals(
  96. 'Orientation must be HORIZONTAL',
  97. goog.ui.Container.Orientation.HORIZONTAL, tabBar.getOrientation());
  98. renderer.setStateFromClassName(
  99. tabBar, 'goog-tab-bar-start', renderer.getCssClass());
  100. assertEquals(
  101. 'Location must be START', goog.ui.TabBar.Location.START,
  102. tabBar.getLocation());
  103. assertEquals(
  104. 'Orientation must be VERTICAL', goog.ui.Container.Orientation.VERTICAL,
  105. tabBar.getOrientation());
  106. }
  107. function testGetClassNames() {
  108. assertSameElements(
  109. 'Class names for TOP location must be as expected',
  110. ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-top'],
  111. renderer.getClassNames(tabBar));
  112. tabBar.setLocation(goog.ui.TabBar.Location.START);
  113. assertSameElements(
  114. 'Class names for START location must be as expected',
  115. ['goog-tab-bar', 'goog-tab-bar-vertical', 'goog-tab-bar-start'],
  116. renderer.getClassNames(tabBar));
  117. tabBar.setLocation(goog.ui.TabBar.Location.BOTTOM);
  118. assertSameElements(
  119. 'Class names for BOTTOM location must be as expected',
  120. ['goog-tab-bar', 'goog-tab-bar-horizontal', 'goog-tab-bar-bottom'],
  121. renderer.getClassNames(tabBar));
  122. tabBar.setLocation(goog.ui.TabBar.Location.END);
  123. assertSameElements(
  124. 'Class names for END location must be as expected',
  125. ['goog-tab-bar', 'goog-tab-bar-vertical', 'goog-tab-bar-end'],
  126. renderer.getClassNames(tabBar));
  127. }
  128. function testDoesntCallGetCssClassInConstructor() {
  129. goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor(
  130. goog.ui.TabBarRenderer);
  131. }