forked from lalalic/docx2html
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadSpec.js
141 lines (99 loc) · 3.13 KB
/
loadSpec.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
describe("character features",function(){
var docx2Html,
fs=require('fs'),
jsdom=require('jsdom-nogyp').jsdom,
testDir=__dirname+"/../node_modules/docx4js/test/";
function error(e){
expect(e).toBeUndefined()
}
it("able to load from node", function(){
try{
docx2Html=require('../main')
expect(docx2Html.parser).toBeDefined()
expect(docx2Html.converters).toBeDefined()
}catch(e){
error(e)
}
})
function should(docx, expects){
//if(docx=='fs.docx')
it(docx, function(done){
docx2Html(testDir+docx, {asImageURL:function(buffer){
var path=__dirname+"/images/"
path+=(typeof(buffer.crc32)=='undefined' ? require('jszip/lib/crc32')(buffer) : buffer.crc32)
switch(typeof(buffer)){
case 'string':
path+='.svg';
break
default:
path+='.jpg';
}
fs.writeFile(path, buffer)
return path.replace(/\\/g,'/')
}}).then(function(doc){
console.log(docx)
expect(doc).toBeDefined()
var html=doc.toString()
fs.writeFile(testDir+docx+".html",html)
var converted=jsdom(html)
expect(converted.documentElement.tagName).toBe('HTML')
//must have container
var container=converted.querySelector('#A')
expect(container).toBeDefined()
expect(container.style.width).toBe('100%')
//must have at least 1 section
var section=converted.querySelector('section')
expect(section).toBeDefined()
expect(section.style.width).toBeDefined()
expect(section.style.minHeight).toBeDefined()
expects(converted)
done()
},error)
},1000000)
}
should("fs.docx",function(doc, done){
var section=doc.querySelector('section'),
style=section.style,
content=section.querySelector('span');
expect(style.width).toBe('612pt')
expect(style.minHeight).toBe('792pt')
expect(content.textContent).toMatch("that are designed to coordinate with the overall look of")
})
should("word/table.docx",function(doc,done){
var tables=doc.querySelectorAll('table')
expect(tables.length).toBeGreaterThan(5)
var table=tables[0],
cols=cols=table.querySelectorAll('col');
expect(table.getAttribute('x11')).toBe('1')
for(var len=cols.len,i=0;i<len;i++)
expect(cols[i].style.width).toBe('12.5%')
})
should("word/models.docx", function(doc){
})
should("word/styles.docx", function(doc){
})
should("word/std.docx", function(doc){
})
should("word/image.docx", function(doc){
})
should("word/header-footer.docx", function(doc){
})
should("word/color.docx", function(doc){
})
should("word/columns.docx", function(doc){
})
should("word/shape/textbox.docx", function(doc){
})
should("word/shape/group.docx", function(doc){
})
should("word/shape/inline group.docx", function(doc){
})
should("word/shape/positionH.docx", function(doc){
})
should("word/shape/positionV.docx", function(doc){
})
should("word/shape/wrap.docx", function(doc){
})
should("word/shape/rotate.docx", function(doc){
})
})