/
test.open.js
87 lines (73 loc) · 2.37 KB
/
test.open.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
/*global createContainer:false, removeContainer:false, rnd:false */
describe('.open(fileName)', function () {
var testEl
, id
, editor
, openMeFile
, openMeLaterFile
, eventFired
, newFile;
function flagEvent() {
eventFired = true;
}
before(function (done) {
id = rnd();
testEl = createContainer(id);
openMeFile = 'openMe' + id;
openMeLaterFile = 'openMeLater' + id;
editor = new EpicEditor({ basePath: '/epiceditor/', container: testEl });
newFile = 'foo' + id;
editor.load();
editor.importFile(openMeLaterFile, 'open me later').importFile(openMeFile, 'open this file');
done();
});
after(function (done) {
editor.unload();
removeContainer();
done();
});
afterEach(function (done) {
// reset states
editor.open(id);
eventFired = false;
done();
});
it('should create an exportable openMe file', function () {
expect(editor.exportFile(openMeFile)).to.be('open this file');
});
it('should create an exportable openMeLater file', function () {
expect(editor.exportFile(openMeLaterFile)).to.be('open me later');
});
it('should open the openMe file in the editor', function () {
editor.open(openMeFile);
expect(editor.getElement('editor').body.innerHTML).to.be('open this file');
});
it('should open the openMeLater file in the editor after calling .open', function () {
editor.open(openMeLaterFile);
expect(editor.getElement('editor').body.innerHTML).to.be('open me later');
});
it('should fire the open event when the open method is called', function () {
editor.on('open', flagEvent);
editor.open();
editor.removeListener('open');
expect(eventFired).to.be(true);
});
it('should fire the create event when a new file is created with open()', function () {
editor.on('create', flagEvent);
editor.open(newFile);
editor.removeListener('create');
expect(eventFired).to.be(true);
});
it('should not fire the create event when an existing file is opened', function () {
editor.on('create', flagEvent);
editor.open(id);
editor.removeListener('create');
expect(eventFired).to.be(false);
});
it('should fire the read event when a file is read with open()', function () {
editor.on('read', flagEvent);
editor.open(newFile);
editor.removeListener('read');
expect(eventFired).to.be(true);
});
});