noteshare.space/webapp/src/test/markdown/internalLinks.test.ts

45 lines
1.6 KiB
TypeScript
Raw Normal View History

2022-07-05 00:52:54 +03:00
import { render, screen } from '@testing-library/svelte';
2022-07-06 15:16:54 +03:00
import { readMd } from './util';
import MarkdownRenderer from '$lib/components/MarkdownRenderer.svelte';
2022-07-05 00:52:54 +03:00
2022-07-05 01:46:06 +03:00
// rendering links
describe('rendering [[internal]] links', async () => {
const plaintext = await readMd('links.md');
2022-07-05 00:52:54 +03:00
2022-07-05 01:46:06 +03:00
it('Renders [[links]] correctly', async () => {
2022-07-05 00:52:54 +03:00
render(MarkdownRenderer, { plaintext: plaintext });
2022-07-05 01:46:06 +03:00
const linkEl = await screen.findByText(/^Normal internal link$/);
expect(linkEl).toBeInTheDocument();
});
it('Renders [[links|with alias]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with alias$/);
expect(linkEl).toBeInTheDocument();
});
it('Renders [[links#heading]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Page with headings > heading A$/);
expect(linkEl).toBeInTheDocument();
});
it('Renders [[links#heading|with alias]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with heading alias$/);
expect(linkEl).toBeInTheDocument();
});
it('Renders [[links#heading|with alias#fakeheading]] correctly', async () => {
render(MarkdownRenderer, { plaintext: plaintext });
const linkEl = await screen.findByText(/^Link with heading alias#false heading$/);
expect(linkEl).toBeInTheDocument();
});
2022-07-05 00:52:54 +03:00
2022-07-05 01:46:06 +03:00
it('Does not render [[]] empty links', async () => {
render(MarkdownRenderer, { plaintext: plaintext });
const textEl = await screen.findByText('[[]]', { exact: false });
expect(textEl).toBeInTheDocument();
});
});