Skip to content

Commit d0cf774

Browse files
committed
test case updated
1 parent 3348d4f commit d0cf774

28 files changed

+5551
-1
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { Attributes, attributeToString } from "../src/Models/metadata-model"
2+
import { assetReferenceJson } from "./mock/json-element-mock"
3+
4+
describe('Attributes to String', () => {
5+
it('Should return blank string on blank attributes', done => {
6+
const attr = {} as Attributes
7+
8+
const resultString = attributeToString(attr)
9+
10+
expect(resultString).toEqual('')
11+
done()
12+
})
13+
it('Should return style type string', done => {
14+
const attr = {
15+
"style": {
16+
"text-align": "left"
17+
}
18+
} as Attributes
19+
20+
const resultString = attributeToString(attr)
21+
22+
expect(resultString).toEqual(' style="text-align:left; "')
23+
done()
24+
})
25+
it('Should return string of attributes key value format', done => {
26+
const attr = assetReferenceJson.children[0].attrs as Attributes
27+
28+
const resultString = attributeToString(attr)
29+
30+
expect(resultString).toEqual(' display-type="display" asset-uid="asset_uid_1" content-type-uid="sys_assets" asset-link="https://image.url/11.jpg" asset-name="11.jpg" asset-type="image/jpeg" type="asset" class-name="embedded-asset" width="25.16914749661705" className="dsd" id="sdf"')
31+
done()
32+
})
33+
34+
it('Should return string format for array attribute value', done => {
35+
const attr = {
36+
"style": {
37+
"text-align": "left"
38+
},
39+
"rows": 4,
40+
"cols": 2,
41+
"colWidths": [
42+
250,
43+
250
44+
]
45+
} as Attributes
46+
47+
const resultString = attributeToString(attr)
48+
49+
expect(resultString).toEqual(' style="text-align:left; " rows="4" cols="2" colWidths="250, 250"')
50+
done()
51+
})
52+
53+
})
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import MarkType from '../src/nodes/mark-type'
2+
import Node from '../src/nodes/node'
3+
import NodeType from '../src/nodes/node-type'
4+
import { Next, RenderMark, RenderNode } from '../src/options'
5+
import { defaultNodeOption } from '../src/options/default-node-options'
6+
7+
const text = 'text'
8+
const next : Next = () => text
9+
const node: Node = {
10+
type: NodeType.DOCUMENT,
11+
attrs: {},
12+
children: []
13+
}
14+
15+
const imgNode: Node = {
16+
type: NodeType.IMAGE,
17+
attrs: {src: "https://image.url/Donald.jog.png"},
18+
children:[]
19+
20+
}
21+
22+
const linkNode: Node = {
23+
type: NodeType.LINK,
24+
attrs: {href: "https://image.url/Donald.jog.png"},
25+
children:[]
26+
27+
}
28+
29+
const embedNode: Node = {
30+
type: NodeType.EMBED,
31+
"attrs": {
32+
src: "https://www.youtube.com/"
33+
},
34+
children: []
35+
}
36+
37+
describe('Default node render options', () => {
38+
it('Should return document string', done => {
39+
const renderString = (defaultNodeOption[NodeType.DOCUMENT] as RenderNode)(node, next)
40+
expect(renderString).toEqual('')
41+
done()
42+
})
43+
it('Should return paragraph string', done => {
44+
const renderString = (defaultNodeOption[NodeType.PARAGRAPH] as RenderNode)(node, next)
45+
expect(renderString).toEqual('<p>text</p>')
46+
done()
47+
})
48+
it('Should return link string', done => {
49+
let renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNode, next)
50+
expect(renderString).toEqual(`<a href="${linkNode.attrs.href}">text</a>`)
51+
renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNode, next)
52+
expect(renderString).toEqual('<img src="https://image.url/Donald.jog.png" />text')
53+
renderString = (defaultNodeOption[NodeType.EMBED] as RenderNode)(embedNode, next)
54+
expect(renderString).toEqual('<iframe src="https://www.youtube.com/">text</iframe>')
55+
done()
56+
})
57+
it('Should return Heading string', done => {
58+
let renderString = (defaultNodeOption[NodeType.HEADING_1] as RenderNode)(node, next)
59+
expect(renderString).toEqual('<h1>text</h1>')
60+
61+
renderString = (defaultNodeOption[NodeType.HEADING_2] as RenderNode)(node, next)
62+
expect(renderString).toEqual('<h2>text</h2>')
63+
64+
renderString = (defaultNodeOption[NodeType.HEADING_3] as RenderNode)(node, next)
65+
expect(renderString).toEqual('<h3>text</h3>')
66+
67+
renderString = (defaultNodeOption[NodeType.HEADING_4] as RenderNode)(node, next)
68+
expect(renderString).toEqual('<h4>text</h4>')
69+
70+
renderString = (defaultNodeOption[NodeType.HEADING_5] as RenderNode)(node, next)
71+
expect(renderString).toEqual('<h5>text</h5>')
72+
73+
renderString = (defaultNodeOption[NodeType.HEADING_6] as RenderNode)(node, next)
74+
expect(renderString).toEqual('<h6>text</h6>')
75+
76+
done()
77+
})
78+
it('Should return List string', done => {
79+
let renderString = (defaultNodeOption[NodeType.ORDER_LIST] as RenderNode)(node, next)
80+
expect(renderString).toEqual('<ol>text</ol>')
81+
82+
renderString = (defaultNodeOption[NodeType.UNORDER_LIST] as RenderNode)(node, next)
83+
expect(renderString).toEqual('<ul>text</ul>')
84+
85+
renderString = (defaultNodeOption[NodeType.LIST_ITEM] as RenderNode)(node, next)
86+
expect(renderString).toEqual('<li>text</li>')
87+
88+
done()
89+
})
90+
it('Should return HR string', done => {
91+
const renderString = (defaultNodeOption[NodeType.HR] as RenderNode)(node, next)
92+
expect(renderString).toEqual('<hr>')
93+
done()
94+
})
95+
it('Should return table string', done => {
96+
let renderString = (defaultNodeOption[NodeType.TABLE] as RenderNode)(node, next)
97+
expect(renderString).toEqual('<table>text</table>')
98+
99+
renderString = (defaultNodeOption[NodeType.TABLE_HEADER] as RenderNode)(node, next)
100+
expect(renderString).toEqual('<thead>text</thead>')
101+
102+
renderString = (defaultNodeOption[NodeType.TABLE_BODY] as RenderNode)(node, next)
103+
expect(renderString).toEqual('<tbody>text</tbody>')
104+
105+
renderString = (defaultNodeOption[NodeType.TABLE_FOOTER] as RenderNode)(node, next)
106+
expect(renderString).toEqual('<tfoot>text</tfoot>')
107+
108+
renderString = (defaultNodeOption[NodeType.TABLE_ROW] as RenderNode)(node, next)
109+
expect(renderString).toEqual('<tr>text</tr>')
110+
111+
renderString = (defaultNodeOption[NodeType.TABLE_HEAD] as RenderNode)(node, next)
112+
expect(renderString).toEqual('<th>text</th>')
113+
114+
renderString = (defaultNodeOption[NodeType.TABLE_DATA] as RenderNode)(node, next)
115+
expect(renderString).toEqual('<td>text</td>')
116+
117+
done()
118+
})
119+
it('Should return block quote string', done => {
120+
const renderString = (defaultNodeOption[NodeType.BLOCK_QUOTE] as RenderNode)(node, next)
121+
expect(renderString).toEqual('<blockquote>text</blockquote>')
122+
done()
123+
})
124+
it('Should return code string', done => {
125+
const renderString = (defaultNodeOption[NodeType.CODE] as RenderNode)(node, next)
126+
expect(renderString).toEqual('<code>text</code>')
127+
done()
128+
})
129+
it('Should return reference string', done => {
130+
const renderString = (defaultNodeOption.reference as RenderNode)(node, next)
131+
expect(renderString).toEqual('')
132+
done()
133+
})
134+
})
135+
describe('Default node render options', () => {
136+
137+
it('Should return bold string', done => {
138+
const renderString = (defaultNodeOption[MarkType.BOLD] as RenderMark)(text)
139+
expect(renderString).toEqual('<strong>text</strong>')
140+
done()
141+
})
142+
it('Should return italic string', done => {
143+
const renderString = (defaultNodeOption[MarkType.ITALIC] as RenderMark)(text)
144+
expect(renderString).toEqual('<em>text</em>')
145+
done()
146+
})
147+
it('Should return underline string', done => {
148+
const renderString = (defaultNodeOption[MarkType.UNDERLINE] as RenderMark)(text)
149+
expect(renderString).toEqual('<u>text</u>')
150+
done()
151+
})
152+
it('Should return strike through string', done => {
153+
const renderString = (defaultNodeOption[MarkType.STRIKE_THROUGH] as RenderMark)(text)
154+
expect(renderString).toEqual('<strike>text</strike>')
155+
done()
156+
})
157+
it('Should return bold string', done => {
158+
const renderString = (defaultNodeOption[MarkType.INLINE_CODE] as RenderMark)(text)
159+
expect(renderString).toEqual('<span>text</span>')
160+
done()
161+
})
162+
it('Should return bold string', done => {
163+
const renderString = (defaultNodeOption[MarkType.SUBSCRIPT] as RenderMark)(text)
164+
expect(renderString).toEqual('<sub>text</sub>')
165+
done()
166+
})
167+
it('Should return bold string', done => {
168+
const renderString = (defaultNodeOption[MarkType.SUPERSCRIPT] as RenderMark)(text)
169+
expect(renderString).toEqual('<sup>text</sup>')
170+
done()
171+
})
172+
})

