-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtutorialReader.js
More file actions
108 lines (95 loc) · 3.1 KB
/
tutorialReader.js
File metadata and controls
108 lines (95 loc) · 3.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
var sinon = require('sinon');
var assert = require('chai').assert;
describe('GetListOfTutorials Module:', function() {
var fs;
var directoryReader;
before(function() {
fs = require('fs');
directoryReader = require('../lib/tutorialReader.js')(
"public/public-Macaulay2/", fs);
});
describe('When we call getTutorialList on the real file system', function() {
it('should get the list with welcome tutorials', function(done) {
var spy;
var response = {
writeHead: function() {
},
end: function() {
assert(spy.calledOnce);
assert.include(spy.getCall(0).args[0], "welcome2.html");
done();
}
};
spy = sinon.spy(response, "end");
directoryReader.getList(null, response);
});
});
describe('GetTutorialList with a stubbed file system', function() {
var readDirStub;
var existsStub;
beforeEach(function() {
readDirStub = sinon.stub(fs, 'readdir');
existsStub = sinon.stub(fs, 'exists');
});
afterEach(function() {
readDirStub.restore();
existsStub.restore();
});
it('should get the list with shared tutorials', function(done) {
var spy;
var response = {
writeHead: function() {
},
end: function() {
var expected = JSON.stringify([
"tutorials/mock.html",
"shared-tutorials/mock.html"
]);
assert.equal(spy.args, expected);
assert(spy.calledOnce);
done();
}
};
spy = sinon.spy(response, "end");
readDirStub.yields(null, ['mock.html', 'nothtml.foo']);
existsStub.yields(true);
directoryReader.getList(null, response);
});
it('should get the list without shared tutorials', function(done) {
var spy;
var response = {
writeHead: function() {
},
end: function() {
var expected = JSON.stringify(["tutorials/mock.html"]);
assert.equal(spy.args, expected);
assert(spy.calledOnce);
done();
}
};
spy = sinon.spy(response, "end");
readDirStub.yields(null, ['mock.html', 'nothtml.foo']);
existsStub.onFirstCall().yields(true);
existsStub.onSecondCall().yields(false);
directoryReader.getList(null, response);
});
});
describe('When calling moveWelcomeTutorialToBeginning', function() {
it('should move the tutorial to the beginning', function() {
var tutorials = ['a', 'b', 'c'];
var sorted = directoryReader.sortTutorials(tutorials, 'b');
assert.deepEqual(sorted, ['b', 'a', 'c']);
});
it('should move the tutorial to the beginning and keep the others',
function() {
var tutorials = ['c', 'b', 'a'];
var sorted = directoryReader.sortTutorials(tutorials, 'b');
assert.deepEqual(sorted, ['b', 'c', 'a']);
});
it('should move do nothing it index not found', function() {
var tutorials = ['c', 'b', 'a'];
var sorted = directoryReader.sortTutorials(tutorials, 'x');
assert.deepEqual(sorted, ['c', 'b', 'a']);
});
});
});