regions.cy.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import { Labels, LabelStudio, Sidebar, VideoView } from "@humansignal/frontend-test/helpers/LSF/index";
  2. import { simpleVideoConfig, simpleVideoData, simpleVideoResult } from "../../data/video_segmentation/regions";
  3. import { TWO_FRAMES_TIMEOUT } from "../utils/constants";
  4. // This test suite has exhibited flakiness in CI environments, so we are using retries
  5. // while we work on improving CI stability for visual comparisons.
  6. const suiteConfig = {
  7. retries: {
  8. runMode: 3, // Retry 3 times in CI (headless mode)
  9. openMode: 0, // No retries in local development (interactive mode)
  10. },
  11. };
  12. describe("Video segmentation", suiteConfig, () => {
  13. it("Should be able to draw a simple rectangle", () => {
  14. LabelStudio.params().config(simpleVideoConfig).data(simpleVideoData).withResult([]).init();
  15. LabelStudio.waitForObjectsReady();
  16. Sidebar.hasNoRegions();
  17. Labels.select("Label 1");
  18. VideoView.drawRectRelative(0.2, 0.2, 0.6, 0.6);
  19. Sidebar.hasRegions(1);
  20. });
  21. it("Should have changes in canvas", () => {
  22. LabelStudio.params().config(simpleVideoConfig).data(simpleVideoData).withResult([]).init();
  23. LabelStudio.waitForObjectsReady();
  24. // Wait for video and regions to be fully loaded
  25. cy.wait(TWO_FRAMES_TIMEOUT);
  26. Sidebar.hasNoRegions();
  27. // Wait for video to be fully loaded and stable
  28. VideoView.captureCanvas("canvas");
  29. Labels.select("Label 2");
  30. VideoView.drawRectRelative(0.2, 0.2, 0.6, 0.6);
  31. // Ensure drawing operations are complete before comparison
  32. cy.wait(1000);
  33. Sidebar.hasRegions(1);
  34. VideoView.canvasShouldChange("canvas", 0);
  35. });
  36. it("Should be invisible out of the lifespan (rectangle)", () => {
  37. LabelStudio.params().config(simpleVideoConfig).data(simpleVideoData).withResult(simpleVideoResult).init();
  38. LabelStudio.waitForObjectsReady();
  39. // Wait for video and regions to be fully loaded
  40. VideoView.waitForRegionInKonvaByIndex(0);
  41. VideoView.waitForStableState();
  42. Sidebar.hasRegions(1);
  43. VideoView.captureCanvas("canvas");
  44. VideoView.clickAtFrame(4);
  45. VideoView.waitForFrame(4);
  46. VideoView.waitForRegionNotInKonvaByIndex(0);
  47. VideoView.waitForStableState();
  48. VideoView.canvasShouldChange("canvas", 0);
  49. });
  50. it("Should be invisible out of the lifespan (transformer)", () => {
  51. LabelStudio.params().config(simpleVideoConfig).data(simpleVideoData).withResult(simpleVideoResult).init();
  52. LabelStudio.waitForObjectsReady();
  53. // Wait for frame change to be fully processed
  54. VideoView.waitForRegionInKonvaByIndex(0);
  55. VideoView.waitForStableState();
  56. Sidebar.hasRegions(1);
  57. cy.log("Remember an empty canvas state");
  58. VideoView.clickAtFrame(4);
  59. VideoView.waitForFrame(4);
  60. VideoView.waitForRegionNotInKonvaByIndex(0);
  61. VideoView.waitForStableState();
  62. VideoView.captureCanvas("canvas");
  63. VideoView.clickAtFrame(3);
  64. VideoView.waitForRegionInKonvaByIndex(0);
  65. VideoView.waitForStableState();
  66. cy.log("Select region");
  67. VideoView.clickAtRelative(0.5, 0.5);
  68. Sidebar.hasSelectedRegions(1);
  69. VideoView.clickAtFrame(4);
  70. VideoView.waitForFrame(4); // Wait for frame 4
  71. Sidebar.hasSelectedRegions(1);
  72. cy.wait(1000);
  73. VideoView.canvasShouldNotChange("canvas", 0);
  74. });
  75. });