Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEST] Improve integration tests about the lib initialization #2068

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/component/mxgraph/GraphConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default class GraphConfigurator {
this.graph.setPanning(true);

// Zoom configuration
this.graph.createMouseWheelZoomExperience(options?.navigation?.zoom);
this.graph.createMouseWheelZoomExperience(options.navigation.zoom);
} else {
this.graph.setPanning(false);
// Disable gesture support for zoom
Expand Down
19 changes: 16 additions & 3 deletions test/integration/BpmnVisualization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,24 @@
*/

import { readFileSync } from '../helpers/file-helper';
import { initializeBpmnVisualizationWithHtmlElement } from './helpers/bpmn-visualization-initialization';
import type { GlobalOptionsWithoutContainer } from './helpers/bpmn-visualization-initialization';
import { initializeBpmnVisualization, initializeBpmnVisualizationWithHtmlElement } from './helpers/bpmn-visualization-initialization';

const bpmnVisualization = initializeBpmnVisualizationWithHtmlElement('bpmn-container', true);
describe('BpmnVisualization initialization', () => {
it.each`
configName | config
${'undefined'} | ${undefined}
${'navigation disabled'} | ${{ navigation: { enabled: false } }}
${'navigation without zoom config'} | ${{ navigation: { enabled: true } }}
${'navigation with zoom config'} | ${{ navigation: { enabled: true, zoom: { throttleDelay: 20 } } }}
`(`Verify correct initialization with '$configName' configuration`, ({ configName, config }: { configName: string; config: GlobalOptionsWithoutContainer }) => {
initializeBpmnVisualization(`bpmn-visualization-init-check-with-config-${configName}`, config);
});
});

describe('BpmnVisualization API', () => {
const bpmnVisualization = initializeBpmnVisualizationWithHtmlElement('bpmn-container', true);

describe('BpmnVisualization', () => {
it('Load invalid diagram (text file)', async () => {
expect(() => bpmnVisualization.load(readFileSync('../fixtures/bpmn/xml-parsing/special/text-only.txt'))).toThrow(
`XML parsing failed. Unable to retrieve 'definitions' from the BPMN source.`,
Expand Down
19 changes: 19 additions & 0 deletions test/integration/config/hide-console-warnings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright 2022 Bonitasoft S.A.
*
* 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.
*/

jest.spyOn(console, 'warn').mockImplementation(() => {
// do not display actual console outputs during tests (generated by the parsing code)
});
14 changes: 8 additions & 6 deletions test/integration/helpers/bpmn-visualization-initialization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@
* limitations under the License.
*/

import { BpmnVisualization } from '../../../src/bpmn-visualization';
import { BpmnVisualization, type GlobalOptions } from '../../../src/bpmn-visualization';
import { insertBpmnContainer } from './dom-utils';

export function initializeBpmnVisualization(containerId?: string): BpmnVisualization {
export type GlobalOptionsWithoutContainer = Omit<GlobalOptions, 'container'>;

export const initializeBpmnVisualization = (containerId?: string, options?: GlobalOptionsWithoutContainer): BpmnVisualization => {
const bpmnContainerId = containerId ?? 'bpmn-visualization-container';
insertBpmnContainer(bpmnContainerId);
return new BpmnVisualization({ container: bpmnContainerId });
}
return new BpmnVisualization({ container: bpmnContainerId, ...options });
};

export function initializeBpmnVisualizationWithHtmlElement(containerId?: string, withNavigation = false): BpmnVisualization {
export const initializeBpmnVisualizationWithHtmlElement = (containerId?: string, withNavigation = false): BpmnVisualization => {
const bpmnContainerId = containerId ?? 'bpmn-visualization-container-alternative';
const options = { container: insertBpmnContainer(bpmnContainerId), navigation: { enabled: withNavigation } };
return new BpmnVisualization(options);
}
};
6 changes: 5 additions & 1 deletion test/integration/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ module.exports = {
coveragePathIgnorePatterns: ['/src/model/'],
coverageReporters: ['lcov', 'text-summary'],
coverageDirectory: 'build/test-report/integration',
setupFilesAfterEnv: ['./test/integration/config/mxgraph-config.ts'],
setupFilesAfterEnv: [
'./test/integration/config/mxgraph-config.ts',
// put at the latest place to see logs that could be displayed by setup files
'./test/integration/config/hide-console-warnings.js',
],
reporters: [
'default',
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { EdgeUnknownBpmnElementWarning } from '../../../../../src/component/pars
describe('parse bpmn as json for edges', () => {
// this also covers unsupported bpmn element types that are then not retrieved during the parsing
it('should not convert as Edge without related BPMN element', () => {
jest.spyOn(console, 'warn').mockImplementation();
const json = {
definitions: {
targetNamespace: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,6 @@ describe('parse bpmn as json for label font', () => {
});

it("should convert as Shape without Font, when a BPMNShape (who references a non-existing BPMNLabelStyle) is an attribute (as object) of 'BPMNPlane' (as object)", () => {
jest.spyOn(console, 'warn').mockImplementation();
const json = {
definitions: {
targetNamespace: '',
Expand Down Expand Up @@ -473,7 +472,6 @@ describe('parse bpmn as json for label font', () => {
});

it("should convert as Edge without Font, when a BPMNEdge (which references a non-existing BPMNLabelStyle) is an attribute (as object) of 'BPMNPlane' (as object)", () => {
jest.spyOn(console, 'warn').mockImplementation();
const json = {
definitions: {
targetNamespace: '',
Expand Down
2 changes: 1 addition & 1 deletion test/unit/component/parser/parsing-messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import { ShapeBpmnElementKind } from '../../../../src/model/bpmn/internal';
import { ParsingMessageCollector } from '../../../../src/component/parser/parsing-messages';
import { ShapeBpmnElementKind } from '../../../../src/model/bpmn/internal/shape';
import {
EdgeUnknownBpmnElementWarning,
GroupUnknownCategoryValueWarning,
Expand Down