Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalrymple committed Feb 26, 2024
1 parent 6489126 commit f707285
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 83 deletions.
12 changes: 0 additions & 12 deletions test/__mocks__/parse5.mts

This file was deleted.

154 changes: 83 additions & 71 deletions test/unit/helpers/convert-text.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import * as parse5 from 'parse5';
import { convertText } from '../../../src/helpers/convert-text.mts';
import * as convertElementUtils from '../../../src/helpers/convert-element.mts';

// TODO: Move into a __mocks__ directory
type MockedParse5 = { parseFragement(this: void): void };

vi.mock('parse5', async (getModule) => {
const original: MockedParse5 = await getModule();

return {
...original,
parseFragement: vi.fn().mockImplementation(original.parseFragement),
};
});

describe('convertText', () => {
it('should parse the input html and convert to latex', async () => {
const parse5Spy = vi.spyOn(parse5, 'parseFragment');
Expand All @@ -16,75 +28,75 @@ describe('convertText', () => {
expect(tex).toBe('');
});

it('should include a document wrapper if configured', async () => {
const html = `<body></body>`;
const tex = await convertText(html, { includeDocumentWrapper: true });

expect(tex).toBe('\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}');
});

it('should not include a document wrapper by default', async () => {
const html = `<body></body>`;
const tex = await convertText(html);

expect(tex).toBe('');
});

it('should support custom package imports', async () => {
const html = `<body></body>`;
const tex = await convertText(html, {
includePackages: ['amsmath'],
includeDocumentWrapper: true,
});

expect(tex).toBe(
'\\usepackage{amsmath}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
);
});

it('should add known packages by default if matching tags are present within the input html and no custom packages are specified', async () => {
const html = `<body>\\cfrac</body>`;
const tex = await convertText(html, { includeDocumentWrapper: true });

expect(tex).toBe(
'\\usepackage{amsmath}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
);
});

it('should support adding an author to the documentWrapper if passed', async () => {
const html = `<body></body>`;
const tex = await convertText(html, { includeDocumentWrapper: true, author: 'Takashi Kovacs' });

expect(tex).toBe(
'\\author{Takashi Kovachs}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
);
});

it('should support adding a title to the documentWrapper if passed', async () => {
const html = `<body></body>`;
const tex = await convertText(html, { includeDocumentWrapper: true, title: 'Altered Carbon' });

expect(tex).toBe(
'\\title{Altered Carbon}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
);
});

it('should support adding a the current date to the documentWrapper if the includeDate flag is passed', async () => {
const html = `<body></body>`;
const tex = await convertText(html, { includeDocumentWrapper: true, includeDate: true });

expect(tex).toBe(
'\\title{Altered Carbon}\n\n\\documentclass{article}\n\n\\date{\\today}\n\n\\begin{document}\n\n\n\\end{document}',
);
});

it('should support custom documentClasses', async () => {
const html = `<body></body>`;
const tex = await convertText(html, {
includeDocumentWrapper: true,
documentClass: 'fancydoc',
});

expect(tex).toBe('\\documentclass{fancydoc}\n\n\\begin{document}\n\n\n\\end{document}');
});
// it('should include a document wrapper if configured', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, { includeDocumentWrapper: true });

// expect(tex).toBe('\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}');
// });

// it('should not include a document wrapper by default', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html);

// expect(tex).toBe('');
// });

// it('should support custom package imports', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, {
// includePackages: ['amsmath'],
// includeDocumentWrapper: true,
// });

// expect(tex).toBe(
// '\\usepackage{amsmath}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
// );
// });

// it('should add known packages by default if matching tags are present within the input html and no custom packages are specified', async () => {
// const html = `<body>\\cfrac</body>`;
// const tex = await convertText(html, { includeDocumentWrapper: true });

// expect(tex).toBe(
// '\\usepackage{amsmath}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
// );
// });

// it('should support adding an author to the documentWrapper if passed', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, { includeDocumentWrapper: true, author: 'Takashi Kovacs' });

// expect(tex).toBe(
// '\\author{Takashi Kovachs}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
// );
// });

// it('should support adding a title to the documentWrapper if passed', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, { includeDocumentWrapper: true, title: 'Altered Carbon' });

// expect(tex).toBe(
// '\\title{Altered Carbon}\n\n\\documentclass{article}\n\n\\begin{document}\n\n\n\\end{document}',
// );
// });

// it('should support adding a the current date to the documentWrapper if the includeDate flag is passed', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, { includeDocumentWrapper: true, includeDate: true });

// expect(tex).toBe(
// '\\title{Altered Carbon}\n\n\\documentclass{article}\n\n\\date{\\today}\n\n\\begin{document}\n\n\n\\end{document}',
// );
// });

// it('should support custom documentClasses', async () => {
// const html = `<body></body>`;
// const tex = await convertText(html, {
// includeDocumentWrapper: true,
// documentClass: 'fancydoc',
// });

// expect(tex).toBe('\\documentclass{fancydoc}\n\n\\begin{document}\n\n\n\\end{document}');
// });
});

0 comments on commit f707285

Please sign in to comment.