Skip to content

Commit 5d6069f

Browse files
authored
test: add missing tests (#10)
1 parent 347ce85 commit 5d6069f

File tree

10 files changed

+152
-32
lines changed

10 files changed

+152
-32
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"jest-cli": "26.6.3",
5858
"json-stringify-safe": "5.0.1",
5959
"markdown-link-check": "3.8.7",
60-
"nock": "13.0.11",
6160
"prettier": "2.3.0",
6261
"semantic-release": "17.4.3",
6362
"ts-jest": "26.5.6",

src/__tests__/utils/convert-blocks.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import {
66
MockParagraphNull,
77
} from '../../mockData/blocks.paragraph'
88
import { MockHeadingOne, MockHeadingTwo, MockHeadingThree } from '../../mockData/blocks.headings'
9+
import { MockTodoUnchecked, MockTodoChecked } from '../../mockData/blocks.todo'
10+
import { MockToggle } from '../../mockData/blocks.toggle'
11+
import { MockChildPage } from '../../mockData/blocks.child-page'
912
import { defaultAnnotations, defaultPluginConfigRes } from '../../mockData/defaults'
1013

1114
describe('Convert blocks', () => {
@@ -107,5 +110,59 @@ describe('Convert blocks', () => {
107110

108111
expect(fn).toBe('<h4><span class=gs-undefined>Heading three</span></h4>')
109112
})
113+
114+
it('should return an unchecked todo item', () => {
115+
const todoItemUnchecked = [MockTodoUnchecked]
116+
117+
const fn = convertBlockToHTML(todoItemUnchecked, defaultPluginConfigRes)
118+
119+
expect(fn).toBe(
120+
'<div class="gs-todo"><label for="657e68c6-1b09-478f-9912-c647e17077b8"><input type="checkbox" id="657e68c6-1b09-478f-9912-c647e17077b8" /> <span class=gs-undefined>Lorem Ipsum Lorem Ipsum</span></label></div>'
121+
)
122+
})
123+
124+
it('should return a checked todo item', () => {
125+
const todoItemChecked = [MockTodoChecked]
126+
127+
const fn = convertBlockToHTML(todoItemChecked, defaultPluginConfigRes)
128+
129+
expect(fn).toBe(
130+
'<div class="gs-todo"><label for="657e68c6-1b09-478f-9912-c647e17077b8"><input type="checkbox" id="657e68c6-1b09-478f-9912-c647e17077b8" checked /> <span class=gs-undefined>Lorem Ipsum Lorem Ipsum</span></label></div>'
131+
)
132+
})
133+
134+
it('should return a toggle', () => {
135+
const toggle = [MockToggle]
136+
137+
const fn = convertBlockToHTML(toggle, defaultPluginConfigRes)
138+
139+
expect(fn).toBe(
140+
'<details class="gs-toggle"><summary><span class=gs-undefined>Lorem Ipsum Lorem Ipsum</span></summary>It\'s a toggle!</details>'
141+
)
142+
})
143+
144+
it('should return a child page', () => {
145+
const childPage = [MockChildPage]
146+
147+
const fn = convertBlockToHTML(childPage, defaultPluginConfigRes)
148+
149+
expect(fn).toBe('<p class="gs-child-page">This is a child page</p>')
150+
})
151+
152+
it('should return empty if block is not supported', () => {
153+
const noSupported = []
154+
155+
const fn = convertBlockToHTML(noSupported, defaultPluginConfigRes)
156+
157+
expect(fn).toBe('')
158+
})
159+
160+
it('should return a message if block is not supported', () => {
161+
const noSupported = [{}]
162+
163+
const fn = convertBlockToHTML(noSupported, { get: () => 'unsupported' })
164+
165+
expect(fn).toBe('❌ Unsupported block (undefined)')
166+
})
110167
})
111168
})

src/mockData/blocks.child-page.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { MockBlockBase, defaultAnnotations } from './defaults'
2+
import { BlockType } from '../types'
3+
4+
const MockChildPageBase = {
5+
...MockBlockBase,
6+
type: BlockType.CHILD_PAGE,
7+
}
8+
9+
export const MockChildPage = {
10+
...MockChildPageBase,
11+
[BlockType.CHILD_PAGE]: {
12+
checked: false,
13+
title: 'This is a child page',
14+
},
15+
}

