mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-21 09:38:01 +02:00
52 lines
2.6 KiB
TypeScript
52 lines
2.6 KiB
TypeScript
const mdImporterService = require('@joplin/lib/services/interop/InteropService_Importer_Md').default;
|
|
const Note = require('@joplin/lib/models/Note').default;
|
|
const { setupDatabaseAndSynchronizer, switchClient } = require('@joplin/lib/testing/test-utils.js');
|
|
|
|
const importer = new mdImporterService();
|
|
|
|
|
|
describe('InteropService_Importer_Md: importLocalImages', function() {
|
|
beforeEach(async (done) => {
|
|
await setupDatabaseAndSynchronizer(1);
|
|
await switchClient(1);
|
|
done();
|
|
});
|
|
it('should import linked files and modify tags appropriately', async function() {
|
|
const tagNonExistentFile = '![does not exist](does_not_exist.png)';
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(2);
|
|
const inexistentLinkUnchanged = note.body.includes(tagNonExistentFile);
|
|
expect(inexistentLinkUnchanged).toBe(true);
|
|
});
|
|
it('should only create 1 resource for duplicate links, all tags should be updated', async function() {
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample-duplicate-links.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(1);
|
|
const reg = new RegExp(items[0].id, 'g');
|
|
const matched = note.body.match(reg);
|
|
expect(matched.length).toBe(2);
|
|
});
|
|
it('should import linked files and modify tags appropriately when link is also in alt text', async function() {
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample-link-in-alt-text.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(1);
|
|
});
|
|
it('should passthrough unchanged if no links present', async function() {
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample-no-links.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(0);
|
|
expect(note.body).toContain('Unidentified vessel travelling at sub warp speed, bearing 235.7. Fluctuations in energy readings from it, Captain. All transporters off.');
|
|
});
|
|
it('should import linked image with special characters in name', async function() {
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample-special-chars.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(1);
|
|
});
|
|
it('should import resources for files', async function() {
|
|
const note = await importer.importFile(`${__dirname}/md_to_md/sample-files.md`, 'notebook');
|
|
const items = await Note.linkedItems(note.body);
|
|
expect(items.length).toBe(4);
|
|
});
|
|
});
|