|
3 | 3 | describe('Gallery', function () {
|
4 | 4 | var expect = chai.expect;
|
5 | 5 |
|
6 |
| - describe('#start', function () { |
7 |
| - var itemElem1, itemElem2, items, galleryElem; |
8 |
| - var MockItem = function (hasLabel, attributes) { |
9 |
| - this.hasLabel = hasLabel; |
10 |
| - this.attributes = attributes; |
11 |
| - return this; |
| 6 | + var itemElem1, itemElem2, items, galleryElem; |
| 7 | + var MockItem = function (hasLabel, attributes) { |
| 8 | + this.hasLabel = hasLabel; |
| 9 | + this.attributes = attributes; |
| 10 | + this.style = {}; |
| 11 | + this.img = { |
| 12 | + style: {}, |
| 13 | + attributes: this.attributes, |
| 14 | + src: "SRC" |
12 | 15 | };
|
13 |
| - MockItem.prototype.querySelector = function (selector) { |
14 |
| - if (selector === "label") { |
15 |
| - return this.hasLabel; |
16 |
| - } else if (selector === "img") { |
17 |
| - return { |
18 |
| - style: {}, |
19 |
| - attributes: this.attributes |
20 |
| - }; |
| 16 | + return this; |
| 17 | + }; |
| 18 | + MockItem.prototype.querySelector = function (selector) { |
| 19 | + if (selector === "label") { |
| 20 | + return this.hasLabel; |
| 21 | + } else if (selector === "img") { |
| 22 | + return this.img; |
| 23 | + } |
| 24 | + }; |
| 25 | + MockItem.prototype.appendChild = function () {}; |
| 26 | + var intervalStub, stepSpy; |
| 27 | + |
| 28 | + beforeEach(function () { |
| 29 | + /* Mock Item elements */ |
| 30 | + itemElem1 = new MockItem(true, {}); |
| 31 | + itemElem2 = new MockItem(false, {alt: { value: "ALT"}}); |
| 32 | + items = [itemElem1, itemElem2]; |
| 33 | + /* Mock DOM Gallery element */ |
| 34 | + galleryElem = { |
| 35 | + dataset: {}, |
| 36 | + // return SOMETHING! |
| 37 | + querySelector: function (selector) { |
| 38 | + return this; |
| 39 | + }, |
| 40 | + querySelectorAll: function (selector) { |
| 41 | + return items; |
| 42 | + }, |
| 43 | + parentNode: { |
| 44 | + replaceChild: function () {} |
21 | 45 | }
|
22 | 46 | };
|
23 |
| - MockItem.prototype.appendChild = function () {}; |
24 |
| - var intervalStub, stepSpy; |
25 |
| - |
26 |
| - beforeEach(function () { |
27 |
| - /* Mock Item elements */ |
28 |
| - itemElem1 = new MockItem(true, {}); |
29 |
| - itemElem2 = new MockItem(false, {alt: { value: "ALT"}}); |
30 |
| - items = [itemElem1, itemElem2]; |
31 |
| - /* Mock DOM Gallery element */ |
32 |
| - galleryElem = { |
33 |
| - dataset: {}, |
34 |
| - // return SOMETHING! |
35 |
| - querySelector: function (selector) { |
36 |
| - return this; |
37 |
| - }, |
38 |
| - querySelectorAll: function (selector) { |
39 |
| - return items; |
40 |
| - } |
41 |
| - }; |
42 |
| - intervalStub = sinon.stub(window, "setInterval"); |
43 |
| - stepSpy = sinon.spy(Gallery, "step"); |
44 |
| - }); |
45 |
| - |
46 |
| - afterEach(function () { |
47 |
| - intervalStub.restore(); |
48 |
| - stepSpy.restore(); |
49 |
| - }); |
| 47 | + intervalStub = sinon.stub(window, "setInterval"); |
| 48 | + stepSpy = sinon.spy(Gallery, "step"); |
| 49 | + }); |
| 50 | + afterEach(function () { |
| 51 | + intervalStub.restore(); |
| 52 | + stepSpy.restore(); |
| 53 | + }); |
50 | 54 |
|
| 55 | + describe('#start', function () { |
51 | 56 | it("initialises the gallery with defaults", function () {
|
52 | 57 | Gallery.start(galleryElem);
|
53 | 58 | expect(stepSpy.calledWith(items, 1)).to.be.true;
|
54 | 59 | expect(intervalStub.calledWith(sinon.match.any, 1000)).to.be.true;
|
| 60 | + expect(itemElem1.style.backgroundImage).to.be.undefined; |
| 61 | + expect(itemElem1.img.style.display).to.equal(""); |
55 | 62 | });
|
56 | 63 |
|
57 | 64 | it("initialises the gallery with custom iterations", function () {
|
@@ -82,6 +89,23 @@ describe('Gallery', function () {
|
82 | 89 | expect(appendChildSpy2.called).to.be.false;
|
83 | 90 | appendChildSpy2.restore();
|
84 | 91 | });
|
| 92 | + it("handles a full screen gallery", function () { |
| 93 | + 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 | + }); |
| 99 | + }); |
| 100 | + describe('#stop', function () { |
| 101 | + it("restores a full screen gallery", function () { |
| 102 | + 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(""); |
| 108 | + }); |
85 | 109 | });
|
86 | 110 | describe('#step', function () {
|
87 | 111 | var items;
|
|
0 commit comments