Repository navigation
Expand file tree
/
Copy pathfeatherlight_test.js
More file actions
162 lines (138 loc) · 5.75 KB
/
Copy pathfeatherlight_test.js
File metadata and controls
162 lines (138 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
var expect = chai.expect;
(function($) {
var $htmlFixtures = null;
var resetFixtures = function(){
if (!$htmlFixtures) $htmlFixtures = $('#fixtures').detach();
$('body >:not(#mocha)').remove()
$('body').append($htmlFixtures.clone(true));
};
$.fx.off = true;
describe('Featherlight', function() {
beforeEach(resetFixtures);
after(resetFixtures);
it ('works on items with data-featherlight by default', function(done) {
expect($('img')).to.not.be.visible;
$('#auto-bound').click();
patiently(done, [
function() {
expect($('.featherlight img')).to.be.visible;
expect($('.featherlight img')).to.have.attr('src').equal('fixtures/photo.jpeg');
$('.featherlight').click();
}, function() {
expect($('img')).to.not.be.visible;
}
]);
});
describe('jQuery#featherlight', function() {
it('is chainable', function() {
// Not a bad test to run on collection methods.
var $all_links = $('a')
expect($all_links.featherlight()).to.equal($all_links);
});
it("won't open a dialog if the event is already prevented", function(){
$('#auto-bound').on('click', function(event) { event.preventDefault(); }).click()
expect($.featherlight.current()).to.be.undefined;
});
});
describe('jQuery.featherlight', function() {
it('opens a dialog box', function() {
$.featherlight('<p class="testing">This is a test<p>');
expect($('.featherlight p.testing')).to.be.visible;
});
});
describe('jQuery.featherlight.current', function() {
it('returns null if no dialogbox is currently opened', function() {
expect($.featherlight.current()).to.be.undefined;
/* even if opened and then closed */
$.featherlight('<p class="testing">This is a test<p>');
$('.featherlight').click();
expect($.featherlight.current()).to.be.undefined;
/* even if savagely removed */
$.featherlight('<p class="testing">This is a test<p>');
$('.featherlight').remove();
expect($.featherlight.current()).to.be.undefined;
});
it('returns the featherlight object of the last currently opened dialog', function() {
var first = $.featherlight('<p>First<p>');
expect($.featherlight.current()).to.equal(first);
var second = $.featherlight('<p>Inner<p>', {namespace: 'different_namespace'});
expect($.featherlight.current()).to.equal(second);
$('.different_namespace').click();
expect($.featherlight.current()).to.equal(first);
});
});
describe('jQuery.featherlight.close', function() {
it('closes the currently opened window, if any', function() {
$.featherlight('<p class="testing">This is a test<p>');
$.featherlight.close();
expect($.featherlight.current()).to.be.undefined;
$.featherlight.close(); /* should not create error */
});
});
describe('configuration', function() {
it('can be set using data-feather-*', function() {
$('#data-attr-test a').featherlight().click();
expect($.featherlight.current()).to.have.properties({
variant: 'test',
closeOnEsc: false,
closeSpeed: 42,
});
expect($.featherlight.current().$instance.find('b')).to.have.text('Added in callback');
});
it('can be set using data-feather-* on filtered element too', function() {
$('#data-attr-filter-test a:first').click();
expect($.featherlight.current()).to.have.property('variant').equal('wrapper');
$('#data-attr-filter-test a:last').click();
expect($.featherlight.current()).to.have.property('variant').equal('inner');
$('<a data-featherlight-variant="dynamic" href=".some-content">z</a>')
.appendTo($('#data-attr-filter-test')).click()
expect($.featherlight.current()).to.have.property('variant').equal('dynamic');
});
it('can specify to close or not on escape key', function() {
var first = $.featherlight('<p/>'),
second = $.featherlight('<p/>'),
third = $.featherlight('<p/>', {closeOnEsc: false}),
last = $.featherlight('<p/>', {closeOnEsc: true}),
triggerEscape = function(){
$(document).trigger($.Event("keyup", { keyCode: 27 }));
};
triggerEscape();
expect($.featherlight.current()).to.equal(third);
triggerEscape();
expect($('.featherlight')).with.length(3);
$('.featherlight:last').click();
expect($.featherlight.current()).to.equal(second);
triggerEscape();
expect($.featherlight.current()).to.equal(first);
});
it('can specify a filter for events', function() {
$("#filter-test .group").featherlight({filter: '.yes', type: 'text'})
.append('<span class="yes" href="filter Appended">Photo</span>');
$("#filter-test span").each(function(){ $(this).click(); });
expect($('.featherlight')).with.length(2);
expect($('.featherlight:first .featherlight-content')).to.contain('filter Yes');
expect($('.featherlight:last .featherlight-content')).to.contain('filter Appended');
});
it('can specify explicit content', function() {
$.featherlight({text: 'A <div> & "quoted text"'});
expect($('.featherlight')).to.contain('A <div> & "quoted text"');
});
it('can specify ajax content', function(done) {
$.featherlight({ajax: 'featherlight.html .some-content'});
patiently(done, function() {
expect($('.featherlight')).to.contain('Hello');
});
})
it('can specify an alternate close button selector', function() {
var fl = $.featherlight('<div>Test<div class="close-me">close</div></div>', {otherClose: '.close-me'});
expect($.featherlight.current()).to.equal(fl);
$('.close-me').click();
expect($.featherlight.current()).to.be.undefined;
});
it('can specify an alternate root selector', function() {
$.featherlight('<div>Test<div class="close-me">close</div></div>', {root: '#fixtures'});
expect($('#fixtures').children().last()).to.have.class('featherlight');
});
});
});
}(jQuery));