mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +01:00
Added test helper
This commit is contained in:
parent
a2d655e0b9
commit
356c22b391
21
packages/mindplot/test/unit/import/Helper.ts
Normal file
21
packages/mindplot/test/unit/import/Helper.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
|
/* eslint-disable import/prefer-default-export */
|
||||||
|
import path from 'path';
|
||||||
|
import { expect } from '@jest/globals';
|
||||||
|
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`);
|
||||||
|
const mindmapMapDocument = parseXMLFile(mindmapPath, 'text/xml');
|
||||||
|
|
||||||
|
// Convert to mindmap...
|
||||||
|
const serializer = XMLSerializerFactory.createInstanceFromDocument(mindmapMapDocument);
|
||||||
|
const mindmapExpect = serializer.loadFromDom(mindmapMapDocument, testName);
|
||||||
|
|
||||||
|
expect(actualMindmap).toEqual(mindmapExpect);
|
||||||
|
};
|
@ -1,18 +1,17 @@
|
|||||||
|
/* eslint-disable import/no-extraneous-dependencies */
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
||||||
import { test } from '@jest/globals';
|
import { test } from '@jest/globals';
|
||||||
|
import { exporterAssert } from './Helper';
|
||||||
import { parseXMLFile } from '../export/Helper';
|
import { parseXMLFile } from '../export/Helper';
|
||||||
import FreemindMap from '../../../src/components/export/freemind/Map';
|
import FreemindMap from '../../../src/components/export/freemind/Map';
|
||||||
import TextImporterFactory from '../../../src/components/import/TextImporterFactory';
|
import TextImporterFactory from '../../../src/components/import/TextImporterFactory';
|
||||||
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
|
|
||||||
import Mindmap from '../../../src/components/model/Mindmap';
|
|
||||||
|
|
||||||
const testNames = fs
|
const testNames = fs
|
||||||
.readdirSync(path.resolve(__dirname, './input/'))
|
.readdirSync(path.resolve(__dirname, './input/'))
|
||||||
.map((filename: string) => filename.split('.')[0]);
|
.map((filename: string) => filename.split('.')[0]);
|
||||||
|
|
||||||
describe('MMa import test execution', () => {
|
describe('MM import test execution', () => {
|
||||||
test.each(testNames)('Importing %p suite', async (testName: string) => {
|
test.each(testNames)('Importing %p suite', async (testName: string) => {
|
||||||
// load freemap...
|
// load freemap...
|
||||||
const freemapPath = path.resolve(__dirname, `./input/${testName}.mm`);
|
const freemapPath = path.resolve(__dirname, `./input/${testName}.mm`);
|
||||||
@ -20,17 +19,8 @@ describe('MMa import test execution', () => {
|
|||||||
|
|
||||||
const freemap: FreemindMap = new FreemindMap().loadFromDom(mapDocument);
|
const freemap: FreemindMap = new FreemindMap().loadFromDom(mapDocument);
|
||||||
|
|
||||||
// Load mindmap DOM..
|
|
||||||
const mindmapPath = path.resolve(__dirname, `./expected/${testName}.wxml`);
|
|
||||||
const mindmapMapDocument = parseXMLFile(mindmapPath, 'text/xml');
|
|
||||||
|
|
||||||
// Convert to mindmap...
|
|
||||||
const serializer = XMLSerializerFactory.createInstanceFromDocument(mindmapMapDocument);
|
|
||||||
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
|
|
||||||
|
|
||||||
const importer = TextImporterFactory.create('mm', freemap);
|
const importer = TextImporterFactory.create('mm', freemap);
|
||||||
const mindmapImport: Mindmap = await importer.import(testName, '');
|
|
||||||
|
|
||||||
expect(mindmapImport).toStrictEqual(mindmap);
|
await exporterAssert(testName, importer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user