wisemapping-frontend/packages/mindplot/test/unit/import/Helper.ts

27 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-03-10 16:26:24 +01:00
/* eslint-disable import/no-extraneous-dependencies */
/* eslint-disable import/prefer-default-export */
2022-03-14 21:31:54 +01:00
import fs from 'fs';
2022-03-10 16:26:24 +01:00
import path from 'path';
import { expect } from '@jest/globals';
2022-03-14 21:31:54 +01:00
import { diff } from 'jest-diff';
2022-03-10 16:26:24 +01:00
import Importer from '../../../src/components/import/Importer';
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
import { parseXMLFile } from '../export/Helper';
export const exporterAssert = async (testName: string, importer: Importer) => {
const actualMindmap = await importer.import(testName, '');
// Load mindmap DOM..
const mindmapPath = path.resolve(__dirname, `./expected/${testName}.wxml`);
2022-03-14 21:31:54 +01:00
const mindmapDocument = parseXMLFile(mindmapPath, 'text/xml');
const serializer = XMLSerializerFactory.createInstanceFromDocument(mindmapDocument);
const mindmapExpect = serializer.loadFromDom(mindmapDocument, testName);
2022-03-10 16:26:24 +01:00
2022-03-14 21:31:54 +01:00
// Compare with expected...
if (actualMindmap !== mindmapExpect) {
const diffResult = diff(actualMindmap, mindmapExpect);
console.log(diffResult);
expect(actualMindmap).toEqual(mindmapExpect);
}
2022-03-10 16:26:24 +01:00
};