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