| 1 |
// Copyright 2009 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.ColorMenuButtonTest'); |
| 16 |
goog.setTestOnly('goog.ui.ColorMenuButtonTest'); |
| 17 |
|
| 18 |
goog.require('goog.dom'); |
| 19 |
goog.require('goog.dom.TagName'); |
| 20 |
goog.require('goog.testing.jsunit'); |
| 21 |
goog.require('goog.testing.ui.RendererHarness'); |
| 22 |
goog.require('goog.testing.ui.rendererasserts'); |
| 23 |
goog.require('goog.ui.ColorMenuButton'); |
| 24 |
goog.require('goog.ui.ColorMenuButtonRenderer'); |
| 25 |
goog.require('goog.userAgent'); |
| 26 |
|
| 27 |
var harness; |
| 28 |
|
| 29 |
function setUp() { |
| 30 |
harness = new goog.testing.ui.RendererHarness( |
| 31 |
goog.ui.ColorMenuButtonRenderer.getInstance(), |
| 32 |
goog.dom.getElement('parent'), goog.dom.getElement('decoratedButton')); |
| 33 |
} |
| 34 |
|
| 35 |
function tearDown() { |
| 36 |
harness.dispose(); |
| 37 |
} |
| 38 |
|
| 39 |
function testEquality() { |
| 40 |
harness.attachControlAndRender(new goog.ui.ColorMenuButton('Foo')); |
| 41 |
harness.attachControlAndDecorate(new goog.ui.ColorMenuButton()); |
| 42 |
harness.assertDomMatches(); |
| 43 |
} |
| 44 |
|
| 45 |
function testWrapCaption() { |
| 46 |
var caption = goog.dom.createDom(goog.dom.TagName.DIV, null, 'Foo'); |
| 47 |
var wrappedCaption = goog.ui.ColorMenuButtonRenderer.wrapCaption( |
| 48 |
caption, goog.dom.getDomHelper()); |
| 49 |
assertNotEquals('Caption should have been wrapped', caption, wrappedCaption); |
| 50 |
assertEquals( |
| 51 |
'Wrapped caption should have indicator css class', |
| 52 |
'goog-color-menu-button-indicator', wrappedCaption.className); |
| 53 |
} |
| 54 |
|
| 55 |
function testSetCaptionValue() { |
| 56 |
var caption = goog.dom.createDom(goog.dom.TagName.DIV, null, 'Foo'); |
| 57 |
var wrappedCaption = goog.ui.ColorMenuButtonRenderer.wrapCaption( |
| 58 |
caption, goog.dom.getDomHelper()); |
| 59 |
goog.ui.ColorMenuButtonRenderer.setCaptionValue(wrappedCaption, 'red'); |
| 60 |
|
| 61 |
var expectedColor = |
| 62 |
goog.userAgent.IE && !goog.userAgent.isDocumentModeOrHigher(9) ? |
| 63 |
'#ff0000' : |
| 64 |
'rgb(255, 0, 0)'; |
| 65 |
assertEquals(expectedColor, caption.style.borderBottomColor); |
| 66 |
} |
| 67 |
|
| 68 |
function testDoesntCallGetCssClassInConstructor() { |
| 69 |
goog.testing.ui.rendererasserts.assertNoGetCssClassCallsInConstructor( |
| 70 |
goog.ui.ColorMenuButtonRenderer); |
| 71 |
} |