Skip to content

Commit

Permalink
Merge pull request #63 from datopian/update-tests
Browse files Browse the repository at this point in the history
Update obsidian links test
  • Loading branch information
mohamedsalem401 authored Nov 22, 2023
2 parents 7d73442 + d04f225 commit eea5b9b
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 97 deletions.
3 changes: 2 additions & 1 deletion src/lib/process.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Can parse a file and get file info", () => {
);

expect(fileInfo.file_path).toBe(fullPath);
expect(fileInfo.url_path).toBe("index.mdx");
expect(fileInfo.extension).toBe("mdx");
expect(fileInfo.tags).toEqual(["tag1", "tag2", "tag3"]);
expect(fileInfo.metadata).toEqual({
Expand All @@ -23,7 +24,7 @@ describe("Can parse a file and get file info", () => {
});
expect(fileInfo.links).toEqual([
{
embed: true,
embed: false,
from: "index.mdx",
internal: true,
text: "link",
Expand Down
190 changes: 95 additions & 95 deletions src/utils/extractWikiLinks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe("extractWikiLinks", () => {
to: "abc/page-1",
toRaw: "page-1",
text: "Page 1",
embed: true,
embed: false,
internal: true,
},
];
Expand All @@ -36,7 +36,7 @@ describe("extractWikiLinks", () => {
to: "abc/world.png",
toRaw: "world.png",
text: "hello",
embed: true,
embed: false,
internal: true,
},
];
Expand All @@ -52,7 +52,7 @@ describe("extractWikiLinks", () => {
to: "abc/world.mdx",
toRaw: "world.mdx",
text: "hello",
embed: true,
embed: false,
internal: true,
},
];
Expand All @@ -68,7 +68,7 @@ describe("extractWikiLinks", () => {
to: "abc/world",
toRaw: "/world",
text: "hello",
embed: true,
embed: false,
internal: true,
},
];
Expand Down Expand Up @@ -109,98 +109,98 @@ describe("extractWikiLinks", () => {
});

// TODO Obsidian wiki links
// describe("Obsidian wiki links", () => {
// test("should extract wiki links", () => {
// const source = "[[Page 1]] [[Page 2]] [[Page 3]]";
// const expectedLinks = [
// {
// from: "abc/foobar.md",
// to: "abc/Page 1.md",
// toRaw: "Page 1",
// text: "Page 1",
// embed: false,
// internal: true,
// },
// {
// from: "abc/foobar.md",
// to: "abc/Page 2.md",
// toRaw: "Page 2",
// text: "Page 2",
// embed: false,
// internal: true,
// },
// {
// from: "abc/foobar.md",
// to: "abc/Page 3.md",
// toRaw: "Page 3",
// text: "Page 3",
// embed: false,
// internal: true,
// },
// ];
// const links = extractWikiLinks("abc/foobar.md", source);
// expect(links).toHaveLength(expectedLinks.length);
// links.forEach((link) => {
// expect(expectedLinks).toContainEqual(link);
// });
// });
describe("Obsidian wiki links", () => {
test("should extract wiki links", () => {
const source = "[[Page 1]] [[Page 2]] [[Page 3]]";
const expectedLinks = [
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/Page 1",
toRaw: "Page 1",
},
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/Page 2",
toRaw: "Page 2",
},
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/Page 3",
toRaw: "Page 3",
},
];
const links = extractWikiLinks("abc/foobar.md", source);
expect(links).toHaveLength(expectedLinks.length);
links.forEach((link) => {
expect(expectedLinks).toContainEqual(link);
});
});

// test("should extract wiki links with Obsidian-style shortest path", () => {
// const source = "[[Page 1]] [[Page 2]] [[Page 3]]";
// const expectedLinks = [
// {
// from: "abc/foobar.md",
// to: "abc/some/folder/Page 1.md",
// toRaw: "/some/folder/Page 1",
// text: "Page 1",
// embed: false,
// internal: true,
// },
// {
// from: "abc/foobar.md",
// to: "abc/some/folder/Page 2.md",
// toRaw: "/some/folder/Page 2",
// text: "Page 2",
// embed: false,
// internal: true,
// },
// {
// from: "abc/foobar.md",
// to: "abc/some/folder/Page 3.md",
// toRaw: "/some/folder/Page 3",
// text: "Page 3",
// embed: false,
// internal: true,
// },
// ];
// const permalinks = [
// "/some/folder/Page 1",
// "/some/folder/Page 2",
// "/some/folder/Page 3",
// ];
// const links = extractWikiLinks("abc/foobar.md", source, { permalinks });
// expect(links).toHaveLength(expectedLinks.length);
// links.forEach((link) => {
// expect(expectedLinks).toContainEqual(link);
// });
// });
test("should extract wiki links with Obsidian-style shortest path", () => {
const source = "[[Page 1]] [[Page 2]] [[Page 3]]";
const expectedLinks = [
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/some/folder/Page 1",
toRaw: "/some/folder/Page 1",
},
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/some/folder/Page 2",
toRaw: "/some/folder/Page 2",
},
{
embed: false,
from: "abc/foobar.md",
internal: true,
text: "",
to: "abc/some/folder/Page 3",
toRaw: "/some/folder/Page 3",
},
];
const permalinks = [
"/some/folder/Page 1",
"/some/folder/Page 2",
"/some/folder/Page 3",
];
const links = extractWikiLinks("abc/foobar.md", source, { permalinks });
expect(links).toHaveLength(expectedLinks.length);
links.forEach((link) => {
expect(expectedLinks).toContainEqual(link);
});
});

// test("should extract embedded wiki links", () => {
// const source = "![[My File.png]]]]";
// const expectedLinks = [
// {
// from: "abc/foobar.md",
// to: "abc/My File.png",
// toRaw: "My File.png",
// text: "My File.png",
// embed: true,
// internal: true,
// },
// ];
// const links = extractWikiLinks("abc/foobar.md", source);
// expect(links).toEqual(expectedLinks);
// });
// });
test("should extract embedded wiki links", () => {
const source = "![[My File.png]]]]";
const expectedLinks = [
{
from: "abc/foobar.md",
to: "abc/My File.png",
toRaw: "My File.png",
text: "",
embed: true,
internal: true,
},
];
const links = extractWikiLinks("abc/foobar.md", source);
expect(links).toEqual(expectedLinks);
});
});

// TODO fix this test
// test("should return unique links", () => {
Expand All @@ -226,7 +226,7 @@ describe("extractWikiLinks", () => {
to: "https://example.com",
toRaw: "https://example.com",
text: "External Link",
embed: true, // Adjust this based on your requirements
embed: false,
internal: false,
},
];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/extractWikiLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const extractWikiLinks = (
to: to,
toRaw: node.url,
text: node.children?.[0]?.value || "",
embed: true,
embed: false,
internal: !node.url.startsWith("http"),
};
},
Expand Down

0 comments on commit eea5b9b

Please sign in to comment.