forked from stringer-rss/stringer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstory_spec.js
More file actions
146 lines (126 loc) · 4.1 KB
/
story_spec.js
File metadata and controls
146 lines (126 loc) · 4.1 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
"use strict";
describe("Story", function(){
it("should exist", function(){
Story.should.exist;
});
it("uses defaults", function(){
var story = new Story();
story.get('open').should.be.false;
story.get('selected').should.be.false;
});
describe("open", function(){
it("sets open and selected to true", function(){
var story = new Story();
story.open();
story.get("open").should.be.true;
story.get("selected").should.be.true;
});
it("sets is_read to true if keep_unread isn't true", function(){
var story = new Story();
(!! story.get("keep_unread")).should.be.false;
story.open();
story.get("is_read").should.be.true;
});
it("doesn't sets is_read to true if keep_unread is true", function(){
var story = new Story();
story.set("keep_unread", true);
story.open();
(!! story.get("is_read")).should.be.false;
});
it("calls closeOthers, unselectAll, setSelection on collection", function(){
var story = new Story(),
spy = story.collection = {
closeOthers: sinon.spy(),
unselectAll: sinon.spy(),
setSelection: sinon.spy()
};
story.open();
spy.closeOthers.should.have.been.calledWith(story);
spy.unselectAll.should.have.been.calledOnce;
spy.setSelection.should.have.been.calledWith(story);
});
it("calls save if it should save", function(){
var story = new Story();
sinon.stub(story, "save");
sinon.stub(story, "shouldSave", function(){
return true;
});
story.open();
story.shouldSave.should.have.been.calledOnce;
story.save.should.have.been.calledOnce;
})
});
describe("close", function(){
it("sets open to false", function(){
var story = new Story();
story.set("open", true);
story.get("open").should.be.true;
story.close();
story.get("open").should.be.false;
});
});
describe("select", function(){
it("sets selected to true", function(){
var story = new Story();
story.select();
story.get("selected").should.be.true;
});
it("calls unselectAll on collection", function(){
var story = new Story(),
spy = story.collection = {
unselectAll: sinon.spy()
};
story.select();
spy.unselectAll.should.have.been.calledOnce;
});
});
describe("toggle", function(){
it("calles open/close based on state", function(){
var story = new Story();
sinon.stub(story, "open");
sinon.stub(story, "close");
story.toggle();
story.open.should.have.been.calledOnce;
story.close.should.not.have.been.called;
story.set("open", true);
story.toggle();
story.open.should.have.been.calledOnce;
story.close.should.have.been.calledOnce;
});
});
describe("shouldSave", function(){
it("returns false in there are no changed Attributes", function(){
var story = new Story();
sinon.stub(story, "changedAttributes", function(){
return false;
});
story.shouldSave().should.be.false;
story.changedAttributes.should.have.been.calledOnce;
});
it("returns false if it has changedAttributes but no id", function(){
var story = new Story();
sinon.stub(story, "changedAttributes", function(){
return {is_read: true};
});
story.shouldSave().should.be.false;
story.changedAttributes.should.have.been.calledOnce;
});
it("returns true if it has changedAttributes and an id", function(){
var story = new Story({id: 1});
sinon.stub(story, "changedAttributes", function(){
return {is_read: true};
});
story.shouldSave().should.be.true;
story.changedAttributes.should.have.been.calledOnce;
});
});
describe("openInTab", function(){
it("opens a new window", function(){
var story = new Story({permalink: "http://localhost"});
sinon.stub(window, "open");
story.openInTab();
window.open.should.have.been.calledWith("http://localhost", "_blank");
window.open.restore();
});
});
});