1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-21 09:38:01 +02:00

Chore: Added tests for renderMarkup command

This commit is contained in:
Laurent Cozic 2024-10-27 21:39:44 +00:00
parent ff09937ca2
commit f4ee4a178e
4 changed files with 50 additions and 1 deletions

View File

@ -155,6 +155,7 @@ packages/app-desktop/commands/exportNotes.js
packages/app-desktop/commands/focusElement.js
packages/app-desktop/commands/index.js
packages/app-desktop/commands/openProfileDirectory.js
packages/app-desktop/commands/renderMarkup.test.js
packages/app-desktop/commands/renderMarkup.js
packages/app-desktop/commands/replaceMisspelling.js
packages/app-desktop/commands/restoreNoteRevision.js

1
.gitignore vendored
View File

@ -132,6 +132,7 @@ packages/app-desktop/commands/exportNotes.js
packages/app-desktop/commands/focusElement.js
packages/app-desktop/commands/index.js
packages/app-desktop/commands/openProfileDirectory.js
packages/app-desktop/commands/renderMarkup.test.js
packages/app-desktop/commands/renderMarkup.js
packages/app-desktop/commands/replaceMisspelling.js
packages/app-desktop/commands/restoreNoteRevision.js

View File

@ -0,0 +1,47 @@
import shim from '@joplin/lib/shim';
import Resource from '@joplin/lib/models/Resource';
import Note from '@joplin/lib/models/Note';
import { setupDatabaseAndSynchronizer, supportDir, switchClient } from '@joplin/lib/testing/test-utils';
import { runtime } from './renderMarkup';
import { MarkupLanguage } from '@joplin/renderer';
const testImagePath = `${supportDir}/photo.jpg`;
const command = runtime();
describe('renderMarkup', () => {
beforeEach(async () => {
await setupDatabaseAndSynchronizer(1);
await switchClient(1);
});
test('should return the rendered note as HTML', async () => {
{
const renderedNote = await command.execute(null, MarkupLanguage.Markdown, 'hello **strong**');
expect(renderedNote.html).toBe('<div id="rendered-md"><p>hello <strong>strong</strong></p>\n</div>');
expect(!!renderedNote.pluginAssets).toBe(true);
expect(!!renderedNote.cssStrings).toBe(true);
}
{
const renderedNote = await await command.execute(null, MarkupLanguage.Markdown, '- [ ] Beer\n- [x] Milk\n- [ ] Eggs');
expect(renderedNote.html).toContain('checkbox-label-unchecked">Beer');
expect(renderedNote.html).toContain('checkbox-label-checked">Milk');
expect(renderedNote.html).toContain('checkbox-label-unchecked">Eggs');
expect(!!renderedNote.pluginAssets).toBe(true);
expect(!!renderedNote.cssStrings).toBe(true);
}
{
const note = await Note.save({ });
await shim.attachFileToNote(note, testImagePath, null, { resizeLargeImages: 'never' });
const resource = (await Resource.all())[0];
const noteBody = (await Note.load(note.id)).body;
const renderedNote = await await command.execute(null, MarkupLanguage.Markdown, noteBody);
expect(renderedNote.html).toContain(`<div id="rendered-md"><p><img data-from-md data-resource-id="${resource.id}" src="joplin-content://note-viewer//Users/laurent/src/joplin/packages/lib/testing/../../app-cli/tests/test data/`);
expect(renderedNote.html).toContain(`/resources-1/${resource.id}.jpg?t=`);
expect(renderedNote.html).toContain('" title alt="photo.jpg" /></p>');
}
});
});

View File

@ -309,7 +309,7 @@ const shim = {
detectAndSetLocale: null as Function,
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
attachFileToNote: async (_note: any, _filePath: string): Promise<NoteEntity> => {
attachFileToNote: async (_note: any, _filePath: string, _position: number, _options: any): Promise<NoteEntity> => {
throw new Error('Not implemented: attachFileToNote');
},