From fe33c71c11e90f4fdffaa7dafec34730143cf7ee Mon Sep 17 00:00:00 2001 From: Guillaume Dufour Date: Thu, 3 Nov 2016 00:32:28 +0100 Subject: [PATCH] #221 Support Package add unit test --- test/editors/genmymodel_parser_test.js | 7 +- test/editors/modelio_parser_test.js | 51 +++++++++++--- test/editors/parser_helper_test.js | 14 +++- test/editors/umldesigner_parser_test.js | 5 +- test/xmi/genmymodel_package.xmi | 90 +++++++++++++++---------- test/xmi/modelio_packages2.xmi | 39 +++++++++++ test/xmi/umldesigner_package.uml | 56 +++++++-------- 7 files changed, 184 insertions(+), 78 deletions(-) create mode 100644 test/xmi/modelio_packages2.xmi diff --git a/test/editors/genmymodel_parser_test.js b/test/editors/genmymodel_parser_test.js index 7f134ae..4cfd47f 100644 --- a/test/editors/genmymodel_parser_test.js +++ b/test/editors/genmymodel_parser_test.js @@ -284,12 +284,13 @@ describe('GenMyModelParser', () => { expect(parsedData).not.to.be.null; }); it('includes classes in package', () => { - expect(parsedData.classes['_54pHLZ-oEeawbN_F_HFDxg']).not.to.be.null; - expect(parsedData.classes['_54pHQJ-oEeawbN_F_HFDxg']).not.to.be.null; + expect(parsedData.classes['_z3DqLaFTEeawbN_F_HFDxg']).not.to.be.null; + expect(parsedData.classes['_z3DqQ6FTEeawbN_F_HFDxg']).not.to.be.null; expect(parsedData.classNames).to.deep.eq(['A','B']); + expect(parsedData.enums['_z3DqRqFTEeawbN_F_HFDxg']).not.to.be.null; + expect(parsedData.associations['_z3DqM6FTEeawbN_F_HFDxg']).not.to.be.null; }); }); - }); describe('when passing an invalid diagram', () => { describe('as a class has no name', () => { diff --git a/test/editors/modelio_parser_test.js b/test/editors/modelio_parser_test.js index 0296ed1..29b9444 100644 --- a/test/editors/modelio_parser_test.js +++ b/test/editors/modelio_parser_test.js @@ -279,18 +279,49 @@ describe('ModelioParser', () => { }); }); describe('with packages', () => { - var parserData = ParserFactory.createParser({ - file: './test/xmi/modelio_packages.xmi', - databaseType: 'sql' - }); - var parser = parserData.parser; - var parsedData = parser.parse(parserData.data); + describe('simple model', () => { + var parserData = ParserFactory.createParser({ + file: './test/xmi/modelio_packages.xmi', + databaseType: 'sql' + }); + var parser = parserData.parser; + var parsedData = parser.parse(parserData.data); - it('parses it', () => { - expect(parsedData).not.to.be.null; + it('parses it', () => { + expect(parsedData).not.to.be.null; + }); + it('works by adding all the classes', () => { + expect(parsedData.classNames).to.deep.eq(['Class1', 'Class3', 'Class2']); + expect(parsedData.classes['_vC4sxHdfEeaWkfx80xqrTw']).not.to.be.null; + expect(parsedData.classes['_vC4syndfEeaWkfx80xqrTw']).not.to.be.null; + expect(parsedData.classes['_vC4sz3dfEeaWkfx80xqrTw']).not.to.be.null; + expect(parsedData.associations['_vC4sx3dfEeaWkfx80xqrTw']).not.to.be.null; + expect(parsedData.associations['_vC4szXdfEeaWkfx80xqrTw']).not.to.be.null; + + }); }); - it('works by adding all the classes', () => { - expect(parsedData.classNames).to.deep.eq(['Class1', 'Class3', 'Class2']); + describe('more complex model', () => { + var parserData = ParserFactory.createParser({ + file: './test/xmi/modelio_packages2.xmi', + databaseType: 'sql' + }); + var parser = parserData.parser; + var parsedData = parser.parse(parserData.data); + + it('parses it', () => { + expect(parsedData).not.to.be.null; + }); + it('works by adding all the classes', () => { + expect(parsedData.classNames).to.deep.eq(['Class1', 'Class3', 'Class2']); + expect(parsedData.classes['_bYuIdaFSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.classes['_bYuviqFSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.classes['_bYuvj6FSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.enums['_bYuvi6FSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.associations['_bYuvhaFSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.associations['_bYuvg6FSEeaVvapPODu8lg']).not.to.be.null; + expect(parsedData.associations['_bYuvh6FSEeaVvapPODu8lg']).not.to.be.null; + + }); }); }); }); diff --git a/test/editors/parser_helper_test.js b/test/editors/parser_helper_test.js index 4fb4817..0eaa3e7 100644 --- a/test/editors/parser_helper_test.js +++ b/test/editors/parser_helper_test.js @@ -2,7 +2,8 @@ var expect = require('chai').expect, isAnId = require('../../lib/editors/parser_helper').isAnId, - extractClassName = require('../../lib/editors/parser_helper').extractClassName; + extractClassName = require('../../lib/editors/parser_helper').extractClassName, + getXmlElementFromRawIndexes = require('../../lib/editors/parser_helper').getXmlElementFromRawIndexes; describe('ParserHelper', () => { describe('#isAnId', () => { @@ -37,4 +38,15 @@ describe('ParserHelper', () => { }); }); }); + describe('#getXmlElementFromRawIndexes', () => { + var root = { packagedElement : [{dumb: 'dumb'}, { packagedElement: [{dumb: 'dumb'},{dumb: 'dumb'},{dumb: 'good'}]}]}; + var rawIndexes = [{index: 2, path: [1]}]; + var i = 0; + var xmlElt = getXmlElementFromRawIndexes(root, rawIndexes, i); + + it('returns the right element', () => { + expect(xmlElt.dumb).to.eq('good'); + }); + }); + }); diff --git a/test/editors/umldesigner_parser_test.js b/test/editors/umldesigner_parser_test.js index 82591e2..764d177 100644 --- a/test/editors/umldesigner_parser_test.js +++ b/test/editors/umldesigner_parser_test.js @@ -368,7 +368,10 @@ This sucks.` it('includes classes in package', () => { expect(parsedData.classes['_wx0Db4PVEeaFY_lPQPbINQ']).not.to.be.null; expect(parsedData.classes['_wx0DdoPVEeaFY_lPQPbINQ']).not.to.be.null; - expect(parsedData.classNames).to.deep.eq(['A','B']); + expect(parsedData.classNames).to.deep.eq(['B','A']); + expect(parsedData.enums['_dRpdIKFLEeaWHdu8QjKipg']).not.to.be.null; + expect(parsedData.associations['_vB6ZwKFLEeaWHdu8QjKipg']).not.to.be.null; + expect(parsedData.associations['_9ZrJgKFLEeaWHdu8QjKipg']).not.to.be.null; }); }); }); diff --git a/test/xmi/genmymodel_package.xmi b/test/xmi/genmymodel_package.xmi index 356b1a9..2aad860 100644 --- a/test/xmi/genmymodel_package.xmi +++ b/test/xmi/genmymodel_package.xmi @@ -1,58 +1,78 @@ - - -
-
+ + +
+
- - -
+ + +
- - -
+ + +
- - -
+ + +
- - -
+ + +
+ + +
+ + - - -
+ + +
- - -
+ + +
- - + + - - -
+ + +
- - + + - - -
+ + +
- - -
+ + +
+ + +
+ + + +
+ + + + +
+ + + diff --git a/test/xmi/modelio_packages2.xmi b/test/xmi/modelio_packages2.xmi new file mode 100644 index 0000000..35a8ca8 --- /dev/null +++ b/test/xmi/modelio_packages2.xmi @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/xmi/umldesigner_package.uml b/test/xmi/umldesigner_package.uml index 3adb1fa..ae004dc 100644 --- a/test/xmi/umldesigner_package.uml +++ b/test/xmi/umldesigner_package.uml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + +