wisemapping-frontend/packages/mindplot/test/unit/export/TextExporterTestSuite.test.ts

75 lines
2.9 KiB
TypeScript
Raw Permalink Normal View History

2022-01-02 19:37:33 +01:00
import path from 'path';
2022-01-24 20:24:16 +01:00
import fs from 'fs';
import { test } from '@jest/globals'; // Workaround for cypress conflict
import Mindmap from '../../../src/components/model/Mindmap';
2022-01-02 19:37:33 +01:00
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
import TextExporterFactory from '../../../src/components/export/TextExporterFactory';
import { parseXMLFile, setupBlob, exporterAssert } from './Helper';
setupBlob();
2022-02-11 22:33:22 +01:00
const testNames = fs
.readdirSync(path.resolve(__dirname, './input/'))
2022-01-24 20:24:16 +01:00
.filter((f) => f.endsWith('.wxml'))
.map((filename: string) => filename.split('.')[0]);
2022-01-12 02:52:54 +01:00
2022-01-02 19:37:33 +01:00
describe('WXML export test execution', () => {
2022-01-24 20:24:16 +01:00
test.each(testNames)('Exporting %p suite', async (testName: string) => {
// Load mindmap DOM ...
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
// Convert to mindmap ...
2023-01-15 04:31:01 +01:00
const serializer = XMLSerializerFactory.createFromDocument(mapDocument);
2022-01-24 20:24:16 +01:00
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
const exporter = TextExporterFactory.create('wxml', mindmap);
await exporterAssert(testName, exporter);
2022-01-02 19:37:33 +01:00
});
2022-01-24 20:24:16 +01:00
});
2022-01-02 19:37:33 +01:00
2022-01-24 20:24:16 +01:00
describe('Txt export test execution', () => {
test.each(testNames)('Exporting %p suite', async (testName: string) => {
// Load mindmap DOM ...
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
// Convert to mindmap ...
2023-01-15 04:31:01 +01:00
const serializer = XMLSerializerFactory.createFromDocument(mapDocument);
2022-01-24 20:24:16 +01:00
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
const exporter = TextExporterFactory.create('txt', mindmap);
await exporterAssert(testName, exporter);
});
});
describe('MD export test execution', () => {
test.each(testNames)('Exporting %p suite', async (testName: string) => {
// Load mindmap DOM ...
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
// Convert to mindmap ...
2023-01-15 04:31:01 +01:00
const serializer = XMLSerializerFactory.createFromDocument(mapDocument);
2022-01-24 20:24:16 +01:00
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
const exporter = TextExporterFactory.create('md', mindmap);
await exporterAssert(testName, exporter);
});
});
2022-02-11 22:33:22 +01:00
describe('MM export test execution', () => {
test.each(testNames)('Exporting %p suite', async (testName: string) => {
2022-02-18 17:08:08 +01:00
// Load mindmap DOM..
2022-02-11 22:33:22 +01:00
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
// Convert to mindmap...
2023-01-15 04:31:01 +01:00
const serializer = XMLSerializerFactory.createFromDocument(mapDocument);
2022-02-11 22:33:22 +01:00
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
const exporter = TextExporterFactory.create('mm', mindmap);
await exporterAssert(testName, exporter);
});
});