From 4e1544db037c263758ed3508faa5a3d9c4537885 Mon Sep 17 00:00:00 2001 From: Ezequiel-Vega Date: Fri, 18 Mar 2022 14:23:08 -0300 Subject: [PATCH] FreemindImport return fixes --- .../src/components/import/FreemindImporter.ts | 15 +- .../src/components/import/Importer.ts | 4 +- packages/mindplot/test/unit/import/Helper.ts | 16 +- .../test/unit/import/expected/bug2.wxml | 41 +- .../test/unit/import/expected/bug3.wxml | 498 ++++++++++++++---- .../unit/import/expected/cdata-support.wxml | 54 +- .../test/unit/import/expected/complex.wxml | 365 +------------ .../test/unit/import/expected/emptyNodes.wxml | 304 +++-------- .../test/unit/import/expected/enc.wxml | 205 +------ .../test/unit/import/expected/i18n.wxml | 20 +- .../test/unit/import/expected/i18n2.wxml | 18 +- .../test/unit/import/expected/issue.wxml | 136 +---- .../test/unit/import/expected/npe.wxml | 54 +- .../test/unit/import/expected/process.wxml | 293 +++-------- .../test/unit/import/expected/sample3.wxml | 6 +- .../test/unit/import/expected/sample4.wxml | 6 +- .../test/unit/import/expected/welcome.wxml | 84 ++- 17 files changed, 731 insertions(+), 1388 deletions(-) diff --git a/packages/mindplot/src/components/import/FreemindImporter.ts b/packages/mindplot/src/components/import/FreemindImporter.ts index 7a06767e..8ba8c979 100644 --- a/packages/mindplot/src/components/import/FreemindImporter.ts +++ b/packages/mindplot/src/components/import/FreemindImporter.ts @@ -1,3 +1,4 @@ +import xmlFormatter from 'xml-formatter'; import Importer from './Importer'; import Mindmap from '../model/Mindmap'; import RelationshipModel from '../model/RelationshipModel'; @@ -19,6 +20,7 @@ import FreemindIconConverter from './FreemindIconConverter'; import NoteModel from '../model/NoteModel'; import FeatureModelFactory from '../model/FeatureModelFactory'; import FeatureModel from '../model/FeatureModel'; +import XMLSerializerFactory from '../persistence/XMLSerializerFactory'; export default class FreemindImporter extends Importer { private mindmap: Mindmap; @@ -34,7 +36,7 @@ export default class FreemindImporter extends Importer { this.freemindMap = map; } - import(nameMap: string, description: string): Promise { + import(nameMap: string, description: string): Promise { this.mindmap = new Mindmap(nameMap); this.nodesmap = new Map(); this.relationship = new Array(); @@ -69,7 +71,16 @@ export default class FreemindImporter extends Importer { this.mindmap.setDescription(description); this.mindmap.addBranch(wiseTopic); - return Promise.resolve(this.mindmap); + const serialize = XMLSerializerFactory.createInstanceFromMindmap(this.mindmap); + const domMindmap = serialize.toXML(this.mindmap); + const xmlToString = new XMLSerializer().serializeToString(domMindmap); + const formatXml = xmlFormatter(xmlToString, { + indentation: ' ', + collapseContent: true, + lineSeparator: '\n', + }); + + return Promise.resolve(formatXml); } private addRelationship(mindmap: Mindmap): void { diff --git a/packages/mindplot/src/components/import/Importer.ts b/packages/mindplot/src/components/import/Importer.ts index c4749c97..249a0a7a 100644 --- a/packages/mindplot/src/components/import/Importer.ts +++ b/packages/mindplot/src/components/import/Importer.ts @@ -1,5 +1,3 @@ -import Mindmap from '../model/Mindmap'; - export default abstract class Importer { - abstract import(nameMap: string, description: string): Promise; + abstract import(nameMap: string, description: string): Promise; } diff --git a/packages/mindplot/test/unit/import/Helper.ts b/packages/mindplot/test/unit/import/Helper.ts index 3649b4b6..a78553a9 100644 --- a/packages/mindplot/test/unit/import/Helper.ts +++ b/packages/mindplot/test/unit/import/Helper.ts @@ -5,7 +5,8 @@ import path from 'path'; import { expect } from '@jest/globals'; import { diff } from 'jest-diff'; import Importer from '../../../src/components/import/Importer'; -import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory'; + +const saveOutputRecord = false; export const parseXMLString = (xmlStr: string, mimeType: DOMParserSupportedType) => { const parser = new DOMParser(); @@ -38,17 +39,18 @@ export const parseXMLFile = (filePath: fs.PathOrFileDescriptor, mimeType: DOMPar export const exporterAssert = async (testName: string, importer: Importer) => { const actualMindmap = await importer.import(testName, ''); - // Load mindmap DOM.. + // Load mindmap file.. const mindmapPath = path.resolve(__dirname, `./expected/${testName}.wxml`); - const mindmapDocument = parseXMLFile(mindmapPath, 'text/xml'); - const serializer = XMLSerializerFactory.createInstanceFromDocument(mindmapDocument); - const mindmapExpect = serializer.loadFromDom(mindmapDocument, testName); + if (saveOutputRecord) { + fs.writeFileSync(mindmapPath, actualMindmap); + } + + const mindmapExpect = fs.readFileSync(mindmapPath).toString(); // Compare with expected... if (actualMindmap !== mindmapExpect) { const diffResult = diff(actualMindmap, mindmapExpect); console.log(diffResult); - - expect(actualMindmap.toString()).toEqual(mindmapExpect.toString()); + expect(actualMindmap).toEqual(mindmapExpect); } }; diff --git a/packages/mindplot/test/unit/import/expected/bug2.wxml b/packages/mindplot/test/unit/import/expected/bug2.wxml index 4e7394c4..fc1bad98 100644 --- a/packages/mindplot/test/unit/import/expected/bug2.wxml +++ b/packages/mindplot/test/unit/import/expected/bug2.wxml @@ -1,21 +1,21 @@ - + - - + + - - - - - - - - + + + + + + + + - + @@ -28,17 +28,12 @@ - - - - - - + + + + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/bug3.wxml b/packages/mindplot/test/unit/import/expected/bug3.wxml index 257e8977..50b48f6e 100644 --- a/packages/mindplot/test/unit/import/expected/bug3.wxml +++ b/packages/mindplot/test/unit/import/expected/bug3.wxml @@ -1,102 +1,412 @@ - - - - - - - + + + + + + + - + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + - - - - + + + - - - - + + + + - - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/cdata-support.wxml b/packages/mindplot/test/unit/import/expected/cdata-support.wxml index 4d262220..a0b3d4c2 100644 --- a/packages/mindplot/test/unit/import/expected/cdata-support.wxml +++ b/packages/mindplot/test/unit/import/expected/cdata-support.wxml @@ -1,53 +1,3 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/complex.wxml b/packages/mindplot/test/unit/import/expected/complex.wxml index c9e716e6..903d45f5 100644 --- a/packages/mindplot/test/unit/import/expected/complex.wxml +++ b/packages/mindplot/test/unit/import/expected/complex.wxml @@ -1,352 +1,25 @@ - - - - - + + + + + - - - - - - - + + + + + + + - - - - - + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/emptyNodes.wxml b/packages/mindplot/test/unit/import/expected/emptyNodes.wxml index 9c08eb07..47288b6b 100644 --- a/packages/mindplot/test/unit/import/expected/emptyNodes.wxml +++ b/packages/mindplot/test/unit/import/expected/emptyNodes.wxml @@ -1,239 +1,89 @@ - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - - - - - - - - + + + + + + - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - - - - + + + + + + + + - - + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/enc.wxml b/packages/mindplot/test/unit/import/expected/enc.wxml index 36358ae4..c78c54b5 100644 --- a/packages/mindplot/test/unit/import/expected/enc.wxml +++ b/packages/mindplot/test/unit/import/expected/enc.wxml @@ -1,187 +1,34 @@ - + - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - + + + diff --git a/packages/mindplot/test/unit/import/expected/i18n.wxml b/packages/mindplot/test/unit/import/expected/i18n.wxml index 678c2c6c..302aa541 100644 --- a/packages/mindplot/test/unit/import/expected/i18n.wxml +++ b/packages/mindplot/test/unit/import/expected/i18n.wxml @@ -1,15 +1,7 @@ - - - - - - - - - - - - - + + + + + - + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/i18n2.wxml b/packages/mindplot/test/unit/import/expected/i18n2.wxml index 94ce5659..dd5b32e8 100644 --- a/packages/mindplot/test/unit/import/expected/i18n2.wxml +++ b/packages/mindplot/test/unit/import/expected/i18n2.wxml @@ -1,14 +1,8 @@ - - - - - - - - - - + + + + + - + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/issue.wxml b/packages/mindplot/test/unit/import/expected/issue.wxml index e957fa3d..8bdb38f9 100644 --- a/packages/mindplot/test/unit/import/expected/issue.wxml +++ b/packages/mindplot/test/unit/import/expected/issue.wxml @@ -1,120 +1,36 @@ - - - - - - - - - + + + + + - - - - + + - - - - + + - - - - - - - + + + + + - - - - - - - - - + + + + + + - - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/npe.wxml b/packages/mindplot/test/unit/import/expected/npe.wxml index 359233bb..086c7442 100644 --- a/packages/mindplot/test/unit/import/expected/npe.wxml +++ b/packages/mindplot/test/unit/import/expected/npe.wxml @@ -1,51 +1,3 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/process.wxml b/packages/mindplot/test/unit/import/expected/process.wxml index b423097e..5a38fa1c 100644 --- a/packages/mindplot/test/unit/import/expected/process.wxml +++ b/packages/mindplot/test/unit/import/expected/process.wxml @@ -1,225 +1,100 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + - - - - - - + + + + + + + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - + + + + - - - - - - - - - - - - - - - - - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + - - - + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/sample3.wxml b/packages/mindplot/test/unit/import/expected/sample3.wxml index 251d41cc..e94e61f5 100644 --- a/packages/mindplot/test/unit/import/expected/sample3.wxml +++ b/packages/mindplot/test/unit/import/expected/sample3.wxml @@ -1,3 +1,3 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/sample4.wxml b/packages/mindplot/test/unit/import/expected/sample4.wxml index 15beda65..f5c6506f 100644 --- a/packages/mindplot/test/unit/import/expected/sample4.wxml +++ b/packages/mindplot/test/unit/import/expected/sample4.wxml @@ -1,3 +1,3 @@ - \ No newline at end of file + + + \ No newline at end of file diff --git a/packages/mindplot/test/unit/import/expected/welcome.wxml b/packages/mindplot/test/unit/import/expected/welcome.wxml index b570a101..70cd21fc 100644 --- a/packages/mindplot/test/unit/import/expected/welcome.wxml +++ b/packages/mindplot/test/unit/import/expected/welcome.wxml @@ -1,70 +1,48 @@ - - - - - + + + - - - - - - - - + + + + - - + + - - - - - - - - - - + + + + + + - - - - - - + + + + + - - - - - - - + + + + - - - - + + - + - - - - - - - + + + + - \ No newline at end of file