-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Expand file tree
/
Copy pathsection_spec.js
More file actions
71 lines (63 loc) · 2.7 KB
/
section_spec.js
File metadata and controls
71 lines (63 loc) · 2.7 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
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
define(["js/models/section", "sinon", "edx-ui-toolkit/js/utils/spec-helpers/ajax-helpers", "js/utils/module"], (Section, sinon, AjaxHelpers, ModuleUtils) =>
describe("Section", function() {
describe("basic", function() {
beforeEach(function() {
this.model = new Section({
id: 42,
name: "Life, the Universe, and Everything"
});
});
it("should take an id argument", function() {
expect(this.model.get("id")).toEqual(42);
});
it("should take a name argument", function() {
expect(this.model.get("name")).toEqual("Life, the Universe, and Everything");
});
it("should have a URL set", function() {
expect(this.model.url()).toEqual(ModuleUtils.getUpdateUrl(42));
});
it("should serialize to JSON correctly", function() {
expect(this.model.toJSON()).toEqual({
metadata:
{
display_name: "Life, the Universe, and Everything"
}
});
});
});
describe("XHR", function() {
var server;
beforeEach(function() {
server = sinon.fakeServer.create();
spyOn(Section.prototype, 'showNotification');
spyOn(Section.prototype, 'hideNotification');
this.model = new Section({
id: 42,
name: "Life, the Universe, and Everything"
});
});
afterEach(function() {
server.restore();
});
it("show/hide a notification when it saves to the server", function() {
server.respondWith([200, {"Content-Type": "application/json"}, "{}"]);
this.model.save();
expect(Section.prototype.showNotification).toHaveBeenCalled();
server.respond();
expect(Section.prototype.hideNotification).toHaveBeenCalled();
});
it("don't hide notification when saving fails", function() {
// this is handled by the global AJAX error handler
server.respondWith([500, {"Content-Type": "application/json"}, "{}"]);
this.model.save();
server.respond();
expect(Section.prototype.hideNotification).not.toHaveBeenCalled();
});
});
})
);