primaryactionbuttonrenderer_test.js 2.9 KB

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