tab_test.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.TabTest');
  15. goog.setTestOnly('goog.ui.TabTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.testing.jsunit');
  18. goog.require('goog.ui.Component');
  19. goog.require('goog.ui.Tab');
  20. goog.require('goog.ui.TabRenderer');
  21. var sandbox;
  22. var tab;
  23. function setUp() {
  24. sandbox = goog.dom.getElement('sandbox');
  25. tab = new goog.ui.Tab('Hello');
  26. }
  27. function tearDown() {
  28. tab.dispose();
  29. goog.dom.removeChildren(sandbox);
  30. }
  31. function testConstructor() {
  32. assertNotNull('Tab must not be null', tab);
  33. assertEquals('Tab must have expected content', 'Hello', tab.getContent());
  34. assertEquals(
  35. 'Tab\'s renderer must default to TabRenderer',
  36. goog.ui.TabRenderer.getInstance(), tab.getRenderer());
  37. assertTrue(
  38. 'Tab must support the SELECTED state',
  39. tab.isSupportedState(goog.ui.Component.State.SELECTED));
  40. assertTrue(
  41. 'SELECTED must be an auto-state',
  42. tab.isAutoState(goog.ui.Component.State.SELECTED));
  43. assertTrue(
  44. 'Tab must dispatch transition events for the DISABLED state',
  45. tab.isDispatchTransitionEvents(goog.ui.Component.State.DISABLED));
  46. assertTrue(
  47. 'Tab must dispatch transition events for the SELECTED state',
  48. tab.isDispatchTransitionEvents(goog.ui.Component.State.SELECTED));
  49. }
  50. function testGetSetTooltip() {
  51. assertUndefined('Tooltip must be undefined by default', tab.getTooltip());
  52. tab.setTooltip('Hello, world!');
  53. assertEquals(
  54. 'Tooltip must have expected value', 'Hello, world!', tab.getTooltip());
  55. }
  56. function testSetAriaLabel() {
  57. assertNull('Tab must not have aria label by default', tab.getAriaLabel());
  58. tab.setAriaLabel('My tab');
  59. tab.render();
  60. var element = tab.getElementStrict();
  61. assertNotNull('Element must not be null', element);
  62. assertEquals(
  63. 'Tab element must have expected aria-label', 'My tab',
  64. element.getAttribute('aria-label'));
  65. assertEquals(
  66. 'Tab element must have expected aria role', 'tab',
  67. element.getAttribute('role'));
  68. tab.setAriaLabel('My new tab');
  69. assertEquals(
  70. 'Tab element must have updated aria-label', 'My new tab',
  71. element.getAttribute('aria-label'));
  72. assertEquals(
  73. 'Tab element must have expected aria role', 'tab',
  74. element.getAttribute('role'));
  75. }