-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
121 lines (119 loc) · 4.27 KB
/
index.test.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
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
/**
* Created by chris on 8/17/2016.
*/
var chai = require('chai');
var tablemaker = require('./index.js');
var expect = chai.expect;
//noinspection JSUnresolvedFunction
describe('Objects To Table', function() {
var jsonObjects = [
{
name: "a name",
column1: "row 1 column 1",
column2: "row 1 column 2",
column3: "row 1 column 3",
},
{
name: "another name",
column1: "row 2 column 1",
column2: "row 2 column 2",
column3: "row 2 column 3",
},
{
name: "yet another name",
column1: "row 3 column 1",
column2: "row 3 column 2",
column3: "row 3 column 3",
},
];
var singleObject = {
name: "a name",
column1: "row 1 column 1",
column2: "row 1 column 2",
column3: "row 1 column 3",
};
//noinspection JSUnresolvedFunction
it('converts single json object to an html table', function(done){
var data = tablemaker.objectsToTable(singleObject);
expect(data).to.include("<table>");
expect(data).to.include("<th>");
expect(data).to.include("<tr>");
expect(data).to.include("<td>");
expect(data).to.include("</table>");
expect(data).to.include("</th>");
expect(data).to.include("</tr>");
expect(data).to.include("</td>");
done();
});
//noinspection JSUnresolvedFunction
it('convert array of json objects to an html table', function(done){
var data = tablemaker.objectsToTable(jsonObjects);
expect(data).to.include("<table>");
expect(data).to.include("<th>");
expect(data).to.include("<tr>");
expect(data).to.include("<td>");
expect(data).to.include("</table>");
expect(data).to.include("</th>");
expect(data).to.include("</tr>");
expect(data).to.include("</td>");
done();
});
//noinspection JSUnresolvedFunction
it('uses the Id CSVtoTable for the id of the div containing the table by default', function(done){
var data = tablemaker.objectsToTable(jsonObjects);
expect(data).to.include('<div id="CSVtoTable">');
done();
});
//noinspection JSUnresolvedFunction
it('uses the passed in Id for the id of the div containing the table, if provided', function(done){
var myId = "myID";
var data = tablemaker.objectsToTable(jsonObjects, myId);
expect(data).to.include(`<div id="${myId}">`);
done();
});
});
//noinspection JSUnresolvedFunction
describe('CSV To Table', function() {
//noinspection JSUnresolvedFunction
it('Throws Error if file not found', function(done){
tablemaker.csvToTable("./testcsvfile.csvnothere").catch(function(error){
expect(error.code).to.include('ENOENT');
done();
})
});
//noinspection JSUnresolvedFunction
it('parse a CSV file and return an html table', function(done){
tablemaker.csvToTable("./testcsvfile.csv").then(function(data){
expect(data).to.include("<table>");
expect(data).to.include("<th>");
expect(data).to.include("<tr>");
expect(data).to.include("<td>");
expect(data).to.include("</table>");
expect(data).to.include("</th>");
expect(data).to.include("</tr>");
expect(data).to.include("</td>");
done();
}).catch(function(error){
done(error);
})
});
//noinspection JSUnresolvedFunction
it('uses the Id CSVtoTable for the id of the div containing the table by default', function(done){
tablemaker.csvToTable("./testcsvfile.csv").then(function(data){
expect(data).to.include('<div id="CSVtoTable">');
done();
}).catch(function(error){
done(error);
})
});
//noinspection JSUnresolvedFunction
it('uses the passed in Id for the id of the div containing the table, if provided', function(done){
var myId = "myID";
tablemaker.csvToTable("./testcsvfile.csv", myId).then(function(data){
expect(data).to.include(`<div id="${myId}">`);
done();
}).catch(function(error){
done(error);
})
});
});