tabpane_test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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.TabPaneTest');
  15. goog.setTestOnly('goog.ui.TabPaneTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.testing.jsunit');
  18. goog.require('goog.ui.TabPane');
  19. var tabPane;
  20. var page1;
  21. var page2;
  22. var page3;
  23. function setUp() {
  24. goog.dom.getElement('testBody').innerHTML = '<div id="tabpane"></div>' +
  25. '<div id="page1Content">' +
  26. ' Content for page 1' +
  27. '</div>' +
  28. '<div id="page2Content">' +
  29. ' Content for page 2' +
  30. '</div>' +
  31. '<div id="page3Content">' +
  32. ' Content for page 3' +
  33. '</div>';
  34. tabPane = new goog.ui.TabPane(goog.dom.getElement('tabpane'));
  35. page1 =
  36. new goog.ui.TabPane.TabPage(goog.dom.getElement('page1Content'), 'page1');
  37. page2 =
  38. new goog.ui.TabPane.TabPage(goog.dom.getElement('page2Content'), 'page2');
  39. page3 =
  40. new goog.ui.TabPane.TabPage(goog.dom.getElement('page3Content'), 'page3');
  41. tabPane.addPage(page1);
  42. tabPane.addPage(page2);
  43. tabPane.addPage(page3);
  44. }
  45. function tearDown() {
  46. tabPane.dispose();
  47. }
  48. function testAllPagesEnabledAndSelectable() {
  49. tabPane.setSelectedIndex(0);
  50. var selected = tabPane.getSelectedPage();
  51. assertEquals('page1 should be selected', 'page1', selected.getTitle());
  52. assertEquals(
  53. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  54. tabPane.setSelectedIndex(1);
  55. selected = tabPane.getSelectedPage();
  56. assertEquals('page2 should be selected', 'page2', selected.getTitle());
  57. assertEquals(
  58. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  59. tabPane.setSelectedIndex(2);
  60. selected = tabPane.getSelectedPage();
  61. assertEquals('page3 should be selected', 'page3', selected.getTitle());
  62. assertEquals(
  63. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  64. }
  65. function testDisabledPageIsNotSelectable() {
  66. page2.setEnabled(false);
  67. assertEquals('goog-tabpane-tab-disabled', page2.getTitleElement().className);
  68. tabPane.setSelectedIndex(0);
  69. var selected = tabPane.getSelectedPage();
  70. assertEquals('page1 should be selected', 'page1', selected.getTitle());
  71. assertEquals(
  72. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  73. tabPane.setSelectedIndex(1);
  74. selected = tabPane.getSelectedPage();
  75. assertEquals(
  76. 'page1 should remain selected, as page2 is disabled', 'page1',
  77. selected.getTitle());
  78. assertEquals(
  79. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  80. tabPane.setSelectedIndex(2);
  81. selected = tabPane.getSelectedPage();
  82. assertEquals('page3 should be selected', 'page3', selected.getTitle());
  83. assertEquals(
  84. 'goog-tabpane-tab-selected', selected.getTitleElement().className);
  85. }