mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-25 11:51:07 +00:00
* Upgrade typescript to 4.9.5 * Fix compile issue and put back files in tsconfig.strict.json * Update test snapshots * Fix jest tests by upgrading jest and other related packages. * Attempt to fix playwright test * Revert "Attempt to fix playwright test" This reverts commit8293f34c9c. * 2nd attempt to fix example test * fix waitFor in playwright * Remove unused describe section * Attempt to fix e2e test * Revert "Attempt to fix e2e test" This reverts commit9745bcd2ef. * Upgrade playwright to latest * Revert "Upgrade playwright to latest" This reverts commite2ea1d0189. * Error test on e2e * Revert "Error test on e2e" This reverts commit124e3764f7. * Try to select dropdown item by xpath selector * Revert "Try to select dropdown item by xpath selector" This reverts commit8eb42a64e2. * Attempt to wait until page is fully loaded * Revert "Attempt to wait until page is fully loaded" This reverts commitbb43fcea6e. * Use playwright selectOption to select dropdown option * Revert "Use playwright selectOption to select dropdown option" This reverts commitdaa8cd0930. * Select dropdown option with playwright api instead of manual click * c7ab4c7ecf7b05f32a85568bce1a667ad8c62703Revert "Select dropdown option with playwright api instead of manual click" This reverts commitc7ab4c7ecf. * Wait for 5s after dropdown click * Revert "Wait for 5s after dropdown click" This reverts commit847e9ad33f. * Try forcing click * Revert "Try forcing click" This reverts commit29b9fa1bda. * Force click on the dropdown and set viewport size bigger. * Force click on the dropdown and set viewport size bigger. * try force clicking option * Skip container test on webkit * Add branded browsers to e2e tests --------- Co-authored-by: Ashley Stanton-Nurse <ashleyst@microsoft.com>
144 lines
4.4 KiB
TypeScript
144 lines
4.4 KiB
TypeScript
import dayjs from "dayjs";
|
|
import { handleMessage, Heatmap, isDarkTheme } from "./Heatmap";
|
|
import { PortalTheme } from "./HeatmapDatatypes";
|
|
|
|
describe("The Heatmap Control", () => {
|
|
const dataPoints = {
|
|
"1": {
|
|
"2019-06-19T00:59:10Z": {
|
|
"Normalized Throughput": 0.35,
|
|
},
|
|
"2019-06-19T00:48:10Z": {
|
|
"Normalized Throughput": 0.25,
|
|
},
|
|
},
|
|
};
|
|
|
|
const chartCaptions = {
|
|
chartTitle: "chart title",
|
|
yAxisTitle: "YAxisTitle",
|
|
tooltipText: "Tooltip text",
|
|
timeWindow: 123456789,
|
|
};
|
|
|
|
let heatmap: Heatmap;
|
|
const theme: PortalTheme = 1;
|
|
const divElement = `<div id="${Heatmap.elementId}"></div>`;
|
|
|
|
describe("drawHeatmap rendering", () => {
|
|
beforeEach(() => {
|
|
heatmap = new Heatmap(dataPoints, chartCaptions, theme);
|
|
document.body.innerHTML = divElement;
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.body.innerHTML = ``;
|
|
});
|
|
|
|
it("should call _getChartSettings when drawHeatmap is invoked", () => {
|
|
const _getChartSettings = jest.spyOn(heatmap, "_getChartSettings");
|
|
heatmap.drawHeatmap();
|
|
expect(_getChartSettings).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should call _getLayoutSettings when drawHeatmap is invoked", () => {
|
|
const _getLayoutSettings = jest.spyOn(heatmap, "_getLayoutSettings");
|
|
heatmap.drawHeatmap();
|
|
expect(_getLayoutSettings).toHaveBeenCalled();
|
|
});
|
|
|
|
it("should call _getChartDisplaySettings when drawHeatmap is invoked", () => {
|
|
const _getChartDisplaySettings = jest.spyOn(heatmap, "_getChartDisplaySettings");
|
|
heatmap.drawHeatmap();
|
|
expect(_getChartDisplaySettings).toHaveBeenCalled();
|
|
});
|
|
|
|
it("drawHeatmap should render a Heatmap inside the div element", () => {
|
|
heatmap.drawHeatmap();
|
|
expect(document.body.innerHTML).not.toEqual(divElement);
|
|
});
|
|
});
|
|
|
|
describe("generateMatrixFromMap", () => {
|
|
it("should massage input data to match output expected", () => {
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).yAxisPoints).toEqual(["1"]);
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).dataPoints).toEqual([[0.25, 0.35]]);
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).xAxisPoints.length).toEqual(2);
|
|
});
|
|
|
|
it("should output the date format to ISO8601 string format", () => {
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).xAxisPoints[0].slice(10, 11)).toEqual("T");
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).xAxisPoints[0].slice(-1)).toEqual("Z");
|
|
});
|
|
|
|
it("should convert the time to the user's local time", () => {
|
|
if (dayjs().utcOffset()) {
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).xAxisPoints).not.toEqual([
|
|
"2019-06-19T00:48:10Z",
|
|
"2019-06-19T00:59:10Z",
|
|
]);
|
|
} else {
|
|
expect(heatmap.generateMatrixFromMap(dataPoints).xAxisPoints).toEqual([
|
|
"2019-06-19T00:48:10Z",
|
|
"2019-06-19T00:59:10Z",
|
|
]);
|
|
}
|
|
});
|
|
});
|
|
|
|
describe("isDarkTheme", () => {
|
|
it("isDarkTheme should return the correct result", () => {
|
|
expect(isDarkTheme(PortalTheme.dark)).toEqual(true);
|
|
expect(isDarkTheme(PortalTheme.azure)).not.toEqual(true);
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("iframe rendering when there is no data", () => {
|
|
afterEach(() => {
|
|
document.body.innerHTML = ``;
|
|
});
|
|
|
|
it("should show a no data message with a dark theme", () => {
|
|
const data = {
|
|
data: {
|
|
signature: "pcIframe",
|
|
data: {
|
|
chartData: {},
|
|
chartSettings: {},
|
|
theme: 4,
|
|
},
|
|
},
|
|
origin: "http://localhost",
|
|
};
|
|
|
|
const divElement = `<div id="${Heatmap.elementId}"></div>`;
|
|
document.body.innerHTML = divElement;
|
|
|
|
handleMessage(data as MessageEvent);
|
|
expect(document.body.innerHTML).toContain("dark-theme");
|
|
expect(document.body.innerHTML).toContain("noDataMessage");
|
|
});
|
|
|
|
it("should show a no data message with a white theme", () => {
|
|
const data = {
|
|
data: {
|
|
signature: "pcIframe",
|
|
data: {
|
|
chartData: {},
|
|
chartSettings: {},
|
|
theme: 2,
|
|
},
|
|
},
|
|
origin: "http://localhost",
|
|
};
|
|
|
|
const divElement = `<div id="${Heatmap.elementId}"></div>`;
|
|
document.body.innerHTML = divElement;
|
|
|
|
handleMessage(data as MessageEvent);
|
|
expect(document.body.innerHTML).not.toContain("dark-theme");
|
|
expect(document.body.innerHTML).toContain("noDataMessage");
|
|
});
|
|
});
|