forked from mermaid-js/mermaid
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/4451-vertical-branches-in-gitgraph' of https://…
…github.com/mastersibin/mermaid into feature/4451-vertical-branches-in-gitgraph
- Loading branch information
Showing
37 changed files
with
259 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Buffer } from 'buffer'; | ||
import type { MermaidConfig } from '../../packages/mermaid/src/config.type.js'; | ||
|
||
interface CypressConfig { | ||
listUrl?: boolean; | ||
listId?: string; | ||
name?: string; | ||
} | ||
type CypressMermaidConfig = MermaidConfig & CypressConfig; | ||
|
||
interface CodeObject { | ||
code: string; | ||
mermaid: CypressMermaidConfig; | ||
} | ||
|
||
const utf8ToB64 = (str: string): string => { | ||
return Buffer.from(decodeURIComponent(encodeURIComponent(str))).toString('base64'); | ||
}; | ||
|
||
const batchId: string = 'mermaid-batch-' + Cypress.env('CYPRESS_COMMIT') || Date.now().toString(); | ||
|
||
export const mermaidUrl = ( | ||
graphStr: string, | ||
options: CypressMermaidConfig, | ||
api: boolean | ||
): string => { | ||
const codeObject: CodeObject = { | ||
code: graphStr, | ||
mermaid: options, | ||
}; | ||
const objStr: string = JSON.stringify(codeObject); | ||
let url = `http://localhost:9000/e2e.html?graph=${utf8ToB64(objStr)}`; | ||
if (api) { | ||
url = `http://localhost:9000/xss.html?graph=${graphStr}`; | ||
} | ||
|
||
if (options.listUrl) { | ||
cy.log(options.listId, ' ', url); | ||
} | ||
|
||
return url; | ||
}; | ||
|
||
export const imgSnapshotTest = ( | ||
graphStr: string, | ||
_options: CypressMermaidConfig = {}, | ||
api = false, | ||
validation?: any | ||
): void => { | ||
cy.log(JSON.stringify(_options)); | ||
const options: CypressMermaidConfig = Object.assign(_options); | ||
if (!options.fontFamily) { | ||
options.fontFamily = 'courier'; | ||
} | ||
if (!options.sequence) { | ||
options.sequence = {}; | ||
} | ||
if (!options.sequence || (options.sequence && !options.sequence.actorFontFamily)) { | ||
options.sequence.actorFontFamily = 'courier'; | ||
} | ||
if (options.sequence && !options.sequence.noteFontFamily) { | ||
options.sequence.noteFontFamily = 'courier'; | ||
} | ||
options.sequence.actorFontFamily = 'courier'; | ||
options.sequence.noteFontFamily = 'courier'; | ||
options.sequence.messageFontFamily = 'courier'; | ||
if (options.sequence && !options.sequence.actorFontFamily) { | ||
options.sequence.actorFontFamily = 'courier'; | ||
} | ||
if (!options.fontSize) { | ||
options.fontSize = 16; | ||
} | ||
|
||
const url: string = mermaidUrl(graphStr, options, api); | ||
openURLAndVerifyRendering(url, options, validation); | ||
}; | ||
|
||
export const urlSnapshotTest = ( | ||
url: string, | ||
_options: CypressMermaidConfig, | ||
_api = false, | ||
validation?: any | ||
): void => { | ||
const options: CypressMermaidConfig = Object.assign(_options); | ||
openURLAndVerifyRendering(url, options, validation); | ||
}; | ||
|
||
export const renderGraph = ( | ||
graphStr: string, | ||
options: CypressMermaidConfig = {}, | ||
api = false | ||
): void => { | ||
const url: string = mermaidUrl(graphStr, options, api); | ||
openURLAndVerifyRendering(url, options); | ||
}; | ||
|
||
export const openURLAndVerifyRendering = ( | ||
url: string, | ||
options: CypressMermaidConfig, | ||
validation?: any | ||
): void => { | ||
const useAppli: boolean = Cypress.env('useAppli'); | ||
const name: string = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-'); | ||
|
||
if (useAppli) { | ||
cy.log(`Opening eyes ${Cypress.spec.name} --- ${name}`); | ||
cy.eyesOpen({ | ||
appName: 'Mermaid', | ||
testName: name, | ||
batchName: Cypress.spec.name, | ||
batchId: batchId + Cypress.spec.name, | ||
}); | ||
} | ||
|
||
cy.visit(url); | ||
cy.window().should('have.property', 'rendered', true); | ||
cy.get('svg').should('be.visible'); | ||
|
||
if (validation) { | ||
cy.get('svg').should(validation); | ||
} | ||
|
||
if (useAppli) { | ||
cy.log(`Check eyes ${Cypress.spec.name}`); | ||
cy.eyesCheckWindow('Click!'); | ||
cy.log(`Closing eyes ${Cypress.spec.name}`); | ||
cy.eyesClose(); | ||
} else { | ||
cy.matchImageSnapshot(name); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.