1
1
const utf8ToB64 = ( str ) => {
2
- return window . btoa ( unescape ( encodeURIComponent ( str ) ) ) ;
2
+ return btoa ( unescape ( encodeURIComponent ( str ) ) ) ;
3
3
} ;
4
4
5
- const batchId = 'mermaid-batch' + new Date ( ) . getTime ( ) ;
5
+ const batchId = 'mermaid-batch' + Date . now ( ) ;
6
6
7
7
export const mermaidUrl = ( graphStr , options , api ) => {
8
8
const obj = {
9
9
code : graphStr ,
10
10
mermaid : options ,
11
11
} ;
12
12
const objStr = JSON . stringify ( obj ) ;
13
- let url = 'http://localhost:9000/e2e.html?graph=' + utf8ToB64 ( objStr ) ;
14
- if ( api ) {
15
- url = 'http://localhost:9000/xss.html?graph=' + graphStr ;
16
- }
13
+ let url = `http://localhost:9000/${ api ? 'xss.html' : 'e2e.html' } ?graph=${ utf8ToB64 ( objStr ) } ` ;
17
14
18
15
if ( options . listUrl ) {
19
16
cy . log ( options . listId , ' ' , url ) ;
@@ -22,36 +19,24 @@ export const mermaidUrl = (graphStr, options, api) => {
22
19
return url ;
23
20
} ;
24
21
25
- export const imgSnapshotTest = ( graphStr , _options = { } , api = false , validation = undefined ) => {
26
- cy . log ( _options ) ;
27
- const options = Object . assign ( _options ) ;
28
- if ( ! options . fontFamily ) {
29
- options . fontFamily = 'courier' ;
30
- }
31
- if ( ! options . sequence ) {
32
- options . sequence = { } ;
33
- }
34
- if ( ! options . sequence || ( options . sequence && ! options . sequence . actorFontFamily ) ) {
35
- options . sequence . actorFontFamily = 'courier' ;
36
- }
37
- if ( options . sequence && ! options . sequence . noteFontFamily ) {
38
- options . sequence . noteFontFamily = 'courier' ;
39
- }
40
- options . sequence . actorFontFamily = 'courier' ;
41
- options . sequence . noteFontFamily = 'courier' ;
42
- options . sequence . messageFontFamily = 'courier' ;
43
- if ( options . sequence && ! options . sequence . actorFontFamily ) {
44
- options . sequence . actorFontFamily = 'courier' ;
45
- }
46
- if ( ! options . fontSize ) {
47
- options . fontSize = '16px' ;
48
- }
22
+ export const imgSnapshotTest = ( graphStr , _options = { } , api = false , validation ) => {
23
+ const options = {
24
+ ..._options ,
25
+ fontFamily : _options . fontFamily || 'courier' ,
26
+ fontSize : _options . fontSize || '16px' ,
27
+ sequence : {
28
+ ...( options . sequence || { } ) ,
29
+ actorFontFamily : 'courier' ,
30
+ noteFontFamily : _options . sequence ?. noteFontFamily || 'courier' ,
31
+ messageFontFamily : 'courier' ,
32
+ } ,
33
+ } ;
34
+
49
35
const url = mermaidUrl ( graphStr , options , api ) ;
50
36
openURLAndVerifyRendering ( url , options , validation ) ;
51
37
} ;
52
38
53
- export const urlSnapshotTest = ( url , _options , api = false , validation ) => {
54
- const options = Object . assign ( _options ) ;
39
+ export const urlSnapshotTest = ( url , options = { } , api = false , validation ) => {
55
40
openURLAndVerifyRendering ( url , options , validation ) ;
56
41
} ;
57
42
@@ -60,12 +45,12 @@ export const renderGraph = (graphStr, options, api) => {
60
45
openURLAndVerifyRendering ( url , options ) ;
61
46
} ;
62
47
63
- const openURLAndVerifyRendering = ( url , options , validation = undefined ) => {
48
+ const openURLAndVerifyRendering = ( url , options , validation ) => {
64
49
const useAppli = Cypress . env ( 'useAppli' ) ;
65
50
const name = ( options . name || cy . state ( 'runnable' ) . fullTitle ( ) ) . replace ( / \s + / g, '-' ) ;
66
51
67
52
if ( useAppli ) {
68
- cy . log ( ' Opening eyes ' + Cypress . spec . name + ' --- ' + name ) ;
53
+ cy . log ( ` Opening eyes ${ Cypress . spec . name } --- ${ name } ` ) ;
69
54
cy . eyesOpen ( {
70
55
appName : 'Mermaid' ,
71
56
testName : name ,
@@ -83,9 +68,9 @@ const openURLAndVerifyRendering = (url, options, validation = undefined) => {
83
68
}
84
69
85
70
if ( useAppli ) {
86
- cy . log ( ' Check eyes' + Cypress . spec . name ) ;
71
+ cy . log ( ` Check eyes ${ Cypress . spec . name } ` ) ;
87
72
cy . eyesCheckWindow ( 'Click!' ) ;
88
- cy . log ( ' Closing eyes' + Cypress . spec . name ) ;
73
+ cy . log ( ` Closing eyes ${ Cypress . spec . name } ` ) ;
89
74
cy . eyesClose ( ) ;
90
75
} else {
91
76
cy . matchImageSnapshot ( name ) ;
0 commit comments