Skip to content

Commit b9e5402

Browse files
author
Marcin Szczepanski
committed
Fix some of the DOM tests
1 parent 5a525ad commit b9e5402

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

tests/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,25 @@
33
<meta charset="utf-8">
44
<title>Mocha Tests</title>
55
<link rel="stylesheet" href="mocha.css" />
6+
<style type="text/css">
7+
.container {
8+
display: none;
9+
}
10+
.gallery {
11+
display: none;
12+
}
13+
</style>
614
</head>
715
<body>
816
<div id="mocha"></div>
17+
<div class="container">
18+
<section class="slide">
19+
<ul class="gallery">
20+
<li><img src="item1.jpg" alt="ALT1"><label>Foo</label></li>
21+
<li><img src="item2.jpg" alt="ALT2"></li>
22+
</ul>
23+
</section>
24+
</div>
925
<script src="chai.js"></script>
1026
<script src="mocha.js"></script>
1127
<script src="sinon-1.8.2.js"></script>

tests/test.gallery.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
describe('Gallery', function () {
44
var expect = chai.expect;
55

6+
var contextNode = document.querySelector(".container");
7+
68
var itemElem1, itemElem2, items, galleryElem;
79
var MockItem = function (hasLabel, attributes) {
810
this.hasLabel = hasLabel;
@@ -90,21 +92,25 @@ describe('Gallery', function () {
9092
appendChildSpy2.restore();
9193
});
9294
it("handles a full screen gallery", function () {
95+
var galleryElem = document.querySelector(".gallery");
96+
var items = galleryElem.querySelectorAll('li');
9397
galleryElem.dataset.mode = "full-screen";
94-
Gallery.start(galleryElem);
95-
expect(itemElem1.img.style.display).to.equal("none");
96-
expect(itemElem2.img.style.display).to.equal("none");
97-
expect(itemElem1.style.backgroundImage).to.equal("url(SRC)");
98+
Gallery.start(galleryElem, contextNode);
99+
expect(items[0].querySelector('img').style.display).to.equal("none");
100+
expect(items[1].querySelector('img').style.display).to.equal("none");
101+
expect(items[0].style.backgroundImage).to.contain("item1.jpg");
98102
});
99103
});
100104
describe('#stop', function () {
101105
it("restores a full screen gallery", function () {
106+
var galleryElem = document.querySelector(".gallery");
107+
var items = galleryElem.querySelectorAll('li');
102108
galleryElem.dataset.mode = "full-screen";
103-
Gallery.start(galleryElem);
104-
Gallery.stop();
105-
expect(itemElem1.img.style.display).to.equal("");
106-
expect(itemElem2.img.style.display).to.equal("");
107-
expect(itemElem1.style.backgroundImage).to.equal("");
109+
Gallery.start(galleryElem, contextNode);
110+
Gallery.stop(galleryElem, contextNode);
111+
expect(items[0].querySelector('img').style.display).to.equal("");
112+
expect(items[1].querySelector('img').style.display).to.equal("");
113+
expect(items[0].style.backgroundImage).to.equal("");
108114
});
109115
});
110116
describe('#step', function () {

0 commit comments

Comments
 (0)