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

33 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-12-30 02:10:28 +01:00
import path from 'path';
2022-01-02 19:37:33 +01:00
import fs from 'fs';
import { expect, test } from '@jest/globals'; // Workaround for cypress conflict
2022-01-24 20:24:16 +01:00
import Mindmap from '../../../src/components/model/Mindmap';
2021-12-30 02:10:28 +01:00
import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory';
import SVGExporter from '../../../src/components/export/SVGExporter';
2022-01-02 19:37:33 +01:00
import { parseXMLFile, setupBlob, exporterAssert } from './Helper';
setupBlob();
describe('SVG export test execution', () => {
test.each(fs.readdirSync(path.resolve(__dirname, './input/'))
.filter((f) => f.endsWith('.wxml'))
2022-01-24 20:24:16 +01:00
.map((filename: string) => filename.split('.')[0]))('Exporting %p suite', async (testName: string) => {
// Load mindmap DOM ...
const mindmapPath = path.resolve(__dirname, `./input/${testName}.wxml`);
const mapDocument = parseXMLFile(mindmapPath, 'text/xml');
2022-01-02 19:37:33 +01:00
2022-01-24 20:24:16 +01:00
// Convert to mindmap ...
const serializer = XMLSerializerFactory.createInstanceFromDocument(mapDocument);
const mindmap: Mindmap = serializer.loadFromDom(mapDocument, testName);
2022-01-02 19:37:33 +01:00
2022-01-24 20:24:16 +01:00
// Load SVG ...
const svgPath = path.resolve(__dirname, `./input/${testName}.svg`);
expect(fs.existsSync(svgPath)).toEqual(true);
const svgDocument = parseXMLFile(svgPath, 'image/svg+xml');
2022-01-02 19:37:33 +01:00
2022-01-24 20:24:16 +01:00
// Generate output ...
const exporter = new SVGExporter(mindmap, svgDocument.documentElement);
await exporterAssert(testName, exporter);
});
2021-12-30 02:10:28 +01:00
});