Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
127 lines (100 sloc) 4.88 KB
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<script src="../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../bower_components/web-component-tester/browser.js"></script>
<!-- Step 1: import the element to test -->
<link rel="import" href="../elements/triad-card.html">
<link rel="import" href="../elements/card-rep.html">
</head>
<body>
<div id="container"></div>
<script>
var container = document.querySelector('#container');
function createCardElement () {
container.innerHTML = "";
var card = document.createElement('triad-card');
container.appendChild(card);
return card;
}
suite('<triad-card>', function() {
test('blank card representation', function () {
var card = createCardElement();
var expected = new CardRep();
var cardRepresentation = card.rep();
assert.equal(cardRepresentation.top, expected.top, 'Top value should be the same');
assert.equal(cardRepresentation.left, expected.left, 'Left value should be the same');
assert.equal(cardRepresentation.right, expected.right, 'Right value should be the same');
assert.equal(cardRepresentation.bottom, expected.bottom, 'Bottom value should be the same');
assert.equal(cardRepresentation.element, expected.element, 'Element value should be the same');
assert.equal(cardRepresentation.modifier, expected.modifier, 'Modifier value should be the same');
assert.equal(cardRepresentation.color, expected.color, 'Color value should be the same');
});
test('full card representation', function () {
var card = createCardElement();
card.top = "1";
card.left = "2";
card.right = "3";
card.bottom = "4";
card.element = "f";
card.modifier = "-1";
card.color = "blue";
var expected = new CardRep(1,2,3,4,"f",-1,"blue");
var cardRepresentation = card.rep();
assert.equal(cardRepresentation.top, expected.top, 'Top value should be the same');
assert.equal(cardRepresentation.left, expected.left, 'Left value should be the same');
assert.equal(cardRepresentation.right, expected.right, 'Right value should be the same');
assert.equal(cardRepresentation.bottom, expected.bottom, 'Bottom value should be the same');
assert.equal(cardRepresentation.element, expected.element, 'Element value should be the same');
assert.equal(cardRepresentation.modifier, expected.modifier, 'Modifier value should be the same');
assert.equal(cardRepresentation.color, expected.color, 'Color value should be the same');
});
test('color change', function () {
var card = createCardElement();
var classes = card.$.grid.className;
assert.notInclude(classes, "red", "The card shouldn't have a color class set");
assert.notInclude(classes, "blue", "The card shouldn't have a color class set");
card.color = "blue";
classes = card.$.grid.className;
assert.notInclude(classes, "red", "The card shouldn't have a color class set");
assert.include(classes, "blue", "The card should have a color class set");
card.color = "red";
classes = card.$.grid.className;
assert.include(classes, "red", "The card should have a color class set");
assert.notInclude(classes, "blue", "The card shouldn't have a color class set");
});
test('color flip: no color', function () {
var card = createCardElement();
var expectedColor = card.color;
card.flip();
assert.equal(card.color, expectedColor, "The color should not change");
});
test('color flip: the color should change, and back', function () {
var card = createCardElement();
card.color = "red";
var expectedColor = "blue";
card.flip();
assert.equal(card.color, expectedColor, "The color should change to blue");
expectedColor = "red";
card.flip();
assert.equal(card.color, expectedColor, "The color should change to red");
});
test('rep', function () {
var card = createCardElement();
card.top = 1;
card.left = 2;
card.right = 3;
card.bottom = 4;
card.element = "f";
card.modifier = -1;
card.color = "red";
var expected = new CardRep(1,2,3,4,"f",-1,"red").objectify();
var cardRep = card.rep().objectify();
assert.deepEqual(expected, cardRep, "The card rep didn't process correctly");
});
});
</script>
</body>
</html>