2019-09-18 18:25:06 +02:00
|
|
|
import { Base64 } from 'js-base64';
|
2019-09-11 18:53:05 +02:00
|
|
|
|
|
|
|
export const mermaidUrl = (graphStr, options, api) => {
|
|
|
|
const obj = {
|
|
|
|
code: graphStr,
|
2021-11-18 19:17:00 +01:00
|
|
|
mermaid: options,
|
2019-09-18 18:25:06 +02:00
|
|
|
};
|
|
|
|
const objStr = JSON.stringify(obj);
|
|
|
|
let url = 'http://localhost:9000/e2e.html?graph=' + Base64.encodeURI(objStr);
|
2019-09-11 18:53:05 +02:00
|
|
|
if (api) {
|
2019-09-18 18:25:06 +02:00
|
|
|
url = 'http://localhost:9000/xss.html?graph=' + graphStr;
|
2019-09-11 18:53:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.listUrl) {
|
2019-09-18 18:25:06 +02:00
|
|
|
cy.log(options.listId, ' ', url);
|
2019-09-11 18:53:05 +02:00
|
|
|
}
|
|
|
|
|
2019-09-18 18:25:06 +02:00
|
|
|
return url;
|
|
|
|
};
|
2019-09-11 18:53:05 +02:00
|
|
|
|
2022-04-14 19:19:18 -07:00
|
|
|
export const imgSnapshotTest = (graphStr, _options, api = false, validation) => {
|
2020-08-23 20:02:51 +02:00
|
|
|
cy.log(_options);
|
2020-08-16 21:49:36 +02:00
|
|
|
const options = 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 = '16px';
|
|
|
|
}
|
2022-07-20 14:39:01 +02:00
|
|
|
// const useAppli = Cypress.env('useAppli');
|
|
|
|
const useAppli = false;
|
2022-05-10 20:33:55 +02:00
|
|
|
const branch = Cypress.env('codeBranch');
|
|
|
|
cy.log('Hello ' + useAppli ? 'Appli' : 'image-snapshot');
|
|
|
|
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
|
|
|
|
|
|
|
if (useAppli) {
|
|
|
|
cy.eyesOpen({
|
|
|
|
appName: 'Mermaid-' + branch,
|
|
|
|
testName: name,
|
|
|
|
batchName: branch,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-09-18 18:25:06 +02:00
|
|
|
const url = mermaidUrl(graphStr, options, api);
|
2019-09-11 18:53:05 +02:00
|
|
|
|
|
|
|
cy.visit(url);
|
2022-04-14 19:19:18 -07:00
|
|
|
if (validation) cy.get('svg').should(validation);
|
2019-09-18 18:25:06 +02:00
|
|
|
cy.get('svg');
|
2022-03-31 18:06:04 +02:00
|
|
|
// Default name to test title
|
|
|
|
|
2022-05-10 20:33:55 +02:00
|
|
|
if (useAppli) {
|
|
|
|
cy.eyesCheckWindow('Click!');
|
|
|
|
cy.eyesClose();
|
|
|
|
} else {
|
|
|
|
cy.matchImageSnapshot(name);
|
|
|
|
}
|
2019-09-18 18:25:06 +02:00
|
|
|
};
|
2019-11-20 19:06:46 +01:00
|
|
|
|
2022-06-21 21:17:53 +02:00
|
|
|
export const urlSnapshotTest = (url, _options, api = false, validation) => {
|
|
|
|
cy.log(_options);
|
|
|
|
const options = 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 = '16px';
|
|
|
|
}
|
|
|
|
const useAppli = Cypress.env('useAppli');
|
|
|
|
const branch = Cypress.env('codeBranch');
|
|
|
|
cy.log('Hello ' + useAppli ? 'Appli' : 'image-snapshot');
|
|
|
|
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
|
|
|
|
|
|
|
if (useAppli) {
|
|
|
|
cy.eyesOpen({
|
|
|
|
appName: 'Mermaid-' + branch,
|
|
|
|
testName: name,
|
|
|
|
batchName: branch,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.visit(url);
|
|
|
|
if (validation) cy.get('svg').should(validation);
|
|
|
|
cy.get('body');
|
|
|
|
// Default name to test title
|
|
|
|
|
|
|
|
if (useAppli) {
|
|
|
|
cy.eyesCheckWindow('Click!');
|
|
|
|
cy.eyesClose();
|
|
|
|
} else {
|
|
|
|
cy.matchImageSnapshot(name);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-11-20 19:06:46 +01:00
|
|
|
export const renderGraph = (graphStr, options, api) => {
|
|
|
|
const url = mermaidUrl(graphStr, options, api);
|
|
|
|
|
|
|
|
cy.visit(url);
|
|
|
|
};
|