<! DOCTYPE html>
<html>
<!-- 
Copyright 2008 The Closure Library Authors.  All Rights Reserved. 

Use of this source code is governed by the Apache License, Version 2.0. 
See the COPYING file for details. 
-->
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Closure Unit Tests - goog.ui. TabPane</title>
<script src="../base.js"></script>
<script>
  goog.require('goog.ui. TabPane');
  goog.require('goog.dom');
  goog.require('goog.events');
  goog.require('goog.testing.jsunit');
</script>
</head>
<body>

<div id='testBody'></div>

<script>

  var tabPane;
  var page1;
  var page2;
  var page3;

  function setUp() {
    goog.dom.getElement('testBody').innerHTML =
       "<div id='tabpane'></div>"
       "<div id='page1Content'>"
       "  Content for page 1"
       "</div>"
       "<div id='page2Content'>"
       "  Content for page 2"
       "</div>"
       "<div id='page3Content'>"
       "  Content for page 3"
       "</div>";

    tabPane = new goog.ui. TabPane(goog.dom.getElement('tabpane'));
    page1 = new goog.ui. TabPane. TabPage(goog.dom.getElement('page1Content'),
        'page1');
    page2 = new goog.ui. TabPane. TabPage(goog.dom.getElement('page2Content'),
        'page2');
    page3 = new goog.ui. TabPane. TabPage(goog.dom.getElement('page3Content'),
        'page3');

    tabPane.addPage(page1);
    tabPane.addPage(page2);
    tabPane.addPage(page3);
  }

  function tearDown() {
    tabPane.dispose();
  }

  function testAllPagesEnabledAndSelectable() {
    tabPane.setSelectedIndex(0);
    var selected = tabPane.getSelectedPage();
    assertEquals('page1 should be selected', 'page1', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);

    tabPane.setSelectedIndex(1);
    selected = tabPane.getSelectedPage();
    assertEquals('page2 should be selected', 'page2', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);

    tabPane.setSelectedIndex(2);
    selected = tabPane.getSelectedPage();
    assertEquals('page3 should be selected', 'page3', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);
  }

  function testDisabledPageIsNotSelectable() {
    page2.setEnabled(false);
    assertEquals('goog-tabpane-tab-disabled',
                 page2.getTitleElement().className);

    tabPane.setSelectedIndex(0);
    var selected = tabPane.getSelectedPage();
    assertEquals('page1 should be selected', 'page1', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);

    tabPane.setSelectedIndex(1);
    selected = tabPane.getSelectedPage();
    assertEquals('page1 should remain selected, as page2 is disabled',
                 'page1', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);

    tabPane.setSelectedIndex(2);
    selected = tabPane.getSelectedPage();
    assertEquals('page3 should be selected', 'page3', selected.getTitle());
    assertEquals('goog-tabpane-tab-selected',
                 selected.getTitleElement().className);
  }
</script>
</body>
</html>
