Added test helper

This commit is contained in:
Ezequiel-Vega 2022-03-10 12:26:24 -03:00
parent a2d655e0b9
commit 356c22b391
2 changed files with 25 additions and 14 deletions

View 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);
};

View File

@ -1,18 +1,17 @@
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import fs from 'fs';
// eslint-disable-next-line import/no-extraneous-dependencies
import { test } from '@jest/globals';
import { exporterAssert } from './Helper';
import { parseXMLFile } from '../export/Helper';
import FreemindMap from '../../../src/components/export/freemind/Map';
import TextImporterFactory from '../../../src/components/import/TextImporterFactory';
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
import Mindmap from '../../../src/components/model/Mindmap';
const testNames = fs
.readdirSync(path.resolve(__dirname, './input/'))
.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) => {
// load freemap...
const freemapPath = path.resolve(__dirname, `./input/${testName}.mm`);
@ -20,17 +19,8 @@ describe('MMa import test execution', () => {
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 mindmapImport: Mindmap = await importer.import(testName, '');
expect(mindmapImport).toStrictEqual(mindmap);
await exporterAssert(testName, importer);
});
});