-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdefault-options.test.ts
More file actions
126 lines (105 loc) · 7.74 KB
/
default-options.test.ts
File metadata and controls
126 lines (105 loc) · 7.74 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
import StyleType from '../src/embedded-types/style-type';
import { defaultOptions } from '../src/options/default-options';
import { entryContentBlank, entryContentURL, entryContentTitle, entryContentTitleURL, entryContentURLWithoutSystemUid, entryContentURLWithSystemNoUid } from './mock/entry-mock';
import { RenderItem } from '../src/options/index';
import { assetContentBlank,
assetContentUrl,
assetContentWithoutTitleAndUID,
assetContentonlyFileName,
assetContentonlyFileNameAndURL,
assetContentonlyTitle,
assetContentonlyTitleAndUrl } from './mock/asset-mock';
import { Metadata, Attributes } from '../src/Models/metadata-model';
const linkText = "linkText"
const entryBlockFunction: RenderItem = defaultOptions[StyleType.BLOCK] as RenderItem
const entryInlineFunction: RenderItem = defaultOptions[StyleType.INLINE] as RenderItem
const entryLinkFunction: RenderItem = defaultOptions[StyleType.LINK] as RenderItem
const assetDisplaableFunction: RenderItem = defaultOptions[StyleType.DISPLAY] as RenderItem
const assetDownloadFunction: RenderItem = defaultOptions[StyleType.DOWNLOAD] as RenderItem
const embedAttributes = { attributes: {} } as Metadata
const embedAttributesText = { text: linkText, attributes: { alt: linkText } } as unknown as Metadata
describe('Default Option test', () => {
it('Default options Entry with only uid test', done => {
expect(entryBlockFunction(entryContentBlank, embedAttributes)).toEqual(`<div><p>${entryContentBlank.uid}</p><p>Content type: <span>${entryContentBlank._content_type_uid}</span></p></div>`)
expect(entryInlineFunction(entryContentBlank, embedAttributes)).toEqual(`<span>${entryContentBlank.uid}</span>`)
expect(entryLinkFunction(entryContentBlank, embedAttributes)).toEqual(`<a>${entryContentBlank.uid}</a>`)
done()
})
it('Default options Entry with uid, url test', done => {
expect(entryBlockFunction(entryContentURL, embedAttributes)).toEqual(`<div><p>${entryContentURL.uid}</p><p>Content type: <span>${entryContentURL._content_type_uid}</span></p></div>`)
expect(entryInlineFunction(entryContentURL, embedAttributes)).toEqual(`<span>${entryContentURL.uid}</span>`)
expect(entryLinkFunction(entryContentURL, embedAttributes)).toEqual(`<a href="${entryContentURL.url}">${entryContentURL.uid}</a>`)
done()
})
it('Default options Entry with only uid, title test', done => {
expect(entryBlockFunction(entryContentTitle, embedAttributes)).toEqual(`<div><p>${entryContentTitle.title}</p><p>Content type: <span>${entryContentTitle._content_type_uid}</span></p></div>`)
expect(entryInlineFunction(entryContentTitle, embedAttributes)).toEqual(`<span>${entryContentTitle.title}</span>`)
expect(entryLinkFunction(entryContentTitle, embedAttributes)).toEqual(`<a>${entryContentTitle.title}</a>`)
done()
})
it('Default options Entry with only uid, url, title test', done => {
expect(entryBlockFunction(entryContentTitleURL, embedAttributes)).toEqual(`<div><p>${entryContentTitleURL.title}</p><p>Content type: <span>${entryContentTitleURL._content_type_uid}</span></p></div>`)
expect(entryInlineFunction(entryContentTitleURL, embedAttributes)).toEqual(`<span>${entryContentTitleURL.title}</span>`)
expect(entryLinkFunction(entryContentTitleURL, embedAttributes)).toEqual(`<a href="${entryContentURL.url}">${entryContentTitleURL.title}</a>`)
done()
})
it('Default options Entry with only uid, url, system-uid test', done => {
expect(entryBlockFunction(entryContentURLWithoutSystemUid, embedAttributes)).toEqual(`<div><p>${entryContentURLWithoutSystemUid.uid}</p><p>Content type: <span></span></p></div>`)
done()
})
it('Default options Asset with only uid test', done => {
expect(assetDisplaableFunction(assetContentBlank, embedAttributes)).toEqual(`<img alt="${assetContentBlank.uid}" />`)
expect(assetDownloadFunction(assetContentBlank, embedAttributes)).toEqual(`<a>${assetContentBlank.uid}</a>`)
done()
})
it('Default options Asset with uid and url test', done => {
expect(assetDisplaableFunction(assetContentUrl, embedAttributes)).toEqual(`<img src="${assetContentUrl.url}" alt="${assetContentUrl.uid}" />`)
expect(assetDownloadFunction(assetContentUrl, embedAttributes)).toEqual(`<a href="${assetContentUrl.url}">${assetContentUrl.uid}</a>`)
done()
})
it('Default options Asset with uid and filename test', done => {
expect(assetDisplaableFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<img alt="${assetContentonlyFileName.filename}" />`)
expect(assetDownloadFunction(assetContentonlyFileName, embedAttributes)).toEqual(`<a>${assetContentonlyFileName.uid}</a>`)
done()
})
it('Default options Asset with uid, url and filename test', done => {
expect(assetDisplaableFunction(assetContentonlyFileNameAndURL, embedAttributes)).toEqual(`<img src="${assetContentonlyFileNameAndURL.url}" alt="${assetContentonlyFileNameAndURL.filename}" />`)
expect(assetDownloadFunction(assetContentonlyFileNameAndURL, embedAttributes)).toEqual(`<a href="${assetContentonlyFileNameAndURL.url}">${assetContentonlyFileNameAndURL.uid}</a>`)
done()
})
it('Default options Asset with uid and title test', done => {
expect(assetDisplaableFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<img alt="${assetContentonlyTitle.title}" />`)
expect(assetDownloadFunction(assetContentonlyTitle, embedAttributes)).toEqual(`<a>${assetContentonlyTitle.title || assetContentonlyTitle.uid}</a>`)
done()
})
it('Default options Asset with uid, url and filename test', done => {
expect(assetDisplaableFunction(assetContentonlyTitleAndUrl, embedAttributes)).toEqual(`<img src="${assetContentonlyTitleAndUrl.url}" alt="${assetContentonlyTitleAndUrl.title}" />`)
expect(assetDownloadFunction(assetContentonlyTitleAndUrl, embedAttributes)).toEqual(`<a href="${assetContentonlyTitleAndUrl.url}">${assetContentonlyTitleAndUrl.title || assetContentonlyTitleAndUrl.uid}</a>`)
done()
})
it('Default options Asset with uid, url and filename test', done => {
expect(assetDownloadFunction(assetContentWithoutTitleAndUID, embedAttributes)).toEqual(`<a href="${assetContentWithoutTitleAndUID.url}">${assetContentWithoutTitleAndUID.system.content_type_uid}</a>`)
done()
})
it('Default options Link text test', done => {
expect(entryLinkFunction(entryContentURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
expect(entryLinkFunction(entryContentTitle, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
expect(entryLinkFunction(entryContentBlank, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
expect(entryLinkFunction(entryContentTitleURL, embedAttributesText)).toEqual(`<a href="${entryContentURL.url}">${linkText}</a>`)
expect(assetDisplaableFunction(assetContentBlank, embedAttributesText)).toEqual(`<img alt="${linkText}" />`)
expect(assetDownloadFunction(assetContentBlank, embedAttributesText)).toEqual(`<a>${linkText}</a>`)
done()
})
})
describe('Default options negative and corner cases', () => {
it('should throw when item is null for entry block render', () => {
expect(() => entryBlockFunction(null as any, embedAttributes)).toThrow()
})
it('should throw when item is null for asset display render', () => {
expect(() => assetDisplaableFunction(null as any, embedAttributes)).toThrow()
})
it('should handle metadata with empty attributes', () => {
const emptyAttrs = { attributes: {} } as Metadata
expect(entryBlockFunction(entryContentBlank, emptyAttrs)).toContain(entryContentBlank.uid)
})
})