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