|
| 1 | +/* |
| 2 | +Copyright 2025 Bonitasoft S.A. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | +http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +import type { ImageSnapshotThresholdConfig } from './helpers/visu/image-snapshot-config'; |
| 18 | + |
| 19 | +import { ImageSnapshotConfigurator, MultiBrowserImageSnapshotThresholds } from './helpers/visu/image-snapshot-config'; |
| 20 | + |
| 21 | +import { AvailableTestPages, PageTester } from '@test/shared/visu/bpmn-page-utils'; |
| 22 | + |
| 23 | +class ImageSnapshotThresholdsActivityLabelBounds extends MultiBrowserImageSnapshotThresholds { |
| 24 | + constructor() { |
| 25 | + super({ chromium: 0 / 100, firefox: 0 / 100, webkit: 0 / 100 }); |
| 26 | + } |
| 27 | + |
| 28 | + protected override getChromiumThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 29 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 30 | + [ |
| 31 | + 'activities.with.wrongly.positioned.labels.not-ignored', |
| 32 | + { |
| 33 | + macos: 0.19 / 100, // 0.18413140767182812% |
| 34 | + windows: 0.22 / 100, // 0.21177195104159496% |
| 35 | + }, |
| 36 | + ], |
| 37 | + [ |
| 38 | + 'activities.with.wrongly.positioned.labels.ignored', |
| 39 | + { |
| 40 | + macos: 0.29 / 100, // 0.28115982788768923% |
| 41 | + windows: 0.28 / 100, // 0.27545483944123594% |
| 42 | + }, |
| 43 | + ], |
| 44 | + ]); |
| 45 | + } |
| 46 | + |
| 47 | + protected override getFirefoxThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 48 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 49 | + [ |
| 50 | + 'activities.with.wrongly.positioned.labels.not-ignored', |
| 51 | + { |
| 52 | + linux: 0.23 / 100, // 0.2236111574782207% |
| 53 | + macos: 0.36 / 100, // 0.35012765743468455% |
| 54 | + windows: 1.32 / 100, // 1.3103779470739596% |
| 55 | + }, |
| 56 | + ], |
| 57 | + [ |
| 58 | + 'activities.with.wrongly.positioned.labels.ignored', |
| 59 | + { |
| 60 | + linux: 0.85 / 100, // 0.8457215876566115% |
| 61 | + macos: 0.64 / 100, // 0.634897664634726% |
| 62 | + windows: 1.9 / 100, // 1.8900990794732508% |
| 63 | + }, |
| 64 | + ], |
| 65 | + ]); |
| 66 | + } |
| 67 | + |
| 68 | + protected override getWebkitThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 69 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 70 | + [ |
| 71 | + 'activities.with.wrongly.positioned.labels.not-ignored', |
| 72 | + { |
| 73 | + macos: 0.44 / 100, // 0.4382175377357411% |
| 74 | + }, |
| 75 | + ], |
| 76 | + [ |
| 77 | + 'activities.with.wrongly.positioned.labels.ignored', |
| 78 | + { |
| 79 | + macos: 1.5 / 100, // 1.4951298719464878% |
| 80 | + }, |
| 81 | + ], |
| 82 | + ]); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +class ImageSnapshotThresholdsLabelStyles extends MultiBrowserImageSnapshotThresholds { |
| 87 | + constructor() { |
| 88 | + super({ chromium: 0 / 100, firefox: 0 / 100, webkit: 0 / 100 }); |
| 89 | + } |
| 90 | + |
| 91 | + protected override getChromiumThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 92 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 93 | + [ |
| 94 | + 'labels.with.font.styles.not-ignored', |
| 95 | + { |
| 96 | + macos: 0.17 / 100, // 0.16518659366272503% |
| 97 | + windows: 0.16 / 100, // 0.1578221549419112% |
| 98 | + }, |
| 99 | + ], |
| 100 | + [ |
| 101 | + 'labels.with.font.styles.ignored', |
| 102 | + { |
| 103 | + macos: 0.21 / 100, // 0.20961855005547925% |
| 104 | + windows: 0.29 / 100, // 0.2864761242524328% |
| 105 | + }, |
| 106 | + ], |
| 107 | + ]); |
| 108 | + } |
| 109 | + |
| 110 | + protected override getFirefoxThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 111 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 112 | + [ |
| 113 | + 'labels.with.font.styles.not-ignored', |
| 114 | + { |
| 115 | + // very large number because of firefox rendering differences compared to chrome (font) |
| 116 | + // this test requires to use a dedicated reference screenshot, see https://github.com/process-analytics/bpmn-visualization-js/issues/2838 |
| 117 | + linux: 4.53 / 100, // 4.529968414713514% |
| 118 | + macos: 0.5 / 100, // 0.49100385220669507% |
| 119 | + windows: 2.1 / 100, // 2.096414153407533% |
| 120 | + }, |
| 121 | + ], |
| 122 | + [ |
| 123 | + 'labels.with.font.styles.ignored', |
| 124 | + { |
| 125 | + linux: 0.06 / 100, // 0.05351232277721607% |
| 126 | + macos: 0.26 / 100, // 0.2513269855389466% |
| 127 | + windows: 1.64 / 100, // 1.637503468193735% |
| 128 | + }, |
| 129 | + ], |
| 130 | + ]); |
| 131 | + } |
| 132 | + |
| 133 | + protected override getWebkitThresholds(): Map<string, ImageSnapshotThresholdConfig> { |
| 134 | + return new Map<string, ImageSnapshotThresholdConfig>([ |
| 135 | + [ |
| 136 | + 'labels.with.font.styles.not-ignored', |
| 137 | + { |
| 138 | + macos: 0.31 / 100, // 0.30621380597637415% |
| 139 | + }, |
| 140 | + ], |
| 141 | + [ |
| 142 | + 'labels.with.font.styles.ignored', |
| 143 | + { |
| 144 | + macos: 0.38 / 100, // 0.37988509633168904% |
| 145 | + }, |
| 146 | + ], |
| 147 | + ]); |
| 148 | + } |
| 149 | +} |
| 150 | + |
| 151 | +function getConfigName(bpmnDiagramName: string, ignoredOption: boolean): string { |
| 152 | + return bpmnDiagramName + '.' + (ignoredOption ? 'ignored' : 'not-ignored'); |
| 153 | +} |
| 154 | + |
| 155 | +describe('BPMN rendering - ignore options', () => { |
| 156 | + const diagramSubfolder = 'bpmn-rendering-ignore-options'; |
| 157 | + const pageTester = new PageTester({ targetedPage: AvailableTestPages.BPMN_RENDERING, diagramSubfolder }, page); |
| 158 | + |
| 159 | + describe('Ignore activity label bounds', () => { |
| 160 | + const bpmnDiagramName = 'activities.with.wrongly.positioned.labels'; |
| 161 | + |
| 162 | + describe.each([false, true])('ignoreBpmnActivityLabelBounds: %s', (ignoreBpmnActivityLabelBounds: boolean) => { |
| 163 | + const imageSnapshotConfigurator = new ImageSnapshotConfigurator(new ImageSnapshotThresholdsActivityLabelBounds(), 'bpmn-rendering-ignore-options'); |
| 164 | + |
| 165 | + it(`${bpmnDiagramName}`, async () => { |
| 166 | + await pageTester.gotoPageAndLoadBpmnDiagram(bpmnDiagramName, { |
| 167 | + rendererIgnoreBpmnActivityLabelBounds: ignoreBpmnActivityLabelBounds, |
| 168 | + }); |
| 169 | + |
| 170 | + const image = await page.screenshot({ fullPage: true }); |
| 171 | + const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreBpmnActivityLabelBounds)); |
| 172 | + expect(image).toMatchImageSnapshot(config); |
| 173 | + }); |
| 174 | + }); |
| 175 | + }); |
| 176 | + |
| 177 | + describe('Ignore label styles', () => { |
| 178 | + const bpmnDiagramName = 'labels.with.font.styles'; |
| 179 | + |
| 180 | + describe.each([false, true])('ignoreBpmnLabelStyles: %s', (ignoreBpmnLabelStyles: boolean) => { |
| 181 | + const imageSnapshotConfigurator = new ImageSnapshotConfigurator(new ImageSnapshotThresholdsLabelStyles(), 'bpmn-rendering-ignore-options'); |
| 182 | + |
| 183 | + it(`${bpmnDiagramName}`, async () => { |
| 184 | + await pageTester.gotoPageAndLoadBpmnDiagram(bpmnDiagramName, { |
| 185 | + rendererIgnoreBpmnLabelStyles: ignoreBpmnLabelStyles, |
| 186 | + }); |
| 187 | + |
| 188 | + const image = await page.screenshot({ fullPage: true }); |
| 189 | + const config = imageSnapshotConfigurator.getConfig(getConfigName(bpmnDiagramName, ignoreBpmnLabelStyles)); |
| 190 | + expect(image).toMatchImageSnapshot(config); |
| 191 | + }); |
| 192 | + }); |
| 193 | + }); |
| 194 | +}); |
0 commit comments