2022-09-23 15:42:41 +05:30
|
|
|
const utf8ToB64 = (str) => {
|
2023-04-24 12:14:40 +05:30
|
|
|
return btoa(unescape(encodeURIComponent(str)));
|
2022-09-23 15:42:41 +05:30
|
|
|
};
|
2019-09-11 18:53:05 +02:00
|
|
|
|
2023-04-24 12:14:40 +05:30
|
|
|
const batchId = 'mermaid-batch' + Date.now();
|
2022-11-04 13:05:46 +01:00
|
|
|
|
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);
|
2023-04-24 12:14:40 +05:30
|
|
|
let url = `http://localhost:9000/${api ? 'xss.html' : 'e2e.html'}?graph=${utf8ToB64(objStr)}`;
|
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
|
|
|
|
2023-04-24 12:14:40 +05:30
|
|
|
export const imgSnapshotTest = (graphStr, _options = {}, api = false, validation) => {
|
|
|
|
const options = {
|
|
|
|
..._options,
|
|
|
|
fontFamily: _options.fontFamily || 'courier',
|
|
|
|
fontSize: _options.fontSize || '16px',
|
|
|
|
sequence: {
|
|
|
|
...(options.sequence || {}),
|
|
|
|
actorFontFamily: 'courier',
|
|
|
|
noteFontFamily: _options.sequence?.noteFontFamily || 'courier',
|
|
|
|
messageFontFamily: 'courier',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2019-09-18 18:25:06 +02:00
|
|
|
const url = mermaidUrl(graphStr, options, api);
|
2023-01-16 02:07:37 +05:30
|
|
|
openURLAndVerifyRendering(url, options, validation);
|
2019-09-18 18:25:06 +02:00
|
|
|
};
|
2019-11-20 19:06:46 +01:00
|
|
|
|
2023-04-24 12:14:40 +05:30
|
|
|
export const urlSnapshotTest = (url, options = {}, api = false, validation) => {
|
2023-01-16 02:07:37 +05:30
|
|
|
openURLAndVerifyRendering(url, options, validation);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const renderGraph = (graphStr, options, api) => {
|
|
|
|
const url = mermaidUrl(graphStr, options, api);
|
|
|
|
openURLAndVerifyRendering(url, options);
|
|
|
|
};
|
|
|
|
|
2023-04-24 12:14:40 +05:30
|
|
|
const openURLAndVerifyRendering = (url, options, validation) => {
|
2022-06-21 21:17:53 +02:00
|
|
|
const useAppli = Cypress.env('useAppli');
|
|
|
|
const name = (options.name || cy.state('runnable').fullTitle()).replace(/\s+/g, '-');
|
|
|
|
|
|
|
|
if (useAppli) {
|
2023-04-24 12:14:40 +05:30
|
|
|
cy.log(`Opening eyes ${Cypress.spec.name} --- ${name}`);
|
2022-06-21 21:17:53 +02:00
|
|
|
cy.eyesOpen({
|
2022-09-14 01:43:07 +01:00
|
|
|
appName: 'Mermaid',
|
2022-06-21 21:17:53 +02:00
|
|
|
testName: name,
|
2022-11-04 13:05:46 +01:00
|
|
|
batchName: Cypress.spec.name,
|
|
|
|
batchId: batchId + Cypress.spec.name,
|
2022-06-21 21:17:53 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cy.visit(url);
|
2023-01-16 02:07:37 +05:30
|
|
|
cy.window().should('have.property', 'rendered', true);
|
|
|
|
cy.get('svg').should('be.visible');
|
|
|
|
|
2022-10-19 20:06:54 +02:00
|
|
|
if (validation) {
|
|
|
|
cy.get('svg').should(validation);
|
|
|
|
}
|
2022-06-21 21:17:53 +02:00
|
|
|
|
|
|
|
if (useAppli) {
|
2023-04-24 12:14:40 +05:30
|
|
|
cy.log(`Check eyes ${Cypress.spec.name}`);
|
2022-06-21 21:17:53 +02:00
|
|
|
cy.eyesCheckWindow('Click!');
|
2023-04-24 12:14:40 +05:30
|
|
|
cy.log(`Closing eyes ${Cypress.spec.name}`);
|
2022-06-21 21:17:53 +02:00
|
|
|
cy.eyesClose();
|
|
|
|
} else {
|
|
|
|
cy.matchImageSnapshot(name);
|
|
|
|
}
|
|
|
|
};
|