hide-all.cy.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { LabelStudio, Sidebar, Tooltip } from "@humansignal/frontend-test/helpers/LSF/index";
  2. import { simpleRegionsConfig, simpleRegionsData, simpleRegionsResult } from "../../data/outliner/hide-all";
  3. describe("Outliner - Hide all regions", () => {
  4. it("should exist", () => {
  5. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  6. Sidebar.hasRegions(3);
  7. Sidebar.hideAllRegionsButton.should("be.visible").should("be.enabled");
  8. });
  9. it("should be disabled without existed regions", () => {
  10. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult([]).init();
  11. Sidebar.hasRegions(0);
  12. Sidebar.hideAllRegionsButton.should("be.visible").should("be.disabled");
  13. });
  14. it("should hide all regions", () => {
  15. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  16. Sidebar.hasRegions(3);
  17. Sidebar.hasHiddenRegion(0);
  18. Sidebar.hideAllRegionsButton.click();
  19. Sidebar.hasHiddenRegion(3);
  20. });
  21. it("should show all regions", () => {
  22. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  23. Sidebar.hasRegions(3);
  24. Sidebar.hideAllRegionsButton.click();
  25. Sidebar.hasHiddenRegion(3);
  26. Sidebar.showAllRegionsButton.click();
  27. Sidebar.hasHiddenRegion(0);
  28. });
  29. it("should hide rest regions", () => {
  30. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  31. Sidebar.hasRegions(3);
  32. Sidebar.toggleRegionVisibility(1);
  33. Sidebar.hasHiddenRegion(1);
  34. Sidebar.hideAllRegionsButton.click();
  35. Sidebar.hasHiddenRegion(3);
  36. });
  37. it("should hide all regions except the target region by ID from param", () => {
  38. LabelStudio.params()
  39. .config(simpleRegionsConfig)
  40. .data(simpleRegionsData)
  41. .withResult(simpleRegionsResult)
  42. .withParam("region", "label_2")
  43. .init();
  44. cy.window().then((window: any | unknown) => {
  45. window.Htx.annotationStore.annotations[0].regionStore.setRegionVisible(window.LSF_CONFIG.region);
  46. });
  47. Sidebar.hasRegions(3);
  48. Sidebar.hasHiddenRegion(2);
  49. Sidebar.assertRegionHidden(0, "Label 1", true);
  50. Sidebar.assertRegionHidden(1, "Label 2", false);
  51. Sidebar.assertRegionHidden(2, "Label 3", true);
  52. });
  53. it("should hide all regions except the target region by ID within the targeted annotation tab specified by param", () => {
  54. LabelStudio.params()
  55. .config(simpleRegionsConfig)
  56. .data(simpleRegionsData)
  57. .withAnnotation({ id: "10", result: simpleRegionsResult })
  58. .withAnnotation({ id: "20", result: simpleRegionsResult })
  59. .withParam("annotation", "10")
  60. .withParam("region", "label_2")
  61. .init();
  62. cy.window().then((window: any | unknown) => {
  63. const annIdFromParam = window.LSF_CONFIG.annotation;
  64. const annotations = window.Htx.annotationStore.annotations;
  65. const lsfAnnotation = annotations.find((ann: any) => ann.pk === annIdFromParam || ann.id === annIdFromParam);
  66. const annID = lsfAnnotation.pk ?? lsfAnnotation.id;
  67. expect(annID).to.equal("10");
  68. // Move to the annotation tab specified by param
  69. cy.get('[class="lsf-annotations-list__toggle"]').click();
  70. cy.get('[class="lsf-annotations-list__entity-id"]').contains("10").click();
  71. annotations[1].regionStore.setRegionVisible(window.LSF_CONFIG.region);
  72. });
  73. Sidebar.hasRegions(3);
  74. Sidebar.hasHiddenRegion(2);
  75. Sidebar.assertRegionHidden(0, "Label 1", true);
  76. Sidebar.assertRegionHidden(1, "Label 2", false);
  77. Sidebar.assertRegionHidden(2, "Label 3", true);
  78. });
  79. it("should not hide regions in the non-targeted annotaion tab", () => {
  80. LabelStudio.params()
  81. .config(simpleRegionsConfig)
  82. .data(simpleRegionsData)
  83. .withAnnotation({ id: "10", result: simpleRegionsResult })
  84. .withAnnotation({ id: "20", result: simpleRegionsResult })
  85. .withParam("annotation", "10")
  86. .withParam("region", "label_2")
  87. .init();
  88. cy.window().then((window: any | unknown) => {
  89. window.Htx.annotationStore.annotations[1].regionStore.setRegionVisible(window.LSF_CONFIG.region);
  90. });
  91. // Validate the annotation tab
  92. cy.get('[class="lsf-annotations-list__entity-id"]').should("contain.text", "20");
  93. Sidebar.hasRegions(3);
  94. Sidebar.hasHiddenRegion(0);
  95. });
  96. it("should select the target region by ID from param", () => {
  97. LabelStudio.params()
  98. .config(simpleRegionsConfig)
  99. .data(simpleRegionsData)
  100. .withResult(simpleRegionsResult)
  101. .withParam("region", "label_2")
  102. .init();
  103. cy.window().then((window: any | unknown) => {
  104. window.Htx.annotationStore.annotations[0].regionStore.selectRegionByID(window.LSF_CONFIG.region);
  105. });
  106. Sidebar.hasRegions(3);
  107. Sidebar.hasSelectedRegions(1);
  108. Sidebar.hasSelectedRegion(1);
  109. });
  110. it("should have tooltip for hide action", () => {
  111. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  112. Sidebar.hasRegions(3);
  113. Sidebar.hideAllRegionsButton.trigger("mouseover");
  114. Tooltip.hasText("Hide all regions");
  115. });
  116. it("should have tooltip for show action", () => {
  117. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  118. Sidebar.hasRegions(3);
  119. Sidebar.hideAllRegionsButton.click();
  120. Sidebar.showAllRegionsButton.trigger("mouseover");
  121. Tooltip.hasText("Show all regions");
  122. });
  123. it("should react to changes in regions' visibility", () => {
  124. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  125. Sidebar.hasRegions(3);
  126. Sidebar.hideAllRegionsButton.click();
  127. Sidebar.showAllRegionsButton.should("be.visible");
  128. Sidebar.toggleRegionVisibility(1);
  129. Sidebar.hideAllRegionsButton.should("be.visible");
  130. });
  131. it("should toggle visibility when its grouped by tool ", () => {
  132. LabelStudio.params().config(simpleRegionsConfig).data(simpleRegionsData).withResult(simpleRegionsResult).init();
  133. Sidebar.hasRegions(3);
  134. cy.get('[data-testid="grouping-manual"]').click();
  135. cy.wait(500);
  136. cy.contains("Group by Tool").click({ force: true });
  137. Sidebar.toggleRegionVisibility(0);
  138. Sidebar.hasHiddenRegion(3);
  139. });
  140. });