summaryrefslogtreecommitdiff
path: root/packages/integrations/mdx/test/mdx-astro-markdown-remarkRehype.test.js
blob: ddcce4ba59769e091c08492874b82cf4061e54c2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import mdx from '@astrojs/mdx';

import { expect } from 'chai';
import { parseHTML } from 'linkedom';
import { loadFixture } from '../../../astro/test/test-utils.js';

describe('MDX with Astro Markdown remark-rehype config', () => {
	it('Renders footnotes with values from the default configuration', async () => {
		const fixture = await loadFixture({
			root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
			integrations: [mdx()],
			markdown: {
				remarkRehype: {
					footnoteLabel: 'Catatan kaki',
					footnoteBackLabel: 'Kembali ke konten',
				},
			},
		});

		await fixture.build();
		const html = await fixture.readFile('/index.html');
		const { document } = parseHTML(html);

		expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
		expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
			'Kembali ke konten'
		);
	});

	it('Renders footnotes with values from custom configuration extending the default', async () => {
		const fixture = await loadFixture({
			root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
			integrations: [
				mdx({
					remarkRehype: {
						footnoteLabel: 'Catatan kaki',
						footnoteBackLabel: 'Kembali ke konten',
					},
				}),
			],
			markdown: {
				remarkRehype: {
					footnoteBackLabel: 'Replace me',
				},
			},
		});

		await fixture.build();
		const html = await fixture.readFile('/index.html');
		const { document } = parseHTML(html);

		expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
		expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
			'Kembali ke konten'
		);
	});

	it('Renders footnotes with values from custom configuration without extending the default', async () => {
		const fixture = await loadFixture({
			root: new URL('./fixtures/mdx-astro-markdown-remarkRehype/', import.meta.url),
			integrations: [
				mdx({
					extendPlugins: 'astroDefaults',
					remarkRehype: {
						footnoteLabel: 'Catatan kaki',
					},
				}),
			],
			markdown: {
				remarkRehype: {
					footnoteBackLabel: 'Kembali ke konten',
				},
			},
		});

		await fixture.build();
		const html = await fixture.readFile('/index.html');
		const { document } = parseHTML(html);

		expect(document.querySelector('#footnote-label').textContent).to.equal('Catatan kaki');
		expect(document.querySelector('.data-footnote-backref').getAttribute('aria-label')).to.equal(
			'Back to content'
		);
	});
});