-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.article.js
143 lines (121 loc) · 5.03 KB
/
test.article.js
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
// Add Her test for articles.js
define(['jquery', "underscore", "webpage", "backbone"], function($, _, webpage) {
"use strict";
/*
TESTER
- unitairement les méthodes simples des vues
- unitairement les collection/models de données
*/
var page, view, collection, model, pageDocument;
var getArticles = function() {
return $("article", pageDocument);
}
// Test des templates utilisés
describe('Article', function(){
before(function(done){
page = webpage.open("article");
$("body").on("page:complete", function(event) {
view = page.contentWindow.view;
pageDocument = page.contentWindow.document;
collection = view.collection;
model = collection.model;
done();
}.bind(this))
});
describe('Model', function(){
it('Should select a model', function(){
var _model = new model({
title: "Image5",
illustration: false,
src: "http://www.tuxboard.com/photos/2013/06/Chouette-en-folie-4.jpg"
});
var _change = sinon.spy();
_model.on('change:fake', _change);
// Test previous
assert.equal(_model.isSelected(), false);
assert.equal(_change.callCount, 0);
_model.select();
// Event "change:fake" must be triggered
assert.equal(_change.callCount, 1);
// Test new value
assert.equal(_model.isSelected(), true);
});
});
describe('Collection', function(){
it('Should store previousSize', function(){
var oldSize = collection.size();
// No previous Size
assert.equal(collection.previousSize, 0);
collection.add({
title: "Image5",
illustration: false,
src: "http://www.tuxboard.com/photos/2013/06/Chouette-en-folie-4.jpg"
});
assert.equal(collection.previousSize, oldSize);
});
});
describe('DOM', function(){
it('Should have as many items as models', function(){
var articles = getArticles();
assert.equal(collection.length, articles.length);
});
it('Should select Item', function(){
var _index, _model, checkbox;
// Item selected
_model = collection.find(function(model, index) {
var _value = model.get("illustration")
if (_value) {
_index = index;
}
return _value;
})
checkbox = $('[name="medias[][illustration]"]', pageDocument).get(_index);
assert.equal($(checkbox).attr("checked"), "checked");
// Item unselected
_model = collection.find(function(model, index) {
var _value = model.get("illustration")
if (!_value) {
_index = index;
}
return !_value;
});
checkbox = $('[name="medias[][illustration]"]', pageDocument).get(_index);
assert.equal($(checkbox).attr("checked"), undefined);
});
it('Should call Modal', function(){
var modalOpener, id, articles;
articles = getArticles();
id = "zoom-modal";
modalOpener = $('.illustration[data-modal="#' + id + '"]', articles.get(0));
assert.lengthOf(modalOpener, 1);
id = "delete-modal";
modalOpener = $('.trash-button[data-modal="#' + id + '"]', articles.get(0));
assert.lengthOf(modalOpener, 1);
});
it('Picture should be draggable', function(){
var draggableEl, articles;
articles = getArticles();
draggableEl = $('img[data-wysiwyg-draggable="true"]', articles.get(0));
assert.lengthOf(draggableEl, 1);
});
});
describe('Views', function(){
it('Should show/hide Modal', function(){
var _article = getArticles().get(0);
var _id = "delete-modal"
var _link = $('[data-modal="#' + _id + '"]', _article);
// Show Modal
assert.equal($("#" + _id, pageDocument).length, 0);
_link.trigger("click");
assert.equal($("#" + _id, pageDocument).length, 1);
// Hide Modal
var _modal = $("#" + _id);
_modal.trigger("click");
assert.equal($("#" + _id).length, 0);
});
});
after(function(){
webpage.close("article");
});
});
});