Debian Codegraph @

closure-library/closure/goog/ui/style/app/primaryactionbuttonrenderer_test.js

raw
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.style.app.PrimaryActionButtonRendererTest');
16 goog.setTestOnly('goog.ui.style.app.PrimaryActionButtonRendererTest');
17
18 goog.require('goog.dom');
19 goog.require('goog.testing.jsunit');
20 goog.require('goog.testing.ui.style');
21 goog.require('goog.ui.Button');
22 goog.require('goog.ui.Component');
23 goog.require('goog.ui.style.app.PrimaryActionButtonRenderer');
24 var renderer = goog.ui.style.app.PrimaryActionButtonRenderer.getInstance();
25 var button;
26
27 // Write iFrame tag to load reference FastUI markup. Then, our tests will
28 // compare the generated markup to the reference markup.
29 var refPath = '../../../../../' +
30 'webutil/css/fastui/app/primaryactionbutton_spec.html';
31 goog.testing.ui.style.writeReferenceFrame(refPath);
32
33 function shouldRunTests() {
34 // Disable tests when being run as a part of open-source repo as the button
35 // specs are not included in closure-library.
36 return !(/closure\/goog\/ui/.test(location.pathname));
37 }
38
39 function setUp() {
40 button = new goog.ui.Button('Hello Generated', renderer);
41 }
42
43 function tearDown() {
44 if (button) {
45 button.dispose();
46 }
47 goog.dom.removeChildren(goog.dom.getElement('sandbox'));
48 }
49
50 function testGeneratedButton() {
51 button.render(goog.dom.getElement('sandbox'));
52 goog.testing.ui.style.assertStructureMatchesReference(
53 button.getElement(), 'normal-resting');
54 }
55
56 function testButtonStates() {
57 button.render(goog.dom.getElement('sandbox'));
58 goog.testing.ui.style.assertStructureMatchesReference(
59 button.getElement(), 'normal-resting');
60 button.setState(goog.ui.Component.State.HOVER, true);
61 goog.testing.ui.style.assertStructureMatchesReference(
62 button.getElement(), 'normal-hover');
63 button.setState(goog.ui.Component.State.HOVER, false);
64 button.setState(goog.ui.Component.State.FOCUSED, true);
65 goog.testing.ui.style.assertStructureMatchesReference(
66 button.getElement(), 'normal-focused');
67 button.setState(goog.ui.Component.State.FOCUSED, false);
68 button.setState(goog.ui.Component.State.ACTIVE, true);
69 goog.testing.ui.style.assertStructureMatchesReference(
70 button.getElement(), 'normal-active');
71 button.setState(goog.ui.Component.State.ACTIVE, false);
72 button.setState(goog.ui.Component.State.DISABLED, true);
73 goog.testing.ui.style.assertStructureMatchesReference(
74 button.getElement(), 'normal-disabled');
75 }