-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoption_spec.rb
More file actions
316 lines (245 loc) · 12.7 KB
/
option_spec.rb
File metadata and controls
316 lines (245 loc) · 12.7 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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
require 'spec_helper'
def getMetadata(itemType=nil, styleType=nil, linkText=nil)
html = "<test type='#{itemType || 'entry'}' sys-style-type='#{styleType || 'block'}'>#{linkText || ''}</test>";
element = getElement(html, '//test')[0]
ContentstackUtils::Model::Metadata.new(element)
end
RSpec.describe ContentstackUtils::Model::Options do
subject {described_class.new({})}
linkText = "Text To set Link"
describe 'Custom Raise Render' do
it 'Custom render without render implementation should fail' do
expect{ ContentstackUtilsTest::CustomRaiseOption.new.render_option(ENTRY_CONTENT_BLANK, getMetadata()) }.to raise_error(NotImplementedError, "Implement this method in a child class")
end
end
describe 'Default Option' do
it 'Embedded Content Type Entry' do
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata())).
to eq "<div><p>uid</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata('entry', 'inline'))).
to eq "<span>uid</span>"
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata('entry', 'link'))).
to eq "<a href='uid'>uid</a>"
end
it 'Embedded Entry' do
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata())).
to eq "<div><p>title</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata('entry', 'inline'))).
to eq "<span>title</span>"
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata('entry', 'link'))).
to eq "<a href='title'>title</a>"
end
it 'Embedded Entry URL' do
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata())).
to eq "<div><p>title</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata('entry', 'inline'))).
to eq "<span>title</span>"
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata('entry', 'link'))).
to eq "<a href='url'>title</a>"
end
it 'Embedded Asset' do
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('asset', 'display'))).
to eq "<img src='url' alt='title' />"
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('entry', 'download'))).
to eq "<a href='url'>title</a>"
end
it 'Embedded Content Type Entry with text' do
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata('entry', 'block', linkText))).
to eq "<div><p>uid</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata('entry', 'inline', linkText))).
to eq "<span>uid</span>"
expect(subject.render_option(ENTRY_CONTENT_BLANK, getMetadata('entry', 'link', linkText))).
to eq "<a href='uid'>#{linkText}</a>"
end
it 'Embedded Entry with text' do
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata('entry', 'block', linkText))).
to eq "<div><p>title</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata('entry', 'inline', linkText))).
to eq "<span>title</span>"
expect(subject.render_option(ENTRY_CONTENT_TITLE, getMetadata('entry', 'link', linkText))).
to eq "<a href='title'>#{linkText}</a>"
end
it 'Embedded Entry URL with text' do
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata('entry', 'block', linkText))).
to eq "<div><p>title</p><p>Content type: <span>content_type_uid</span></p></div>"
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata('entry', 'inline', linkText))).
to eq "<span>title</span>"
expect(subject.render_option(ENTRY_CONTENT_TITLE_URL, getMetadata('entry', 'link', linkText))).
to eq "<a href='url'>#{linkText}</a>"
end
it 'Embedded Asset with text' do
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('asset', 'display', linkText))).
to eq "<img src='url' alt='title' />"
expect(subject.render_option(ASSET_CONTENT_URL, getMetadata('entry', 'download', linkText))).
to eq "<a href='url'>#{linkText}</a>"
end
it 'Should return Mark text html' do
expect(subject.render_mark('bold', linkText)).
to eq "<strong>#{linkText}</strong>"
expect(subject.render_mark('italic', linkText)).
to eq "<em>#{linkText}</em>"
expect(subject.render_mark('underline', linkText)).
to eq "<u>#{linkText}</u>"
expect(subject.render_mark('strikethrough', linkText)).
to eq "<strike>#{linkText}</strike>"
expect(subject.render_mark('inlineCode', linkText)).
to eq "<span>#{linkText}</span>"
expect(subject.render_mark('subscript', linkText)).
to eq "<sub>#{linkText}</sub>"
expect(subject.render_mark('superscript', linkText)).
to eq "<sup>#{linkText}</sup>"
expect(subject.render_mark('', linkText)).
to eq linkText
end
it 'Should return blank string for doc node type' do
doc = getJson(BlankDocument)
result = subject.render_node('doc', doc, linkText)
expect(result).to eq ""
end
it 'Should return paragraph string for paragrpah node type' do
doc = getJson(BlankDocument)
result = subject.render_node('p', doc, linkText)
expect(result).to eq "<p>#{linkText}</p>"
end
it 'Should return link string with blank href for link node type' do
doc = getJson(BlankDocument)
result = subject.render_node('a', doc, linkText)
expect(result).to eq "<a href=''>#{linkText}</a>"
end
it 'Should return link string for link node type' do
doc = getJson(LinkInPJson)["children"][0]
result = subject.render_node('a', doc, linkText)
expect(result).to eq "<a href='#{doc["attrs"]["href"]}'>#{linkText}</a>"
end
it 'Should return image string with blank src for image node type' do
doc = getJson(BlankDocument)
result = subject.render_node('img', doc, linkText)
expect(result).to eq "<img src='' />#{linkText}"
end
it 'Should return link string for link node type' do
doc = getJson(ImgJson)["children"][0]
result = subject.render_node('img', doc, linkText)
expect(result).to eq "<img src='#{doc["attrs"]["src"]}' />#{linkText}"
end
it 'Should return link string for link node type' do
doc = getJson(ImgJsonURL)["children"][0]
result = subject.render_node('img', doc, linkText)
expect(result).to eq "<img src='#{doc["attrs"]["url"]}' />#{linkText}"
end
it 'Should return embed string with blank src for embed node type' do
doc = getJson(BlankDocument)
result = subject.render_node('embed', doc, linkText)
expect(result).to eq "<iframe src=''></iframe>"
end
it 'Should return embed string for embed node type' do
doc = getJson(EmbedJson)["children"][0]
result = subject.render_node('embed', doc, linkText)
expect(result).to eq "<iframe src='#{doc["attrs"]["src"]}'></iframe>"
end
it 'Should return Heading 1 string for Heading 1 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h1', doc, linkText)
expect(result).to eq "<h1>#{linkText}</h1>"
end
it 'Should return Heading 2 string for Heading 2 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h2', doc, linkText)
expect(result).to eq "<h2>#{linkText}</h2>"
end
it 'Should return Heading 3 string for Heading 3 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h3', doc, linkText)
expect(result).to eq "<h3>#{linkText}</h3>"
end
it 'Should return Heading 4 string for Heading 4 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h4', doc, linkText)
expect(result).to eq "<h4>#{linkText}</h4>"
end
it 'Should return Heading 5 string for Heading 5 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h5', doc, linkText)
expect(result).to eq "<h5>#{linkText}</h5>"
end
it 'Should return Heading 6 string for Heading 6 node type' do
doc = getJson(BlankDocument)
result = subject.render_node('h6', doc, linkText)
expect(result).to eq "<h6>#{linkText}</h6>"
end
it 'Should return Hr string for Hr node type' do
doc = getJson(BlankDocument)
result = subject.render_node('hr', doc, linkText)
expect(result).to eq "<hr />"
end
it 'Should return order list string for order list node type' do
doc = getJson(BlankDocument)
result = subject.render_node('ol', doc, linkText)
expect(result).to eq "<ol>#{linkText}</ol>"
end
it 'Should return Unorder list string for Unorder list node type' do
doc = getJson(BlankDocument)
result = subject.render_node('ul', doc, linkText)
expect(result).to eq "<ul>#{linkText}</ul>"
end
it 'Should return list item string for list item node type' do
doc = getJson(BlankDocument)
result = subject.render_node('li', doc, linkText)
expect(result).to eq "<li>#{linkText}</li>"
end
it 'Should return table string for table node type' do
doc = getJson(BlankDocument)
result = subject.render_node('table', doc, linkText)
expect(result).to eq "<table>#{linkText}</table>"
end
it 'Should return thead string for thead node type' do
doc = getJson(BlankDocument)
result = subject.render_node('thead', doc, linkText)
expect(result).to eq "<thead>#{linkText}</thead>"
end
it 'Should return tfoot string for tfoot node type' do
doc = getJson(BlankDocument)
result = subject.render_node('tfoot', doc, linkText)
expect(result).to eq "<tfoot>#{linkText}</tfoot>"
end
it 'Should return tbody string fortbody node type' do
doc = getJson(BlankDocument)
result = subject.render_node('tbody', doc, linkText)
expect(result).to eq "<tbody>#{linkText}</tbody>"
end
it 'Should return table row string for table row node type' do
doc = getJson(BlankDocument)
result = subject.render_node('tr', doc, linkText)
expect(result).to eq "<tr>#{linkText}</tr>"
end
it 'Should return table head string for table head node type' do
doc = getJson(BlankDocument)
result = subject.render_node('th', doc, linkText)
expect(result).to eq "<th>#{linkText}</th>"
end
it 'Should return table data string for table data node type' do
doc = getJson(BlankDocument)
result = subject.render_node('td', doc, linkText)
expect(result).to eq "<td>#{linkText}</td>"
end
it 'Should return blockquote string for blockquote node type' do
doc = getJson(BlankDocument)
result = subject.render_node('blockquote', doc, linkText)
expect(result).to eq "<blockquote>#{linkText}</blockquote>"
end
it 'Should return code string for code node type' do
doc = getJson(BlankDocument)
result = subject.render_node('code', doc, linkText)
expect(result).to eq "<code>#{linkText}</code>"
end
it 'Should return blank string for reference node type' do
doc = getJson(BlankDocument)
result = subject.render_node('reference', doc, linkText)
expect(result).to eq ""
end
it 'Should return span string for span node type' do
doc = getJson(BlankDocument)
result = subject.render_node('span', doc, linkText)
expect(result).to eq "<span>#{linkText}</span>"
end
end
end