multichannel.cy.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { LabelStudio, TimeSeries } from "@humansignal/frontend-test/helpers/LSF";
  2. import { multiChannelSampleData, multiChannwlCnfig } from "../../data/timeseries/multichannel";
  3. import { TWO_FRAMES_TIMEOUT } from "../utils/constants";
  4. describe("MultiChannel", () => {
  5. it("should render correctly", () => {
  6. cy.log("Initialize MultiChannel TimeSeries");
  7. LabelStudio.params().config(multiChannwlCnfig).data(multiChannelSampleData).withResult([]).init();
  8. LabelStudio.waitForObjectsReady();
  9. TimeSeries.waitForReady();
  10. cy.log("Verify MultiChannel TimeSeries rendered correctly");
  11. // Verify that there are some paths rendered
  12. TimeSeries.paths.should("have.length.greaterThan", 0);
  13. // Verify no positioning errors (NaN/Infinity) in SVG elements
  14. TimeSeries.verifyNoPositioningErrors();
  15. // Verify chart data is visible in viewport
  16. TimeSeries.verifyDataVisibleInViewport();
  17. // Verify that we have multiple channels rendered
  18. TimeSeries.multiChannelContainer.should("be.visible");
  19. // Verify legend is rendered for multiple channels
  20. TimeSeries.legend.should("be.visible");
  21. TimeSeries.legendItems.should("have.length.greaterThan", 1);
  22. // Verify overview is rendered and functional
  23. TimeSeries.overview.should("be.visible");
  24. TimeSeries.overviewSvg.should("be.visible");
  25. cy.log("MultiChannel TimeSeries rendered successfully with valid data");
  26. });
  27. it("should support legend hover interactions", () => {
  28. cy.log("Initialize MultiChannel TimeSeries");
  29. LabelStudio.params().config(multiChannwlCnfig).data(multiChannelSampleData).withResult([]).init();
  30. LabelStudio.waitForObjectsReady();
  31. TimeSeries.waitForReady();
  32. cy.log("Verify legend hover functionality works without errors");
  33. // Test hovering over legend items doesn't cause errors
  34. TimeSeries.hoverLegendItem(0);
  35. cy.wait(TWO_FRAMES_TIMEOUT); // Allow any transitions to complete
  36. // Verify paths are still visible
  37. TimeSeries.paths.should("be.visible");
  38. // Test hovering over different legend item
  39. TimeSeries.hoverLegendItem(1);
  40. cy.wait(TWO_FRAMES_TIMEOUT); // Allow any transitions to complete
  41. // Verify paths are still visible
  42. TimeSeries.paths.should("be.visible");
  43. // Test removing hover
  44. TimeSeries.unhoverLegend();
  45. cy.wait(TWO_FRAMES_TIMEOUT); // Allow any transitions to complete
  46. // Verify paths are still visible
  47. TimeSeries.paths.should("be.visible");
  48. cy.log("Legend hover functionality working correctly without errors");
  49. });
  50. it("should support channel visibility toggling via legend clicks", () => {
  51. cy.log("Initialize MultiChannel TimeSeries");
  52. LabelStudio.params().config(multiChannwlCnfig).data(multiChannelSampleData).withResult([]).init();
  53. LabelStudio.waitForObjectsReady();
  54. TimeSeries.waitForReady();
  55. cy.log("Test channel visibility toggling by clicking legend items");
  56. // Get initial state - count visible paths and legend items
  57. TimeSeries.paths.should("have.length.greaterThan", 0);
  58. TimeSeries.legendItems.should("have.length.greaterThan", 1);
  59. TimeSeries.paths.then(($initialPaths) => {
  60. const initialVisibleCount = $initialPaths.filter(":visible").length;
  61. cy.log(`Initial visible paths: ${initialVisibleCount}`);
  62. // Click first legend item to hide channel
  63. cy.log("Clicking first legend item to hide channel");
  64. TimeSeries.clickLegendItem(0);
  65. // Verify that some paths are now hidden (each channel can have 1-2 paths)
  66. TimeSeries.paths.then(($pathsAfterHide) => {
  67. const visibleAfterHide = $pathsAfterHide.filter(":visible").length;
  68. cy.log(`Visible paths after hiding: ${visibleAfterHide}`);
  69. // Should have fewer visible paths (1-2 paths hidden per channel)
  70. expect(visibleAfterHide).to.be.lessThan(initialVisibleCount);
  71. expect(visibleAfterHide).to.be.at.least(0);
  72. });
  73. // Click the same legend item again to show channel back
  74. cy.log("Clicking same legend item to show channel back");
  75. TimeSeries.clickLegendItem(0);
  76. // Verify paths are restored
  77. TimeSeries.paths.filter(":visible").should("have.length", initialVisibleCount);
  78. // Test hiding different channel
  79. cy.log("Testing hiding second channel");
  80. TimeSeries.clickLegendItem(1);
  81. TimeSeries.paths.then(($pathsAfterHide2) => {
  82. const visibleAfterHide2 = $pathsAfterHide2.filter(":visible").length;
  83. cy.log(`Visible paths after hiding second channel: ${visibleAfterHide2}`);
  84. // Should have fewer visible paths
  85. expect(visibleAfterHide2).to.be.lessThan(initialVisibleCount);
  86. expect(visibleAfterHide2).to.be.at.least(0);
  87. });
  88. // Restore second channel
  89. cy.log("Restoring second channel");
  90. TimeSeries.clickLegendItem(1);
  91. // Verify all paths are restored
  92. TimeSeries.paths.filter(":visible").should("have.length", initialVisibleCount);
  93. cy.log("Channel visibility toggling works correctly");
  94. });
  95. });
  96. });