Skip to content

Commit da495e8

Browse files
authored
Merge pull request #32 from contentstack/chore/improving-coverage
test: ✅ improved coverage
2 parents 21d0c12 + df68ac5 commit da495e8

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

__test__/default-node-options.test.ts

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,35 @@ const imgNode: Node = {
1919

2020
}
2121

22+
const imgNodeWithURL: Node = {
23+
type: NodeType.IMAGE,
24+
attrs: {url: "https://image.url/Donald.jog.png"},
25+
children:[]
26+
27+
}
28+
2229
const linkNode: Node = {
2330
type: NodeType.LINK,
2431
attrs: {href: "https://image.url/Donald.jog.png"},
2532
children:[]
2633

2734
}
2835

36+
const linkNodeWithURL: Node = {
37+
type: NodeType.LINK,
38+
attrs: {url: "https://image.url/Donald.jog.png"},
39+
children:[]
40+
41+
}
42+
2943
const embedNode: Node = {
3044
type: NodeType.EMBED,
31-
"attrs": {
32-
src: "https://www.youtube.com/"
33-
},
45+
attrs: { src: "https://www.youtube.com/" },
46+
children: []
47+
}
48+
const embedNodeWithURL: Node = {
49+
type: NodeType.EMBED,
50+
attrs: { url: "https://www.youtube.com/" },
3451
children: []
3552
}
3653

@@ -54,6 +71,15 @@ describe('Default node render options', () => {
5471
expect(renderString).toEqual('<iframe src="https://www.youtube.com/">text</iframe>')
5572
done()
5673
})
74+
it('Should return link string with url as attr', done => {
75+
let renderString = (defaultNodeOption[NodeType.LINK] as RenderNode)(linkNodeWithURL, next)
76+
expect(renderString).toEqual(`<a href="${linkNodeWithURL.attrs.url}">text</a>`)
77+
renderString = (defaultNodeOption[NodeType.IMAGE] as RenderNode)(imgNodeWithURL, next)
78+
expect(renderString).toEqual(`<img src="${imgNodeWithURL.attrs.url}" />text`)
79+
renderString = (defaultNodeOption[NodeType.EMBED] as RenderNode)(embedNodeWithURL, next)
80+
expect(renderString).toEqual(`<iframe src="${embedNodeWithURL.attrs.url}">text</iframe>`)
81+
done()
82+
})
5783
it('Should return Heading string', done => {
5884
let renderString = (defaultNodeOption[NodeType.HEADING_1] as RenderNode)(node, next)
5985
expect(renderString).toEqual('<h1>text</h1>')

__test__/default-options.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import StyleType from '../src/embedded-types/style-type';
22
import { defaultOptions } from '../src/options/default-options';
3-
import { entryContentBlank, entryContentURL, entryContentTitle, entryContentTitleURL } from './mock/entry-mock';
3+
import { entryContentBlank, entryContentURL, entryContentTitle, entryContentTitleURL, entryContentURLWithoutSystemUid, entryContentURLWithSystemNoUid } from './mock/entry-mock';
44
import { RenderItem } from '../src/options/index';
55
import { assetContentBlank,
66
assetContentUrl,
@@ -51,6 +51,11 @@ describe('Default Option test', () => {
5151
done()
5252
})
5353

54+
it('Default options Entry with only uid, url, system-uid test', done => {
55+
expect(entryBlockFunction(entryContentURLWithoutSystemUid, embedAttributes)).toEqual(`<div><p>${entryContentURLWithoutSystemUid.uid}</p><p>Content type: <span></span></p></div>`)
56+
done()
57+
})
58+
5459
it('Default options Asset with only uid test', done => {
5560
expect(assetDisplaableFunction(assetContentBlank, embedAttributes)).toEqual(`<img src="undefined" alt="${assetContentBlank.uid}" />`)
5661
expect(assetDownloadFunction(assetContentBlank, embedAttributes)).toEqual(`<a href="undefined\">${assetContentBlank.uid}</a>`)

__test__/mock/entry-mock.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ export const entryContentTitleURL = {
2323
_content_type_uid: "content_type_uid"
2424
}
2525

26+
export const entryContentURLWithoutSystemUid = {
27+
uid: "uid",
28+
url: "url"
29+
}
30+
31+
export const entryContentURLWithSystemNoUid = {
32+
uid: "uid",
33+
url: "url",
34+
system: { url: "system_uid"}
35+
}
36+
2637
export const assetDownloadJson = {
2738
type: 'asset',
2839
'data-sys-asset-uid': 'asset_uid_1',

0 commit comments

Comments
 (0)