src/mockData/blocks.headings.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// HeadingTwoBlock,
55
// } from '@notionhq/client/build/src/api-types'
66
import { MockBlockBase, defaultAnnotations } from './defaults'
7+
import { BlockType } from '../types'
78

89
const MockHeadingOneBase = {
910
...MockBlockBase,
@@ -22,7 +23,7 @@ const MockHeadingThreeBase = {
2223

2324
export const MockHeadingOne = {
2425
...MockHeadingOneBase,
25-
heading_1: {
26+
[BlockType.HEADING_1]: {
2627
text: [
2728
{
2829
type: 'text',
@@ -39,7 +40,7 @@ export const MockHeadingOne = {
3940

4041
export const MockHeadingTwo = {
4142
...MockHeadingTwoBase,
42-
heading_2: {
43+
[BlockType.HEADING_2]: {
4344
text: [
4445
{
4546
type: 'text',
@@ -56,7 +57,7 @@ export const MockHeadingTwo = {
5657

5758
export const MockHeadingThree = {
5859
...MockHeadingThreeBase,
59-
heading_3: {
60+
[BlockType.HEADING_3]: {
6061
text: [
6162
{
6263
type: 'text',

src/mockData/blocks.paragraph.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { MockBlockBase, defaultAnnotations } from './defaults'
2+
import { BlockType } from '../types'
23

34
const MockParagraphBase = {
45
...MockBlockBase,
@@ -7,7 +8,7 @@ const MockParagraphBase = {
78

89
export const MockParagraph = {
910
...MockParagraphBase,
10-
paragraph: {
11+
[BlockType.PARAGRAPH]: {
1112
text: [
1213
{
1314
type: 'text',
@@ -24,14 +25,14 @@ export const MockParagraph = {
2425

2526
export const MockParagraphNull = {
2627
...MockParagraphBase,
27-
paragraph: {
28+
[BlockType.PARAGRAPH]: {
2829
text: null,
2930
},
3031
}
3132

3233
export const MockParagraphEmpty = {
3334
...MockParagraphBase,
34-
paragraph: {
35+
[BlockType.PARAGRAPH]: {
3536
text: [
3637
{
3738
type: 'text',

src/mockData/blocks.todo.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { MockBlockBase, defaultAnnotations } from './defaults'
2+
import { BlockType } from '../types'
3+
4+
const MockTodoBase = {
5+
...MockBlockBase,
6+
type: BlockType.TO_DO,
7+
}
8+
9+
export const MockTodoUnchecked = {
10+
...MockTodoBase,
11+
[BlockType.TO_DO]: {
12+
checked: false,
13+
text: [
14+
{
15+
type: 'text',
16+
text: {
17+
content: 'Lorem Ipsum Lorem Ipsum',
18+
},
19+
annotations: [defaultAnnotations],
20+
plain_text: 'Lorem Ipsum Lorem Ipsum',
21+
href: null,
22+
},
23+
],
24+
},
25+
}
26+
27+
export const MockTodoChecked = {
28+
...MockTodoBase,
29+
[BlockType.TO_DO]: {
30+
checked: true,
31+
text: [
32+
{
33+
type: 'text',
34+
text: {
35+
content: 'Lorem Ipsum Lorem Ipsum',
36+
},
37+
annotations: [defaultAnnotations],
38+
plain_text: 'Lorem Ipsum Lorem Ipsum',
39+
href: null,
40+
},
41+
],
42+
},
43+
}

src/mockData/blocks.toggle.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { MockBlockBase, defaultAnnotations } from './defaults'
2+
import { BlockType } from '../types'
3+
4+
const MockToggleBase = {
5+
...MockBlockBase,
6+
type: BlockType.TOGGLE,
7+
}
8+
9+
export const MockToggle = {
10+
...MockToggleBase,
11+
[BlockType.TOGGLE]: {
12+
text: [
13+
{
14+
type: 'text',
15+
text: {
16+
content: 'Lorem Ipsum Lorem Ipsum',
17+
},
18+
annotations: [defaultAnnotations],
19+
plain_text: 'Lorem Ipsum Lorem Ipsum',
20+
href: null,
21+
},
22+
],
23+
},
24+
}

src/mockData/defaults.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ export const defaultAnnotations: Annotations = {
1010
underline: false,
1111
}
1212

13-
export const defaultPluginConfigRes: ICreatePluginConfigRes = {
14-
get: jest.fn(),
15-
}
16-
1713
export const defaultPluginConfig: ICreatePluginConfig = {
1814
token: '123456',
1915
databaseId: '12345',
2016
debug: false,
2117
unsupported: false,
2218
}
2319

20+
export const defaultPluginConfigRes: ICreatePluginConfigRes = {
21+
get: (arg) => '',
22+
}
23+
2424
export const MockBlockBase = {
2525
object: 'block',
2626
id: '657e68c6-1b09-478f-9912-c647e17077b8',

src/utils/convert-blocks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const convertBlockToHTML = (blocks, options: ICreatePluginConfigRes): str
6161
return `<li>${convertToHTML(value.text)}</li>`
6262
case BlockType.TO_DO:
6363
return `<div class="gs-todo"><label for="${id}"><input type="checkbox" id="${id}" ${
64-
value.checked && 'checked'
64+
value.checked ? 'checked' : ''
6565
} />${' '}${convertToHTML(value.text)}</label></div>`
6666
case BlockType.TOGGLE:
6767
return `<details class="gs-toggle"><summary>${convertToHTML(

yarn.lock

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5455,11 +5455,6 @@ lodash.isstring@^4.0.1:
54555455
resolved "https://registry.yarnpkg.com/lodash.isstring/-/lodash.isstring-4.0.1.tgz#d527dfb5456eca7cc9bb95d5daeaf88ba54a5451"
54565456
integrity sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=
54575457

5458-
lodash.set@^4.3.2:
5459-
version "4.3.2"
5460-
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
5461-
integrity sha1-2HV7HagH3eJIFrDWqEvqGnYjCyM=
5462-
54635458
lodash.toarray@^4.4.0:
54645459
version "4.4.0"
54655460
resolved "https://registry.yarnpkg.com/lodash.toarray/-/lodash.toarray-4.4.0.tgz#24c4bfcd6b2fba38bfd0594db1179d8e9b656561"
@@ -5858,16 +5853,6 @@ nice-try@^1.0.4:
58585853
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
58595854
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
58605855

5861-
nock@13.0.11:
5862-
version "13.0.11"
5863-
resolved "https://registry.yarnpkg.com/nock/-/nock-13.0.11.tgz#ba733252e720897ca50033205c39db0c7470f331"
5864-
integrity sha512-sKZltNkkWblkqqPAsjYW0bm3s9DcHRPiMOyKO/PkfJ+ANHZ2+LA2PLe22r4lLrKgXaiSaDQwW3qGsJFtIpQIeQ==
5865-
dependencies:
5866-
debug "^4.1.0"
5867-
json-stringify-safe "^5.0.1"
5868-
lodash.set "^4.3.2"
5869-
propagate "^2.0.0"
5870-
58715856
node-emoji@^1.10.0:
58725857
version "1.10.0"
58735858
resolved "https://registry.yarnpkg.com/node-emoji/-/node-emoji-1.10.0.tgz#8886abd25d9c7bb61802a658523d1f8d2a89b2da"
@@ -6638,11 +6623,6 @@ promzard@^0.3.0:
66386623
dependencies:
66396624
read "1"
66406625

6641-
propagate@^2.0.0:
6642-
version "2.0.1"
6643-
resolved "https://registry.yarnpkg.com/propagate/-/propagate-2.0.1.tgz#40cdedab18085c792334e64f0ac17256d38f9a45"
6644-
integrity sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==
6645-
66466626
psl@^1.1.28, psl@^1.1.33:
66476627
version "1.8.0"
66486628
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"

0 commit comments

Comments
 (0)