-
Notifications
You must be signed in to change notification settings - Fork 130
/
Copy patheditor_spec.js
62 lines (46 loc) · 1.7 KB
/
editor_spec.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
var editor;
describe("Editor", function() {
beforeAll(function() {
fixture = loadFixtures('index.html');
editor = new PL.Editor({
textarea: $('.ple-textarea')[0]
});
});
it("exists, and has a textarea", function() {
expect($('.ple-textarea')[0]).not.toBeUndefined();
expect(editor).not.toBeUndefined();
expect(editor.options.textarea).not.toBeUndefined();
expect(editor.options.textarea).toBe($('.ple-textarea')[0]);
});
it("counts valid modules and enables publish button", function() {
expect(editor.titleModule.el.find('input').val()).toBe("");
expect(editor.titleModule.valid()).toBe(false);
expect(editor.validate()).toBe(false);
editor.richTextModule.wysiwyg.setMode('markdown');
editor.richTextModule.value(""); // empty it
expect(editor.richTextModule.value()).toBe("");
expect(editor.richTextModule.valid()).toBe(false);
editor.titleModule.value("My title");
editor.richTextModule.value("My content");
expect(editor.validate()).toBe(true);
});
it("sends AJAX request on editor.publish()", function(done) {
jasmine.Ajax.install();
editor.options.destination = '/post';
var ajaxSpy = spyOn($, "ajax").and.callFake(function(options) {
if (options === editor.options.destination) {
// http://stackoverflow.com/questions/13148356/how-to-properly-unit-test-jquerys-ajax-promises-using-jasmine-and-or-sinon
var d = $.Deferred();
d.resolve(options);
d.reject(options);
return d.promise();
}
});
function onPublish(response) {
expect(response).not.toBeUndefined();
jasmine.Ajax.uninstall();
done();
}
editor.publish(onPublish);
});
});