style_test.js 3.0 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.testing.ui.styleTest');
  15. goog.setTestOnly('goog.testing.ui.styleTest');
  16. goog.require('goog.dom');
  17. goog.require('goog.testing.TestCase');
  18. goog.require('goog.testing.jsunit');
  19. goog.require('goog.testing.ui.style');
  20. // Write iFrame tag to load reference FastUI markup. Then, our tests will
  21. // compare the generated markup to the reference markup.
  22. var refPath = 'style_reference.html';
  23. goog.testing.ui.style.writeReferenceFrame(refPath);
  24. function setUp() {
  25. // TODO(b/25875505): Fix unreported assertions (go/failonunreportedasserts).
  26. goog.testing.TestCase.getActiveTestCase().failOnUnreportedAsserts = false;
  27. }
  28. // assertStructureMatchesReference should succeed if the structure, node
  29. // names, and classes match.
  30. function testCorrect() {
  31. var el = goog.dom.getFirstElementChild(goog.dom.getElement('correct'));
  32. goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
  33. }
  34. // assertStructureMatchesReference should fail if one of the nodes is
  35. // missing a class.
  36. function testMissingClass() {
  37. var el = goog.dom.getFirstElementChild(goog.dom.getElement('missing-class'));
  38. var e = assertThrows(function() {
  39. goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
  40. });
  41. assertContains('all reference classes', e.message);
  42. }
  43. // assertStructureMatchesReference should NOT fail if one of the nodes has
  44. // an additional class.
  45. function testExtraClass() {
  46. var el = goog.dom.getFirstElementChild(goog.dom.getElement('extra-class'));
  47. goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
  48. }
  49. // assertStructureMatchesReference should fail if there is a missing child
  50. // node somewhere in the DOM structure.
  51. function testMissingChild() {
  52. var el = goog.dom.getFirstElementChild(goog.dom.getElement('missing-child'));
  53. var e = assertThrows(function() {
  54. goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
  55. });
  56. assertContains('same number of children', e.message);
  57. }
  58. // assertStructureMatchesReference should fail if there is an extra child
  59. // node somewhere in the DOM structure.
  60. function testExtraChild() {
  61. var el = goog.dom.getFirstElementChild(goog.dom.getElement('extra-child'));
  62. var e = assertThrows(function() {
  63. goog.testing.ui.style.assertStructureMatchesReference(el, 'reference');
  64. });
  65. assertContains('same number of children', e.message);
  66. }