Debian Codegraph @

closure-library/closure/goog/ui/popupcolorpicker_test.js

raw
1 // Copyright 2007 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.PopupColorPickerTest');
16 goog.setTestOnly('goog.ui.PopupColorPickerTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.events');
20 goog.require('goog.testing.events');
21 goog.require('goog.testing.jsunit');
22 goog.require('goog.ui.ColorPicker');
23 goog.require('goog.ui.PopupColorPicker');
24
25 // Unittest to ensure that the popup gets created in createDom().
26 function testPopupCreation() {
27 var picker = new goog.ui.PopupColorPicker();
28 picker.createDom();
29 assertNotNull(picker.getPopup());
30 }
31
32 function testAutoHideIsSetProperly() {
33 var picker = new goog.ui.PopupColorPicker();
34 picker.createDom();
35 picker.setAutoHide(true);
36 var containingDiv = goog.dom.getElement('containingDiv');
37 picker.setAutoHideRegion(containingDiv);
38 assertTrue(picker.getAutoHide());
39 assertEquals(containingDiv, picker.getAutoHideRegion());
40 }
41
42 // Unittest to ensure the popup opens with a custom color picker.
43 function testCustomColorPicker() {
44 var button1 = document.getElementById('button1');
45 var domHelper = goog.dom.getDomHelper();
46 var colorPicker = new goog.ui.ColorPicker();
47 colorPicker.setColors(['#ffffff', '#000000']);
48 var picker = new goog.ui.PopupColorPicker(domHelper, colorPicker);
49 picker.render();
50 picker.attach(button1);
51 assertNotNull(picker.getColorPicker());
52 assertNotNull(picker.getPopup().getElement());
53 assertNull(picker.getSelectedColor());
54
55 var changeEvents = 0;
56 goog.events.listen(picker, goog.ui.ColorPicker.EventType.CHANGE, function(e) {
57 changeEvents++;
58 });
59
60 // Select the first color.
61 goog.testing.events.fireClickSequence(button1);
62 goog.testing.events.fireClickSequence(
63 document.getElementById('goog-palette-cell-0').firstChild);
64 assertEquals('#ffffff', picker.getSelectedColor());
65 assertEquals(1, changeEvents);
66 }