-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathapi_paragraph_spec.rb
More file actions
269 lines (230 loc) · 14.9 KB
/
api_paragraph_spec.rb
File metadata and controls
269 lines (230 loc) · 14.9 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
# frozen_string_literal: true
require 'spec_helper'
describe 'ApiParagraph section tests' do
it 'ApiParagraph | AddColumnBreak method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_column_break.js')
expect(docx.page_properties.columns.count).to eq(2)
expect(docx.elements.first.nonempty_runs[0].text).to eq('This is the text for the first column. It is written all in one text run. Nothing special.')
expect(docx.elements.first.nonempty_runs[2].text).to eq('This is the text which starts from the beginning of the second column. ')
expect(docx.elements.first.nonempty_runs[3].text).to eq('It is written in two text runs, you need a space at the end of the first run sentence to separate them.')
end
it 'ApiParagraph | AddDrawing method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_drawing.js')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.type).to eq(:chart)
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.axises.first.title.elements.first.runs.first.text).to eq('Year')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.axises.first.title.elements.first.runs.first.properties.font_size).to eq(11.0)
points = docx.elements.first.nonempty_runs.first
.drawings.first.graphic.data.series[0]
.values.number_reference.cache.points
expect(points[0].value.value).to eq('200')
expect(points[1].value.value).to eq('240')
expect(points[2].value.value).to eq('280')
points2 = docx.elements.first.nonempty_runs.first
.drawings.first.graphic.data.series[1]
.values.number_reference.cache.points
expect(points2[0].value.value).to eq('250')
expect(points2[1].value.value).to eq('260')
expect(points2[2].value.value).to eq('280')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.series.first.text.string.cache.points.first.value.value).to eq('Projected Revenue')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.series[1].text.string.cache.points.first.value.value).to eq('Estimated Costs')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.series.first.categories.string.cache.points.first.value.value).to eq('2014')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.series.first.categories.string.cache.points[1].value.value).to eq('2015')
expect(docx.elements.first.nonempty_runs.first.drawings.first.graphic.data.series.first.categories.string.cache.points[2].value.value).to eq('2016')
end
it 'ApiParagraph | AddElement method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_element.js')
expect(docx.elements.first.nonempty_runs.first.text).to eq('This is the text for a text run. Nothing special.')
end
it 'ApiParagraph | AddLineBreak method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_line_break.js')
expect(docx.elements.first.nonempty_runs[0].text).to eq('This is the text for the first line. Nothing special.')
expect(docx.elements.first.nonempty_runs[1].text).to eq("\r")
expect(docx.elements.first.nonempty_runs[2].text).to eq('This is the text which starts from the beginning of the second line. ')
expect(docx.elements.first.nonempty_runs[3].text).to eq('It is written in two text runs, you need a space at the end of the first run sentence to separate them.')
end
it 'ApiParagraph | AddPageBreak method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_page_break.js')
nonempty_runs = docx.elements.first.nonempty_runs
expect(nonempty_runs[0].text).to eq('This is the text for the first page. After it a page break will be added. Scroll down to the second page to see the text there.')
expect(nonempty_runs[2].text).to eq('This is the text which starts from the beginning of the second page. ')
expect(nonempty_runs[3].text).to eq('It is written in two text runs, you need a space at the end of the first run sentence to separate them.')
end
it 'ApiParagraph | AddPageNumber method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_page_number.js')
expect(docx.notes[0].elements.first.field_simple).to be_page_numbering
expect(docx.notes[1].elements.first.field_simple).to be_page_numbering
end
it 'ApiParagraph | AddPagesCount method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_pages_count.js')
expect(docx.notes[0].elements.first.field_simple
.instruction).to eq('NUMPAGES \* MERGEFORMAT')
end
it 'ApiParagraph | AddTabStop method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_tab_stop.js')
expect(docx.elements.first.nonempty_runs[0].text).to eq('This is just a sample text. After it three tab stops will be added.')
expect(docx.elements.first.nonempty_runs[1].text).to eq("\t")
expect(docx.elements.first.nonempty_runs[2].text).to eq("\t")
expect(docx.elements.first.nonempty_runs[3].text).to eq("\t")
expect(docx.elements.first.nonempty_runs[4].text).to eq('This is the text which starts after the tab stops.')
end
it 'ApiParagraph | AddText method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/add_text.js')
expect(docx.elements.first.nonempty_runs.first.text).to eq('This is just a sample text. Nothing special.')
end
it 'ApiParagraph | GetClassType method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_class_type.js')
expect(docx.elements.first.nonempty_runs.first.text).to eq('Class Type = paragraph')
end
it 'ApiParagraph | GetElement method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_element.js')
runs = docx.elements.last.nonempty_runs
expect(runs[0].text).to eq('This is the text for the first text run. Do not forget a space at its end to separate from the second one. ')
expect(runs[1].text).to eq('This is the text for the second run. We will set it bold afterwards. It also needs space at its end. ')
expect(runs[2].text).to eq('This is the text for the third run. It ends the paragraph.')
expect(runs[1].font_style.bold).to be_truthy
end
it 'ApiParagraph | GetElementsCount method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_elements_count.js')
expect(docx.elements.first.nonempty_runs.first.text)
.to eq('Number of paragraph elements at ' \
"this point: \t1\rNumber of paragraph " \
"elements after we added a text run: \t2")
end
it 'ApiParagraph | GetNumbering method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_numbering.js')
expect(docx.elements.first.nonempty_runs.first.text).to eq('This is the first element of a numbered list')
expect(docx.elements.first.numbering.numbering_properties).to eq(1)
expect(docx.elements[1].nonempty_runs.first.text).to eq('This is the second element of a numbered list')
expect(docx.elements[1].numbering.numbering_properties).to eq(1)
end
it 'ApiParagraph | GetParagraphMarkTextPr method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_paragraph_mark_text_pr.js')
expect(docx.elements.first.paragraph_properties.run_properties.size.value).to eq(52)
expect(docx.elements.first.paragraph_properties.run_properties.color).to eq(OoxmlParser::Color.new(255, 255, 0))
end
it 'ApiParagraph | GetParaPr method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/get_para_pr.js')
# TODO: 'https://github.com/ONLYOFFICE/ooxml_parser/issues/1214'
# expect(docx.elements.first.spacing.line).to eq(2)
expect(docx.elements.first.ind.first_line_indent).to eq(OoxmlParser::OoxmlSize.new(1.27, :centimeter))
end
it 'ApiParagraph | RemoveAllElements method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/remove_all_elements.js')
expect(docx.elements.first.nonempty_runs.first.text)
.to eq('This is the first document paragraph. We removed all the elements ' \
'to get the number of paragraph elements at this point: 1. ' \
"If we had not done that the number before this sentence would be '1'.")
end
it 'ApiParagraph | RemoveElement method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/remove_element.js')
expect(docx.elements.first.nonempty_runs[0].text).to eq('This is the first paragraph element. ')
expect(docx.elements.first.nonempty_runs[1].text).to eq('This is the third paragraph element (it will be removed from the paragraph and we will not see it). ')
end
it 'ApiParagraph | SetContextualSpacing method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_contextual_spacing.js')
expect(docx.elements[0].paragraph_properties.contextual_spacing).to be_falsey
expect(docx.elements[1].paragraph_properties.contextual_spacing).to be_falsey
expect(docx.elements[2].paragraph_properties.contextual_spacing).to be_falsey
expect(docx.elements[3].paragraph_properties.contextual_spacing).to be_truthy
expect(docx.elements[4].paragraph_properties.contextual_spacing).to be_truthy
end
it 'ApiParagraph | SetIndFirstLine method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_ind_first_line.js')
expect(docx.elements.first.ind.first_line_indent).to eq(OoxmlParser::OoxmlSize.new(1440, :twip))
end
it 'ApiParagraph | SetIndLeft method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_ind_left.js')
expect(docx.elements.first.ind.left_indent).to eq(OoxmlParser::OoxmlSize.new(2880, :twip))
end
it 'ApiParagraph | SetIndRight method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_ind_right.js')
expect(docx.elements.first.ind.right_indent).to eq(OoxmlParser::OoxmlSize.new(2880, :twip))
end
it 'ApiParagraph | SetJc method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_jc.js')
expect(docx.elements.first.align).to eq(:left)
expect(docx.elements[1].align).to eq(:right)
expect(docx.elements[2].align).to eq(:center)
expect(docx.elements[3].align).to eq(:justify)
end
it 'ApiParagraph | SetKeepLines method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_keep_lines.js')
docx.elements[0..5].each do |elements|
expect(elements.keep_lines).to be_falsey
end
expect(docx.elements[6].keep_lines).to be_truthy
end
it 'ApiParagraph | SetKeepNext method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_keep_next.js')
expect(docx.elements.first.keep_next).to be_falsey
docx.elements[1..5].each do |elements|
expect(elements.keep_next).to be_truthy
end
expect(docx.elements[6].keep_next).to be_falsey
end
it 'ApiParagraph | SetNumbering method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_numbering.js')
docx.elements[1..9].each_with_index do |current_element, index|
expect(current_element.numbering.ilvl).to eq(index)
expect(current_element.numbering.parent).not_to be_nil
end
end
it 'ApiParagraph | SetNumPr method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_num_pr.js')
expect(docx.elements.last.numbering.ilvl).to eq(3)
end
it 'ApiParagraph | SetPageBreakBefore method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_page_break_before.js')
expect(docx.elements.first.page_break).to be(false)
expect(docx.elements[1].page_break).to be(true)
end
it 'ApiParagraph | SetShd method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_shd.js')
expect(docx.elements.first.paragraph_properties.shade.color.upcase)
.to eq(OoxmlParser::Color.new(255, 0, 0).to_hex.to_sym)
expect(docx.elements.first.nonempty_runs[0].text).to eq('This is an example of setting a shade to a paragraph. ')
expect(docx.elements.first.nonempty_runs[1].text).to eq('These sentences are used to add lines for demonstrative purposes. ')
expect(docx.elements.first.nonempty_runs[2].text).to eq('These sentences are used to add lines for demonstrative purposes. ')
expect(docx.elements.first.nonempty_runs[3].text).to eq('These sentences are used to add lines for demonstrative purposes. ')
expect(docx.elements.first.nonempty_runs[4].text).to eq('These sentences are used to add lines for demonstrative purposes. ')
end
it 'ApiParagraph | SetSpacingAfter method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_spacing_after.js')
expect(docx.elements.first.paragraph_properties.spacing.after).to eq(OoxmlParser::OoxmlSize.new(1440, :twip))
end
it 'ApiParagraph | SetSpacingBefore method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_spacing_before.js')
expect(docx.elements[1].paragraph_properties.spacing.before).to eq(OoxmlParser::OoxmlSize.new(1440, :twip))
end
it 'ApiParagraph | SetSpacingLine method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_spacing_line.js')
# TODO: 'https://github.com/ONLYOFFICE/ooxml_parser/issues/1214'
# expect(docx.elements.first.paragraph_properties.spacing.line).to eq(OoxmlParser::OoxmlSize.new(3, :centimeter))
# expect(docx.elements.first.spacing.line_rule).to eq(:auto)
expect(docx.elements[1].paragraph_properties.spacing.line).to eq(OoxmlParser::OoxmlSize.new(200, :twip))
expect(docx.elements[1].paragraph_properties.spacing.line_rule).to eq(:exact)
expect(docx.elements[2].paragraph_properties.spacing.line).to eq(OoxmlParser::OoxmlSize.new(400, :twip))
expect(docx.elements[2].paragraph_properties.spacing.line_rule).to eq(:at_least)
end
it 'ApiParagraph | SetStyle method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_style.js')
expect(docx.elements.first.style.name).to eq('Heading 6')
end
it 'ApiParagraph | SetTabs method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_tabs.js')
expect(docx.elements.first.paragraph_properties.tabs[0].position).to eq(OoxmlParser::OoxmlSize.new(1440, :twip))
expect(docx.elements.first.paragraph_properties.tabs[0].value).to eq(:left)
expect(docx.elements.first.paragraph_properties.tabs[1].position).to eq(OoxmlParser::OoxmlSize.new(4320, :twip))
expect(docx.elements.first.paragraph_properties.tabs[1].value).to eq(:center)
expect(docx.elements.first.paragraph_properties.tabs[2].position).to eq(OoxmlParser::OoxmlSize.new(7200, :twip))
expect(docx.elements.first.paragraph_properties.tabs[2].value).to eq(:right)
end
it 'ApiParagraph | SetWidowControl method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_widow_control.js')
expect(docx.elements[5].orphan_control).to be_truthy
end
it 'ApiParagraph | SetFontFamily method' do
docx = builder.build_and_parse('js/docx/smoke/api_paragraph/set_font_family.js')
expect(docx.elements[0].nonempty_runs[0].font).to eq(docx.elements[0].nonempty_runs[1].text)
end
end