Skip to content

Commit

Permalink
Chore: Added tests for renderMarkup command
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Oct 27, 2024
1 parent ff09937 commit f4ee4a1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 47 additions & 0 deletions packages/app-desktop/commands/renderMarkup.test.ts
Original file line number Diff line number Diff line change
@@ -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>');
}
});

});
2 changes: 1 addition & 1 deletion packages/lib/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> => {

This comment has been minimized.

Copy link
@personalizedrefrigerator

personalizedrefrigerator Oct 28, 2024

Collaborator

This change seems to be causing tsc failures:

➤ YN0000: [@joplin/lib]: models/Folder.sharing.test.ts(302,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Folder.sharing.test.ts(378,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Folder.sharing.test.ts(379,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Folder.sharing.test.ts(460,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Folder.sharing.test.ts(461,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Note.test.ts(40,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Note.test.ts(158,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(17,13): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(39,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(48,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(59,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(77,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(90,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(101,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/Resource.test.ts(117,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: models/utils/readOnly.test.ts(22,13): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ReportService.test.ts(116,15): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(25,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(57,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(92,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(111,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(147,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(160,15): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(177,22): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(202,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(225,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/ResourceService.test.ts(240,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService.test.ts(276,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService.test.ts(532,21): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService.test.ts(595,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(50,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(59,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(94,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(104,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(199,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(208,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(310,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(317,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(323,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(331,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(456,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(475,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/interop/InteropService_Exporter_Md.test.ts(494,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/rest/Api.test.ts(915,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/rest/Api.test.ts(929,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/rest/routes/notes.ts(425,20): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/search/SearchEngine.resources.test.ts(18,13): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/search/SearchFilter.test.ts(795,21): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/search/SearchFilter.test.ts(798,21): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/share/ShareService.test.ts(80,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/share/ShareService.test.ts(149,21): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.e2ee.test.ts(274,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.e2ee.test.ts(306,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.e2ee.test.ts(325,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.e2ee.test.ts(337,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(35,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(68,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(97,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(120,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(153,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(180,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(215,15): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(282,15): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(334,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(356,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: services/synchronizer/Synchronizer.resources.test.ts(374,14): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: testing/syncTargetUtils.ts(54,17): error TS2554: Expected 4 arguments, but got 2.
➤ YN0000: [@joplin/lib]: testing/test-utils.ts(450,20): error TS2554: Expected 4 arguments, but got 2.

This comment has been minimized.

Copy link
@personalizedrefrigerator

personalizedrefrigerator Oct 28, 2024

Collaborator

This should be fixed by #11281.

throw new Error('Not implemented: attachFileToNote');
},

Expand Down

0 comments on commit f4ee4a1

Please sign in to comment.