diff --git a/client/src/__tests__/components/GiftTemplate/TextType.test.ts b/client/src/__tests__/components/GiftTemplate/TextType.test.ts index 980db3c..e185470 100644 --- a/client/src/__tests__/components/GiftTemplate/TextType.test.ts +++ b/client/src/__tests__/components/GiftTemplate/TextType.test.ts @@ -4,6 +4,7 @@ import { TextFormat } from "gift-pegjs"; describe('TextType', () => { it('should format text with basic characters correctly', () => { const input: TextFormat = { + // Text here would already be past the GIFT parsing stage, so we don't need to escape GIFT special characters text: 'Hello, world! 5 > 3, right?', format: 'moodle' }; @@ -11,17 +12,19 @@ describe('TextType', () => { expect(FormattedTextTemplate(input)).toBe(expectedOutput); }); - it('should format text with newlines correctly', () => { + it('should format text with embedded newlines correctly', () => { const input: TextFormat = { + // Text here would already be past the GIFT parsing stage, so we don't need to escape GIFT special characters text: 'Hello,\nworld!\n5 > 3, right?', - format: 'plain' + format: 'moodle' }; - const expectedOutput = 'Hello,
world!
5 > 3, right?'; + const expectedOutput = 'Hello,
world!
5 > 3, right?'; expect(FormattedTextTemplate(input)).toBe(expectedOutput); }); - it('should format text with LaTeX correctly', () => { + it('should format text with display-mode LaTeX correctly, with $$ delimiters', () => { const input: TextFormat = { + // Text here would already be past the GIFT parsing stage, so we don't need to escape GIFT special characters text: '$$E=mc^2$$', format: 'plain' }; @@ -30,27 +33,41 @@ describe('TextType', () => { // Hint -- if the output changes because of a change in the code or library, you can update // by running the test and copying the "Received string:" in jest output // when it fails (assuming the output is correct) - const expectedOutput = 'E=mc2E=mc^2'; + const expectedOutput = 'E=mc2E=mc^2'; expect(FormattedTextTemplate(input)).toContain(expectedOutput); }); it('should format text with two equations (inline and separate) correctly', () => { const input: TextFormat = { + // Text here would already be past the GIFT parsing stage, so we don't need to escape GIFT special characters text: '$a + b = c$ ? $$E=mc^2$$', format: 'moodle' }; - // hint: katex-display is the class that indicates a separate equation - const expectedOutput = 'a+b=ca + b = c ? E=mc2E=mc^2'; + const expectedOutput = 'a+b=ca + b = c ? E=mc2E=mc^2'; expect(FormattedTextTemplate(input)).toContain(expectedOutput); }); - it('should format text with a katex matrix correctly', () => { + it('should format text with an inline katex matrix correctly', () => { const input: TextFormat = { - // eslint-disable-next-line no-useless-escape - text: `Donnez le déterminant de la matrice suivante.$$\\begin\{pmatrix\}\n a&b \\\\\n c&d\n\\end\{pmatrix\}`, - format: 'plain' + // Text here would already be past the GIFT parsing stage, so we don't need to escape GIFT special characters + text: `Inline matrix: \\( \\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix} \\)`, + format: '' }; - const expectedOutput = 'Donnez le déterminant de la matrice suivante.\\begin{pmatrix}
a&b \\\\
c&d
\\end{pmatrix}'; + + // eslint-disable-next-line no-irregular-whitespace + // warning: there are zero-width spaces "​" in the expected output -- you must enable seeing them with an extension such as Gremlins tracker in VSCode + + // eslint-disable-next-line no-irregular-whitespace + const expectedOutput = `Inline matrix: (abcd) \\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix} `; + expect(FormattedTextTemplate(input)).toContain(expectedOutput); + }); + + it('should format text with an inline katex matrix correctly, with \\( and \\) as inline delimiters.', () => { + const input: TextFormat = { + text: `Donnez le déterminant de la matrice suivante.\\( \\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix} \\)`, + format: '' + }; + const expectedOutput = 'Donnez le déterminant de la matrice suivante.(abcd) \\begin{pmatrix} a & b \\\\ c & d \\end{pmatrix} '; expect(FormattedTextTemplate(input)).toContain(expectedOutput); });