From 7037fb69323fa4252d1a396ee4a71aaff1cece28 Mon Sep 17 00:00:00 2001 From: mauriziovitale84 Date: Wed, 2 Nov 2016 10:20:54 +0000 Subject: [PATCH] Add swimlanes component unit test --- .../src/assets/diagramSwimlanes.mock.ts | 44 ++++++++++++++ .../src/components/diagram.component.spec.ts | 60 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 ng2-components/ng2-activiti-diagrams/src/assets/diagramSwimlanes.mock.ts diff --git a/ng2-components/ng2-activiti-diagrams/src/assets/diagramSwimlanes.mock.ts b/ng2-components/ng2-activiti-diagrams/src/assets/diagramSwimlanes.mock.ts new file mode 100644 index 0000000000..e9d41c2131 --- /dev/null +++ b/ng2-components/ng2-activiti-diagrams/src/assets/diagramSwimlanes.mock.ts @@ -0,0 +1,44 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export let pool = { + id: 'sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716', + name: 'Activiti', + width: 600, + height: 500, + x: 60, + y: 45, + properties: [{}] +}; + +export let poolLanes = { + id: 'sid-0FF10DA3-E2BD-4E6A-9013-6D66FC8A4716', + name: 'Activiti', + width: 600, + height: 500, + x: 60, + y: 45, + lanes: [{ + id: 'sid-332204AB-D0F8-44CD-87B3-BF9DF59FF8AB', + name: 'Beckend', + width: 570, + height: 250, + x: 90, + y: 45 + }], + properties: [{}] +}; diff --git a/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.spec.ts b/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.spec.ts index 1cfac45436..7587452688 100644 --- a/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.spec.ts +++ b/ng2-components/ng2-activiti-diagrams/src/components/diagram.component.spec.ts @@ -31,6 +31,7 @@ import * as intermediateCatchingMock from '../assets/diagramIntermediate.mock'; import * as boundaryEventMock from '../assets/diagramBoundary.mock'; import * as throwEventMock from '../assets/diagramThrow.mock'; import * as structuralMock from '../assets/diagramStructural.mock'; +import * as swimLanesMock from '../assets/diagramSwimlanes.mock'; declare let jasmine: any; @@ -1158,4 +1159,63 @@ describe('Test ng2-activiti-diagrams ', () => { }); })); }); + + describe('Diagrams component Swim lane: ', () => { + beforeEach(() => { + jasmine.Ajax.install(); + component.processDefinitionId = 'fakeprocess:24:38399'; + component.metricPercentages = {startEvent: 0}; + }); + + afterEach(() => { + jasmine.Ajax.uninstall(); + }); + + it('Should render the Pool', async(() => { + component.onSuccess.subscribe((res) => { + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(res).not.toBeNull(); + let shape: any = element.querySelector('diagram-pool > raphael-rect'); + expect(shape).not.toBeNull(); + + let shapeText: any = element.querySelector('diagram-pool > raphael-text'); + expect(shapeText).not.toBeNull(); + expect(shapeText.attributes[2].value).toEqual('Activiti'); + }); + }); + component.ngOnChanges(); + let resp = {pools: [swimLanesMock.pool]}; + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: resp + }); + })); + + it('Should render the Pool with Lanes', async(() => { + component.onSuccess.subscribe((res) => { + fixture.detectChanges(); + fixture.whenStable().then(() => { + expect(res).not.toBeNull(); + let shapeLane: any = element.querySelector('diagram-lanes > div > div > diagram-lane'); + expect(shapeLane).not.toBeNull(); + + let shapeRect: any = element.querySelector('diagram-lanes > div > div > diagram-lane > raphael-rect'); + expect(shapeRect).not.toBeNull(); + + let shapeText: any = element.querySelector('diagram-lanes > div > div > diagram-lane > raphael-text'); + expect(shapeText).not.toBeNull(); + expect(shapeText.attributes[2].value).toEqual('Beckend'); + }); + }); + component.ngOnChanges(); + let resp = {pools: [swimLanesMock.poolLanes]}; + jasmine.Ajax.requests.mostRecent().respondWith({ + status: 200, + contentType: 'json', + responseText: resp + }); + })); + }); });