Skip to content

Commit 781857b

Browse files
committed
update util.ts
1 parent b446ab3 commit 781857b

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

cypress/helpers/util.ts

+18-16
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ const convertUtf8ToBase64 = (str: string): string => {
3939
*/
4040
export const createMermaidUrl = (
4141
diagramStr: string,
42-
options?: CypressMermaidConfig,
43-
api?: boolean
42+
options: CypressMermaidConfig = {},
43+
api: boolean = false
4444
): string => {
4545
const codeObject: CodeObject = {
4646
code: diagramStr,
47-
mermaid: options || {},
47+
mermaid: options,
4848
};
4949
const objStr: string = JSON.stringify(codeObject);
5050
const url = `http://localhost:9000/${api ? 'xss' : 'e2e'}.html?graph=${convertUtf8ToBase64(
@@ -68,14 +68,13 @@ export const createMermaidUrl = (
6868
*/
6969
export const openUrlAndVerifyRendering = (
7070
url: string,
71-
options?: CypressMermaidConfig,
71+
options: CypressMermaidConfig = {},
7272
validation?: any
7373
): void => {
7474
const useAppli: boolean = Cypress.env('useAppli');
75-
const name: string = ((options && options.name) || cy.state('runnable').fullTitle()).replace(
76-
/\s+/g,
77-
'-'
78-
);
75+
const name: string = (
76+
options && options.name ? options.name : cy.state('runnable').fullTitle()
77+
).replace(/\s+/g, '-');
7978

8079
if (useAppli) {
8180
cy.log(`Opening eyes ${Cypress.spec.name} --- ${name}`);
@@ -114,18 +113,21 @@ export const openUrlAndVerifyRendering = (
114113
*/
115114
export const imgSnapshotTest = (
116115
diagramStr: string,
117-
_options?: CypressMermaidConfig,
118-
api?: boolean,
116+
_options: CypressMermaidConfig = {},
117+
api: boolean = false,
119118
validation?: any
120119
): void => {
121120
cy.log(JSON.stringify(_options));
122121
const options: CypressMermaidConfig = {
123-
...(_options || {}),
124-
fontFamily: _options?.fontFamily || 'courier',
125-
fontSize: _options?.fontSize || 16,
122+
..._options,
123+
fontFamily: _options && _options.fontFamily ? _options.fontFamily : 'courier',
124+
fontSize: _options && _options.fontSize ? _options.fontSize : 16,
126125
sequence: {
127126
actorFontFamily: 'courier',
128-
noteFontFamily: _options?.sequence?.noteFontFamily || 'courier',
127+
noteFontFamily:
128+
_options && _options.sequence && _options.sequence.noteFontFamily
129+
? _options?.sequence?.noteFontFamily
130+
: 'courier',
129131
messageFontFamily: 'courier',
130132
},
131133
};
@@ -143,8 +145,8 @@ export const imgSnapshotTest = (
143145
*/
144146
export const urlSnapshotTest = (
145147
url: string,
146-
_options?: CypressMermaidConfig,
147-
_api?: boolean,
148+
_options: CypressMermaidConfig = {},
149+
_api: boolean = false,
148150
validation?: any
149151
): void => {
150152
const options: CypressMermaidConfig = Object.assign(_options);

cypress/integration/rendering/xyChart.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { imgSnapshotTest, renderGraph } from '../../helpers/util.ts';
1+
import { imgSnapshotTest } from '../../helpers/util.ts';
22

33
describe('XY Chart', () => {
44
it('should render the simplest possible chart', () => {

0 commit comments

Comments
 (0)