Skip to content

Commit b1fc879

Browse files
committed
More link tests
1 parent 9e1638d commit b1fc879

File tree

3 files changed

+217
-31
lines changed

3 files changed

+217
-31
lines changed

src/TestRun.ts

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,39 @@ export function makeSamplePageObject(options: {
9999
name?: string;
100100
id?: string;
101101
}): NotionPage {
102+
let slugObject: any = {
103+
Slug: {
104+
id: "%7D%3D~K",
105+
type: "rich_text",
106+
rich_text: [],
107+
},
108+
};
109+
110+
if (options.slug)
111+
slugObject = {
112+
id: "%7D%3D~K",
113+
type: "rich_text",
114+
rich_text: [
115+
{
116+
type: "text",
117+
text: {
118+
content: options.slug,
119+
link: null,
120+
},
121+
annotations: {
122+
bold: false,
123+
italic: false,
124+
strikethrough: false,
125+
underline: false,
126+
code: false,
127+
color: "default",
128+
},
129+
plain_text: options.slug,
130+
href: null,
131+
},
132+
],
133+
};
134+
102135
const id = options.id || "4a6de8c0-b90b-444b-8a7b-d534d6ec71a4";
103136
const m: GetPageResponse = {
104137
object: "page",
@@ -150,29 +183,7 @@ export function makeSamplePageObject(options: {
150183
type: "multi_select",
151184
multi_select: [],
152185
},
153-
Slug: {
154-
id: "%7D%3D~K",
155-
type: "rich_text",
156-
rich_text: [
157-
{
158-
type: "text",
159-
text: {
160-
content: options.slug || "/", // oddly, this has "/" when slug is missing
161-
link: null,
162-
},
163-
annotations: {
164-
bold: false,
165-
italic: false,
166-
strikethrough: false,
167-
underline: false,
168-
code: false,
169-
color: "default",
170-
},
171-
plain_text: options.slug || "/", // oddly, this has "/" when slug is missing
172-
href: null,
173-
},
174-
],
175-
},
186+
Slug: slugObject,
176187
Name: {
177188
id: "title",
178189
type: "title",
@@ -198,7 +209,7 @@ export function makeSamplePageObject(options: {
198209
},
199210
},
200211
url: `https://www.notion.so/Hello-World-${id}`,
201-
};
212+
}; // ?
202213

203214
const p = new NotionPage({
204215
layoutContext: "/Second-Level/Third-Level",

src/plugins/externalLinks.spec.ts

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,69 @@ test("links turned into bookmarks", async () => {
1515
expect(results.trim()).toBe("[https://github.com](https://github.com)");
1616
});
1717

18-
test("links inside callouts", async () => {
19-
const results = await getMarkdown({});
18+
test("external link inside callout", async () => {
19+
const results = await getMarkdown({
20+
type: "callout",
21+
callout: {
22+
rich_text: [
23+
{
24+
type: "text",
25+
text: { content: "Callouts inline ", link: null },
26+
annotations: {
27+
bold: false,
28+
italic: false,
29+
strikethrough: false,
30+
underline: false,
31+
code: false,
32+
color: "default",
33+
},
34+
plain_text: "Callouts inline ",
35+
href: null,
36+
},
37+
{
38+
type: "text",
39+
text: {
40+
content: "great page",
41+
link: { url: `https://github.com` },
42+
},
43+
annotations: {
44+
bold: false,
45+
italic: false,
46+
strikethrough: false,
47+
underline: false,
48+
code: false,
49+
color: "default",
50+
},
51+
plain_text: "great page",
52+
href: `https://github.com`,
53+
},
54+
{
55+
type: "text",
56+
text: { content: ".", link: null },
57+
annotations: {
58+
bold: false,
59+
italic: false,
60+
strikethrough: false,
61+
underline: false,
62+
code: false,
63+
color: "default",
64+
},
65+
plain_text: ".",
66+
href: null,
67+
},
68+
],
69+
icon: { type: "emoji", emoji: "⚠️" },
70+
color: "gray_background",
71+
},
72+
});
73+
expect(results.trim()).toBe(
74+
"> ⚠️ Callouts inline [great page](https://github.com)."
75+
);
2076
});
2177

22-
async function getMarkdown(block: object, targetPage?: NotionPage) {
78+
async function getMarkdown(block: object) {
2379
const config = {
2480
plugins: [standardExternalLinkConversion],
2581
};
26-
return await oneBlockToMarkdown(config, block, targetPage);
82+
return await oneBlockToMarkdown(config, block);
2783
}

src/plugins/interalLinks.spec.ts

Lines changed: 122 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,60 @@ test("inline links to external site", async () => {
7070
});
7171
expect(results.trim()).toBe("Inline [github](https://github.com)");
7272
});
73-
test("link to an existing page on this site uses slug and title", async () => {
73+
74+
test("link to an existing page on this site that has no slug", async () => {
75+
const targetPageId = "123";
76+
const targetPage: NotionPage = makeSamplePageObject({
77+
slug: undefined,
78+
name: "Hello World",
79+
id: targetPageId,
80+
});
81+
82+
const results = await getMarkdown(
83+
{
84+
type: "paragraph",
85+
paragraph: {
86+
rich_text: [
87+
{
88+
type: "text",
89+
text: { content: "Inline ", link: null },
90+
annotations: {
91+
bold: false,
92+
italic: false,
93+
strikethrough: false,
94+
underline: false,
95+
code: false,
96+
color: "default",
97+
},
98+
plain_text: "Inline ",
99+
href: null,
100+
},
101+
{
102+
type: "text",
103+
text: {
104+
content: "great page",
105+
link: { url: `/${targetPageId}` },
106+
},
107+
annotations: {
108+
bold: false,
109+
italic: false,
110+
strikethrough: false,
111+
underline: false,
112+
code: false,
113+
color: "default",
114+
},
115+
plain_text: "great page",
116+
href: `/${targetPageId}`,
117+
},
118+
],
119+
color: "default",
120+
},
121+
},
122+
targetPage
123+
);
124+
expect(results.trim()).toBe(`Inline [great page](/${targetPageId})`);
125+
});
126+
test("link to an existing page on this site uses slug", async () => {
74127
const targetPageId = "123";
75128
const targetPage: NotionPage = makeSamplePageObject({
76129
slug: "hello-world",
@@ -166,8 +219,74 @@ test("links to other notion pages that are not in this site give PROBLEM LINK",
166219
expect(results.trim()).toBe("Inline **[Problem Link]**");
167220
});
168221

169-
test("links to headings", async () => {
170-
const results = await getMarkdown({});
222+
test("internal link inside callout", async () => {
223+
const targetPageId = "123";
224+
const targetPage: NotionPage = makeSamplePageObject({
225+
slug: "hello-world",
226+
name: "Hello World",
227+
id: targetPageId,
228+
});
229+
230+
const results = await getMarkdown(
231+
{
232+
type: "callout",
233+
callout: {
234+
rich_text: [
235+
{
236+
type: "text",
237+
text: { content: "Callouts inline ", link: null },
238+
annotations: {
239+
bold: false,
240+
italic: false,
241+
strikethrough: false,
242+
underline: false,
243+
code: false,
244+
color: "default",
245+
},
246+
plain_text: "Callouts inline ",
247+
href: null,
248+
},
249+
{
250+
type: "text",
251+
text: {
252+
content: "great page",
253+
link: { url: `/${targetPageId}` },
254+
},
255+
annotations: {
256+
bold: false,
257+
italic: false,
258+
strikethrough: false,
259+
underline: false,
260+
code: false,
261+
color: "default",
262+
},
263+
plain_text: "great page",
264+
href: `/${targetPageId}`,
265+
},
266+
{
267+
type: "text",
268+
text: { content: ".", link: null },
269+
annotations: {
270+
bold: false,
271+
italic: false,
272+
strikethrough: false,
273+
underline: false,
274+
code: false,
275+
color: "default",
276+
},
277+
plain_text: ".",
278+
href: null,
279+
},
280+
],
281+
icon: { type: "emoji", emoji: "⚠️" },
282+
color: "gray_background",
283+
},
284+
},
285+
targetPage
286+
);
287+
expect(results.trim()).toBe(
288+
"> ⚠️ Callouts inline [great page](/hello-world)."
289+
);
171290
});
172291

173292
async function getMarkdown(block: object, targetPage?: NotionPage) {

0 commit comments

Comments
 (0)