Bin
2025-12-16 9e0b2ba2c317b1a86212f24cbae3195ad1f3dbfa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import { Collapse, LabelStudio } from "@humansignal/frontend-test/helpers/LSF";
import {
  simpleData,
  basicCollapseConfig,
  nonAccordionCollapseConfig,
  borderedCollapseConfig,
  globalOpenCollapseConfig,
  mixedOpenCollapseConfig,
  globalOpenWithOverridesConfig,
  allParamsCollapseConfig,
} from "../../data/visual_tags/collapse";
 
describe("Visual Tags - Collapse", () => {
  describe("Basic functionality", () => {
    it("should render Collapse with default settings", () => {
      LabelStudio.params().config(basicCollapseConfig).data(simpleData).withResult([]).init();
 
      Collapse.root.should("be.visible");
      Collapse.panels.should("have.length", 3);
 
      // All panels should be collapsed by default
      Collapse.findPanel("Panel 1").should("be.visible");
      Collapse.findPanel("Panel 2").should("be.visible");
      Collapse.findPanel("Panel 3").should("be.visible");
 
      // Content should not be visible initially
      cy.contains("Content for panel 1").should("not.be.visible");
      cy.contains("Content for panel 2").should("not.be.visible");
      cy.contains("Content for panel 3").should("not.be.visible");
    });
 
    it("should expand and collapse panels on click", () => {
      LabelStudio.params().config(basicCollapseConfig).data(simpleData).withResult([]).init();
 
      // Check that no panels are active initially
      cy.get(".ant-collapse-content-active").should("have.length", 0);
 
      // Click to expand first panel
      Collapse.findTab("Panel 1").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 1").should("be.visible");
 
      // Click to collapse first panel
      Collapse.findTab("Panel 1").click();
 
      cy.get(".ant-collapse-content-active").should("have.length", 0);
      cy.contains("Content for panel 1").should("not.be.visible");
 
      // Click to expand second panel
      Collapse.findTab("Panel 2").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 2").should("be.visible");
 
      // First panel should still be collapsed (accordion mode)
      cy.contains("Content for panel 1").should("not.be.visible");
    });
  });
 
  describe("Accordion mode", () => {
    it("should work in accordion mode by default (only one panel open at a time)", () => {
      LabelStudio.params().config(basicCollapseConfig).data(simpleData).withResult([]).init();
 
      // Open first panel
      Collapse.findPanel("Panel 1").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 1").should("be.visible");
      cy.contains("Content for panel 2").should("not.be.visible");
      cy.contains("Content for panel 3").should("not.be.visible");
 
      // Open second panel - first should close
      Collapse.findPanel("Panel 2").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 1").should("not.be.visible");
      cy.contains("Content for panel 2").should("be.visible");
      cy.contains("Content for panel 3").should("not.be.visible");
 
      // Open third panel - second should close
      Collapse.findPanel("Panel 3").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 1").should("not.be.visible");
      cy.contains("Content for panel 2").should("not.be.visible");
      cy.contains("Content for panel 3").should("be.visible");
    });
 
    it("should allow multiple panels open when accordion=false", () => {
      LabelStudio.params().config(nonAccordionCollapseConfig).data(simpleData).withResult([]).init();
 
      // Open first panel
      Collapse.findPanel("Panel 1").click();
      cy.get(".ant-collapse-content-active").should("have.length", 1);
      cy.contains("Content for panel 1").should("be.visible");
 
      // Open second panel - first should remain open
      Collapse.findPanel("Panel 2").click();
      cy.get(".ant-collapse-content-active").should("have.length", 2);
      cy.contains("Content for panel 1").should("be.visible");
      cy.contains("Content for panel 2").should("be.visible");
 
      // Open third panel - all should be open
      Collapse.findPanel("Panel 3").click();
      cy.get(".ant-collapse-content-active").should("have.length", 3);
      cy.contains("Content for panel 1").should("be.visible");
      cy.contains("Content for panel 2").should("be.visible");
      cy.contains("Content for panel 3").should("be.visible");
    });
  });
 
  describe("Bordered style", () => {
    it("should show borders when bordered=true", () => {
      LabelStudio.params().config(borderedCollapseConfig).data(simpleData).withResult([]).init();
 
      // When bordered=true, should have borders (default ant-collapse class has borders)
      Collapse.root.should("not.have.class", "ant-collapse-borderless");
    });
 
    it("should not show borders by default", () => {
      LabelStudio.params().config(basicCollapseConfig).data(simpleData).withResult([]).init();
 
      // When bordered=false (default), should have borderless class
      Collapse.root.should("have.class", "ant-collapse-borderless");
    });
  });
 
  describe("Open parameter behavior", () => {
    it("should open all panels when global open=true", () => {
      LabelStudio.params().config(globalOpenCollapseConfig).data(simpleData).withResult([]).init();
 
      // Wait for the component to render
      cy.get(".ant-collapse").should("be.visible");
 
      // Check if panels are open by looking for active class
      cy.get(".ant-collapse-content").should("have.length", 3);
    });
 
    it("should respect panel-level open overrides", () => {
      LabelStudio.params().config(mixedOpenCollapseConfig).data(simpleData).withResult([]).init();
 
      // Wait for the component to render
      cy.get(".ant-collapse").should("be.visible");
 
      // Check if correct panels are open
      cy.get(".ant-collapse-content").should("have.length", 3);
      cy.get(".ant-collapse-content-active").should("have.length", 2);
    });
 
    it("should allow panels to override global open=true", () => {
      LabelStudio.params().config(globalOpenWithOverridesConfig).data(simpleData).withResult([]).init();
 
      // Wait for the component to render
      cy.get(".ant-collapse").should("be.visible");
 
      // Check if correct panels are open
      cy.get(".ant-collapse-content").should("have.length", 3);
      cy.get(".ant-collapse-content-active").should("have.length", 1);
    });
  });
 
  describe("All parameters combined", () => {
    it("should work with all parameters set together", () => {
      LabelStudio.params().config(allParamsCollapseConfig).data(simpleData).withResult([]).init();
 
      // Wait for the component to render
      cy.get(".ant-collapse").should("be.visible");
 
      // Should have bordered style
      Collapse.root.should("not.have.class", "ant-collapse-borderless");
 
      // Global open=true, but some panels override
      cy.contains("Content for panel 1").should("not.be.visible"); // Panel 1: open=false
      cy.contains("Content for panel 2").should("be.visible"); // Panel 2: no override, uses global
      cy.contains("Content for panel 3").should("not.be.visible"); // Panel 3: open=false
 
      // Should allow multiple panels open (accordion=false)
      cy.get(".ant-collapse-header").contains("Panel 1").click();
      cy.contains("Content for panel 1").should("be.visible");
      cy.contains("Content for panel 2").should("be.visible"); // Still open
 
      cy.get(".ant-collapse-header").contains("Panel 3").click();
      cy.contains("Content for panel 3").should("be.visible");
      // All panels should be open now
      cy.contains("Content for panel 1").should("be.visible");
      cy.contains("Content for panel 2").should("be.visible");
      cy.contains("Content for panel 3").should("be.visible");
    });
  });
 
  describe("Edge cases", () => {
    it("should handle empty panels", () => {
      const emptyPanelConfig = `
        <View>
          <Collapse>
            <Panel value="Empty Panel">
            </Panel>
            <Panel value="Panel with Content">
              <Text name="text" value="Some content" />
            </Panel>
          </Collapse>
        </View>
      `;
 
      LabelStudio.params().config(emptyPanelConfig).data(simpleData).withResult([]).init();
 
      Collapse.findPanel("Empty Panel").should("be.visible");
      Collapse.findPanel("Panel with Content").should("be.visible");
 
      // Empty panel should still be clickable
      Collapse.findPanel("Empty Panel").click();
      // Should not throw errors
    });
 
    it("should handle panels with only whitespace content", () => {
      const whitespaceConfig = `
        <View>
          <Collapse>
            <Panel value="Whitespace Panel">
              <Text name="text" value="   " />
            </Panel>
          </Collapse>
        </View>
      `;
 
      LabelStudio.params().config(whitespaceConfig).data(simpleData).withResult([]).init();
 
      Collapse.findPanel("Whitespace Panel").should("be.visible");
      Collapse.findPanel("Whitespace Panel").click();
      // Should not throw errors
    });
  });
 
  describe("Accessibility", () => {
    it("should have proper ARIA attributes", () => {
      LabelStudio.params().config(basicCollapseConfig).data(simpleData).withResult([]).init();
 
      // Check that collapse headers have proper role
      Collapse.panels.each(($panel) => {
        cy.wrap($panel).find(".ant-collapse-header").should("have.attr", "role", "tab");
      });
    });
  });
});