__test__/default-options.test.ts

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import StyleType from '../src/embedded-types/style-type';
2+
import { defaultOptions } from '../src/options/default-options';
3+
import { entryContentBlank, entryContentURL, entryContentTitle, entryContentTitleURL } from './mock/entry-mock';
4+
import { RenderItem } from '../src/options/index';
5+
import { assetContentBlank,
6+
assetContentUrl,
7+
assetContentonlyFileName,
8+
assetContentonlyFileNameAndURL,
9+
assetContentonlyTitle,
10+
assetContentonlyTitleAndUrl } from './mock/asset-mock';
11+
import { Metadata, Attributes } from '../src/Models/metadata-model';
12+
13+
const linkText = "linkText"
14+
const entryBlockFunction: RenderItem = defaultOptions[StyleType.BLOCK] as RenderItem
15+
const entryInlineFunction: RenderItem = defaultOptions[StyleType.INLINE] as RenderItem
16+
const entryLinkFunction: RenderItem = defaultOptions[StyleType.LINK] as RenderItem
17+
18+
const assetDisplaableFunction: RenderItem = defaultOptions[StyleType.DISPLAY] as RenderItem
19+
const assetDownloadFunction: RenderItem = defaultOptions[StyleType.DOWNLOAD] as RenderItem
20+
21+
const embedAttributes = { attributes: {} } as Metadata
22+
23+
const embedAttributesText = { text: linkText, attributes: { alt: linkText } } as unknown as Metadata
24+
25+
describe('Default Option test', () => {
26+
it('Default options Entry with only uid test', done => {
27+
expect(entryBlockFunction(entryContentBlank, embedAttributes)).toEqual(`<div><p>${entryContentBlank.uid}</p><p>Content type: <span>${entryContentBlank._content_type_uid}</span></p></div>`)
28+
expect(entryInlineFunction(entryContentBlank, embedAttributes)).toEqual(`<span>${entryContentBlank.uid}</span>`)
29+
expect(entryLinkFunction(entryContentBlank, embedAttributes)).toEqual(`<a href="undefined">${entryContentBlank.uid}</a>`)
30+
done()
31+
})
32+
33+
it('Default options Entry with uid, url test', done => {
34+
expect(entryBlockFunction(entryContentURL, embedAttributes)).toEqual(`<div><p>${entryContentURL.uid}</p><p>Content type: <span>${entryContentURL._content_type_uid}</span></p></div>`)
35+
expect(entryInlineFunction(entryContentURL, embedAttributes)).toEqual(`<span>${entryContentURL.uid}</span>`)
36+
expect(entryLinkFunction(entryContentURL, embedAttributes)).toEqual(`<a href="${entryContentURL.url}">${entryContentURL.uid}</a>`)
37+
done()
38+
})
39+
40+
it('Default options Entry with only uid, title test', done => {
41+
expect(entryBlockFunction(entryContentTitle, embedAttributes)).toEqual(`<div><p>${entryContentTitle.title}</p><p>Content type: <span>${entryContentTitle._content_type_uid}</span></p></div>`)
42+
expect(entryInlineFunction(entryContentTitle, embedAttributes)).toEqual(`<span>${entryContentTitle.title}</span>`)
43+
expect(entryLinkFunction(entryContentTitle, embedAttributes)).toEqual(`<a href="undefined">${entryContentTitle.title}</a>`)
44+
done()
45+
})
46+
47+
it('Default options Entry with only uid, url, title test', done => {
48+
expect(entryBlockFunction(entryContentTitleURL, embedAttributes)).toEqual(`<div><p>${entryContentTitleURL.title}</p><p>Content type: <span>${entryContentTitleURL._content_type_uid}</span></p></div>`)
49+
expect(entryInlineFunction(entryContentTitleURL, embedAttributes)).toEqual(`<span>${entryContentTitleURL.title}</span>`)
50+
expect(entryLinkFunction(entryContentTitleURL, embedAttributes)).toEqual(`<a href="${entryContentURL.url}">${entryContentTitleURL.title}</a>`)
51+
done()
52+
})
53+
54+
it('Default options Asset with only uid test', done => {
55+
expect(assetDisplaableFunction(assetContentBlank, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentBlank.uid}" />`)
56+
expect(assetDownloadFunction(assetContentBlank, embedAttributes)).toEqual(`<a href="undefined\">${assetContentBlank.uid}</a>`)
57+
done()
58+
})
59+
60+
it('Default options Asset with uid and url test', done => {
61+
expect(assetDisplaableFunction(assetContentUrl, embedAttributes)).toEqual(`<img src="${assetContentUrl.url}" alt="${assetContentUrl.uid}" />`)
62+
expect(assetDownloadFunction(assetContentUrl, embedAttributes)).toEqual(`<a href="${assetContentUrl.url}">${assetContentUrl.uid}</a>`)
63+
done()
64+
})
65+
66+
67+
it('Default options Asset with uid and filename test', done => {
68+
expect(assetDisplaableFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentonlyFileName.filename}" />`)
69+
expect(assetDownloadFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<a href="undefined">${assetContentonlyFileName.uid}</a>`)
70+
done()
71+
})
72+
73+
it('Default options Asset with uid, url and filename test', done => {
74+
expect(assetDisplaableFunction(assetContentonlyFileNameAndURL, embedAttributes)).toEqual(`<img src="${assetContentonlyFileNameAndURL.url}" alt="${assetContentonlyFileNameAndURL.filename}" />`)
75+
expect(assetDownloadFunction(assetContentonlyFileNameAndURL, embedAttributes)).toEqual(`<a href="${assetContentonlyFileNameAndURL.url}">${assetContentonlyFileNameAndURL.uid}</a>`)
76+
done()
77+
})
78+
79+
it('Default options Asset with uid and title test', done => {
80+
expect(assetDisplaableFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentonlyTitle.title}" />`)
81+
expect(assetDownloadFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<a href="undefined">${assetContentonlyTitle.title || assetContentonlyTitle.uid}</a>`)
82+
done()
83+
})
84+
85+
it('Default options Asset with uid, url and filename test', done => {
86+
expect(assetDisplaableFunction(assetContentonlyTitleAndUrl, embedAttributes)).toEqual(`<img src="${assetContentonlyTitleAndUrl.url}" alt="${assetContentonlyTitleAndUrl.title}" />`)
87+
expect(assetDownloadFunction(assetContentonlyTitleAndUrl, embedAttributes)).toEqual(`<a href="${assetContentonlyTitleAndUrl.url}">${assetContentonlyTitleAndUrl.title || assetContentonlyTitleAndUrl.uid}</a>`)
88+
done()
89+
})
90+
91+
it('Default options Link text test', done => {
92+
expect(entryLinkFunction(entryContentURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
93+
expect(entryLinkFunction(entryContentTitle, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
94+
expect(entryLinkFunction(entryContentBlank, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
95+
expect(entryLinkFunction(entryContentTitleURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
96+
expect(assetDisplaableFunction(assetContentBlank, embedAttributesText)).toEqual(`<img src="undefined" alt="${linkText}" />`)
97+
expect(assetDownloadFunction(assetContentBlank, embedAttributesText)).toEqual(`<a href="undefined">${linkText}</a>`)
98+
done()
99+
})
100+
})

__test__/embedded-types.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import StyleType from "../src/embedded-types/style-type"
2+
3+
describe('Embedded types test', () => {
4+
it('Embedded Asset type test', done => {
5+
expect(StyleType.DISPLAY).toEqual('display')
6+
expect(StyleType.DOWNLOAD).toEqual('download')
7+
done()
8+
})
9+
10+
it('Embedded Entry type test', done => {
11+
expect(StyleType.BLOCK).toEqual('block')
12+
expect(StyleType.INLINE).toEqual('inline')
13+
expect(StyleType.LINK).toEqual('link')
14+
done()
15+
})
16+
})

0 commit comments

Comments
 (0)