Skip to content

Commit 8c35c80

Browse files
authored
Merge pull request #22 from zenxol/feature/latex-compatibility
Add unit tests to Latex plugin
2 parents 6e47a28 + 0da93e7 commit 8c35c80

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

test/plugins-composer-latex.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
5+
// Run LaTeX plugin unit tests (same pattern as post-fields-logger)
6+
const pluginTestPath = path.join(__dirname, '../vendor/nodebb-plugin-composer-latex/test/composer-latex.js');
7+
require(pluginTestPath);
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const plugin = require('../library.js');
5+
6+
describe('Composer LaTeX Plugin', () => {
7+
describe('registerFormatting', () => {
8+
it('should add latex option to formatting payload', async () => {
9+
const payload = { options: [] };
10+
await plugin.registerFormatting(payload);
11+
assert(Array.isArray(payload.options));
12+
assert(payload.options.length >= 1);
13+
const latexOption = payload.options.find(o => o.name === 'latex');
14+
assert(latexOption, 'should have a latex option');
15+
assert.strictEqual(latexOption.name, 'latex');
16+
assert(latexOption.title);
17+
assert.strictEqual(latexOption.className, 'fa fa-superscript');
18+
assert(latexOption.visibility);
19+
assert.strictEqual(latexOption.visibility.mobile, true);
20+
assert.strictEqual(latexOption.visibility.desktop, true);
21+
});
22+
23+
it('should preserve existing options when adding latex', async () => {
24+
const payload = { options: [{ name: 'bold' }] };
25+
await plugin.registerFormatting(payload);
26+
assert(payload.options.some(o => o.name === 'bold'));
27+
assert(payload.options.some(o => o.name === 'latex'));
28+
});
29+
30+
it('should create options array if missing', async () => {
31+
const payload = {};
32+
await plugin.registerFormatting(payload);
33+
assert(Array.isArray(payload.options));
34+
assert(payload.options.some(o => o.name === 'latex'));
35+
});
36+
});
37+
38+
describe('addMathJaxScript', () => {
39+
it('should add MathJax script to templateData.useCustomHTML', async () => {
40+
const data = { templateData: {} };
41+
await plugin.addMathJaxScript(data);
42+
assert(data.templateData.useCustomHTML);
43+
assert(data.templateData.useCustomHTML.includes('mathjax'));
44+
assert(data.templateData.useCustomHTML.includes('script'));
45+
assert(data.templateData.useCustomHTML.includes('cdn.jsdelivr.net'));
46+
});
47+
48+
it('should append to existing useCustomHTML if present', async () => {
49+
const data = { templateData: { useCustomHTML: '<div>custom</div>' } };
50+
await plugin.addMathJaxScript(data);
51+
assert(data.templateData.useCustomHTML.includes('<div>custom</div>'));
52+
assert(data.templateData.useCustomHTML.includes('mathjax'));
53+
});
54+
55+
it('should do nothing if templateData is missing', async () => {
56+
const data = {};
57+
await plugin.addMathJaxScript(data);
58+
assert.strictEqual(data.templateData, undefined);
59+
});
60+
});
61+
});

0 commit comments

Comments
 (0)