Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import InteropService from './InteropService';
import InteropService_Importer_OneNote from './InteropService_Importer_OneNote';
import { JSDOM } from 'jsdom';
import { ImportModuleOutputFormat } from './types';
import HtmlToMd from '../../HtmlToMd';

const instructionMessage = `
--------------------------------------
Expand All @@ -26,6 +27,21 @@ const removeItemIds = (body: string) => {
return body.replace(/:\/[a-z0-9]{32}/g, ':/id-here');
};

const removeDefaultCss = (body: string) => {
const defaultCssStart = body.indexOf('/*** Start default CSS ***/');
const endMarker = '/*** End default CSS ***/';
const defaultCssEnd = body.indexOf(endMarker);
if (defaultCssEnd === -1 || defaultCssStart === -1) return body;

const before = body.substring(0, defaultCssStart);
const after = body.substring(defaultCssEnd + endMarker.length);
return [before, '/* (For testing: Removed default CSS) */', after].join('\n');
};

const normalizeNoteForSnapshot = (body: string) => {
return removeItemIds(removeDefaultCss(body));
};

// This file is ignored if not running in CI. Look at onenote-converter/README.md and jest.config.js for more information
describe('InteropService_Importer_OneNote', () => {
let tempDir: string;
Expand Down Expand Up @@ -68,7 +84,7 @@ describe('InteropService_Importer_OneNote', () => {

expectWithInstructions(mainNote.title).toBe('Page title');
expectWithInstructions(mainNote.markup_language).toBe(MarkupToHtml.MARKUP_LANGUAGE_HTML);
expectWithInstructions(mainNote.body).toMatchSnapshot(mainNote.title);
expectWithInstructions(normalizeNoteForSnapshot(mainNote.body)).toMatchSnapshot(mainNote.title);
});

it('should preserve indentation of subpages in Section page', async () => {
Expand Down Expand Up @@ -121,7 +137,7 @@ describe('InteropService_Importer_OneNote', () => {
expectWithInstructions(notes.filter(n => n.parent_id === parentSection.id).length).toBe(6);

for (const note of notes) {
expectWithInstructions(note.body).toMatchSnapshot(note.title);
expectWithInstructions(normalizeNoteForSnapshot(note.body)).toMatchSnapshot(note.title);
}
BaseModel.setIdGenerator(originalIdGenerator);
});
Expand Down Expand Up @@ -186,7 +202,9 @@ describe('InteropService_Importer_OneNote', () => {
const originalIdGenerator = BaseModel.setIdGenerator(() => String(idx++));
const notes = await importNote(`${supportDir}/onenote/bug_broken_character.zip`);

expectWithInstructions(notes.find(n => n.title === 'Action research - Wikipedia').body).toMatchSnapshot();
expectWithInstructions(
normalizeNoteForSnapshot(notes.find(n => n.title === 'Action research - Wikipedia').body),
).toMatchSnapshot();

BaseModel.setIdGenerator(originalIdGenerator);
});
Expand All @@ -197,7 +215,7 @@ describe('InteropService_Importer_OneNote', () => {
const notes = await importNote(`${supportDir}/onenote/remove_hyperlink_on_title.zip`);

for (const note of notes) {
expectWithInstructions(note.body).toMatchSnapshot(note.title);
expectWithInstructions(normalizeNoteForSnapshot(note.body)).toMatchSnapshot(note.title);
}
BaseModel.setIdGenerator(originalIdGenerator);
});
Expand All @@ -217,7 +235,7 @@ describe('InteropService_Importer_OneNote', () => {
const notes = await importNote(`${supportDir}/onenote/hyperlink_marker_as_first_character.zip`);

for (const note of notes) {
expectWithInstructions(note.body).toMatchSnapshot(note.title);
expectWithInstructions(normalizeNoteForSnapshot(note.body)).toMatchSnapshot(note.title);
}
BaseModel.setIdGenerator(originalIdGenerator);
});
Expand All @@ -230,7 +248,7 @@ describe('InteropService_Importer_OneNote', () => {
expectWithInstructions(notes.length).toBe(2);

for (const note of notes) {
expectWithInstructions(note.body).toMatchSnapshot(note.title);
expectWithInstructions(normalizeNoteForSnapshot(note.body)).toMatchSnapshot(note.title);
}
BaseModel.setIdGenerator(originalIdGenerator);
});
Expand All @@ -243,7 +261,7 @@ describe('InteropService_Importer_OneNote', () => {
expectWithInstructions(notes.length).toBe(2);

for (const note of notes) {
expectWithInstructions(note.body).toMatchSnapshot(note.title);
expectWithInstructions(normalizeNoteForSnapshot(note.body)).toMatchSnapshot(note.title);
}
BaseModel.setIdGenerator(originalIdGenerator);
});
Expand All @@ -253,11 +271,11 @@ describe('InteropService_Importer_OneNote', () => {

// InkBias bug
const note1Content = notes.find(n => n.title === 'Marketing Funnel & Training').body;
expect(removeItemIds(note1Content)).toMatchSnapshot();
expect(normalizeNoteForSnapshot(note1Content)).toMatchSnapshot();

// EntityGuid
const note2Content = notes.find(n => n.title === 'Decrease support costs').body;
expect(removeItemIds(note2Content)).toMatchSnapshot();
expect(normalizeNoteForSnapshot(note2Content)).toMatchSnapshot();
});

it('should support directly importing .one files', async () => {
Expand All @@ -277,7 +295,16 @@ describe('InteropService_Importer_OneNote', () => {
it('should support importing .one files that contain checkboxes', async () => {
const notes = await importNote(`${supportDir}/onenote/checkboxes_and_unicode.one`);
expectWithInstructions(
removeItemIds(notes.find(n => n.title.startsWith('Test Todo')).body),
normalizeNoteForSnapshot(notes.find(n => n.title.startsWith('Test Todo')).body),
).toMatchSnapshot();
});

it('should correctly convert imported notes to Markdown', async () => {
const notes = await importNote(`${supportDir}/onenote/checkboxes_and_unicode.one`);
const checklistNote = notes.find(n => n.title.startsWith('Test Todo'));
const converter = new HtmlToMd();
const markdown = converter.parse(checklistNote.body);

expect(markdown).toMatchSnapshot('Test Todo: As Markdown');
});
});
Loading
Loading