Skip to content

Commit

Permalink
Merge pull request #135 from layer5labs/fix-crash
Browse files Browse the repository at this point in the history
fix crash on removing undefined elements
  • Loading branch information
aabidsofi19 authored Dec 15, 2024
2 parents 8981064 + 5c29d67 commit e4c3ba2
Showing 1 changed file with 55 additions and 43 deletions.
98 changes: 55 additions & 43 deletions cypress-action/cypress/e2e/e2e/loadDesign.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,85 @@

import { TIME, canvasContainer } from "../../support/constants";
import {
beforeEachCallbackForCustomUrl,
doSnapshotSetup,
waitFor,
beforeEachCallbackForCustomUrl,
doSnapshotSetup,
waitFor,
} from "../../support/helpers";

const InfraShot = (theme) => {
return describe(`Infra Shot Automated Runner ${theme} Mode`, () => {
beforeEach(() =>
beforeEachCallbackForCustomUrl(
`/extension/meshmap?mode=design&design=${getDesignId()}`,
theme
)
);
return describe(`Infra Shot Automated Runner ${theme} Mode`, () => {
beforeEach(() =>
beforeEachCallbackForCustomUrl(
`/extension/meshmap?mode=design&design=${getDesignId()}`,
theme,
),
);

it(`take light mode infra shot`, () => {
const designId = getDesignId();
waitForDesignRender();
cy.window().then((window) => {
cy.wait(TIME.MEDIUM);
captureSnapshot({
window,
designId: designId,
theme,
});
});
it(`take light mode infra shot`, () => {
const designId = getDesignId();
waitForDesignRender();
cy.window().then((window) => {
cy.wait(TIME.MEDIUM);
captureSnapshot({
window,
designId: designId,
theme,
});
});
});
});
};

const getDesignId = () => {
return Cypress.env("applicationId").replace(/['"]+/g, "");
return Cypress.env("applicationId").replace(/['"]+/g, "");
};

const waitForDesignRender = () => {
waitFor(canvasContainer.query, { timeout: 60_000 });
cy.wait(TIME.X4LARGE);
waitFor(canvasContainer.query, { timeout: 60_000 });
cy.wait(TIME.X4LARGE);
};

const snapshotPath = (designId, theme) => {
return `snapshot-${theme}`;
return `snapshot-${theme}`;
};

const captureSnapshot = ({ window, designId, theme }) => {
console.log("Taking snapshot", designId, theme);
removeWidgets();
cy.window().then((win) => {
const cytoscape = win.cyto;
cytoscape.fit();
cytoscape.center();
})
const path = snapshotPath(designId, theme);
cy.wait(2000)

cy.get(canvasContainer.query, { timeout: 10 * 1000 }).should("exist").screenshot(path, {
scale: true,
console.log("Taking snapshot", designId, theme);
removeWidgets();
cy.window().then((win) => {
const cytoscape = win.cyto;
cytoscape.fit();
cytoscape.center();
});
const path = snapshotPath(designId, theme);
cy.wait(2000);

cy.get(canvasContainer.query, { timeout: 10 * 1000 })
.should("exist")
.screenshot(path, {
scale: true,
});
console.log(`Snapshot taken at ${path}`);
console.log(`Snapshot taken at ${path}`);
};

const removeWidgets = () => {
const ids = ["action-toolbar", "kanvas-bottom-dock", "design-drawer", "visualiser-drawer", "left-navigation-bar", "top-navigation-bar"];
const ids = [
"action-toolbar",
"kanvas-bottom-dock",
"design-drawer",
"left-navigation-bar",
"top-navigation-bar",
];

ids.forEach((className) => {
cy.get(`#${className}`).invoke('remove');
});
ids.forEach((className) => {
try {
cy.get(`#${className}`).invoke("remove");
} catch (error) {
console.log(`Error removing ${className}`);
}
});
};

["light", "dark"].forEach((theme) => {
InfraShot(theme);
InfraShot(theme);
});

0 comments on commit e4c3ba2

Please sign in to comment.