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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
import {
  AudioView,
  ImageView,
  Labels,
  LabelStudio,
  Sidebar,
  TimeSeries,
  VideoView,
} from "@humansignal/frontend-test/helpers/LSF";
import { RichText } from "@humansignal/frontend-test/helpers/LSF/RichText";
import { Paragraphs } from "@humansignal/frontend-test/helpers/LSF/Paragraphs";
import {
  imageRectangleLabelsConfig,
  imagePolygonLabelsConfig,
  richTextLabelsConfig,
  paragraphsLabelsConfig,
  audioLabelsConfig,
  timeseriesLabelsConfig,
  videoLabelsConfig,
  videoTimelineLabelsConfig,
  hyperTextLabelsConfig,
  testImageData,
  testTextData,
  testHyperTextData,
  testParagraphsData,
  testAudioData,
  testTimeseriesData,
  testVideoData,
} from "../../data/labels/multiple-label-blocks";
 
describe("Multiple Label Blocks - All Object Tags", () => {
  beforeEach(() => {
    LabelStudio.addFeatureFlagsOnPageLoad({
      fflag_fix_front_dev_3391_interactive_view_all: true,
      fflag_feat_front_bros_327_multiple_labels_regions_short: true,
    });
  });
  describe("Image Object Tag", () => {
    it("should create separate results for each label block - RectangleLabels", () => {
      cy.log("Initialize LSF with Image and multiple RectangleLabels blocks");
      LabelStudio.params()
        .config(imageRectangleLabelsConfig)
        .data(testImageData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      ImageView.waitForImage();
      Sidebar.hasNoRegions();
 
      cy.log("Select labels from different blocks");
      Labels.select("Circle"); // From shapes block
      Labels.select("Star"); // From objects block
      Labels.select("Visible"); // From general block
 
      cy.log("Draw a rectangle region");
      ImageView.drawRectRelative(0.1, 0.1, 0.3, 0.3);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(3);
 
        // Check results from each block
        const shapesResult = results.find((r: any) => r.from_name === "shapes");
        const objectsResult = results.find((r: any) => r.from_name === "objects");
        const generalResult = results.find((r: any) => r.from_name === "general");
 
        expect(shapesResult).to.exist;
        expect(objectsResult).to.exist;
        expect(generalResult).to.exist;
 
        expect(shapesResult.value.rectanglelabels).to.include("Circle");
        expect(objectsResult.value.rectanglelabels).to.include("Star");
        expect(generalResult.value.labels).to.include("Visible");
 
        // All results should have the same region coordinates
        expect(shapesResult.value.x).to.approximately(objectsResult.value.x, 1);
        expect(shapesResult.value.y).to.approximately(objectsResult.value.y, 1);
      });
    });
 
    it("should create separate results for each label block - PolygonLabels", () => {
      cy.log("Initialize LSF with Image and multiple PolygonLabels blocks");
      LabelStudio.params()
        .config(imagePolygonLabelsConfig)
        .data(testImageData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      ImageView.waitForImage();
      Sidebar.hasNoRegions();
 
      cy.log("Select labels from different polygon blocks");
      Labels.select("Area1"); // From areas block
      Labels.select("Region1"); // From regions block
      Labels.select("Tagged"); // From tags block
 
      cy.log("Draw a polygon region");
      // Draw polygon with multiple points
      ImageView.clickAtRelative(0.2, 0.2);
      ImageView.clickAtRelative(0.4, 0.2);
      ImageView.clickAtRelative(0.4, 0.4);
      ImageView.clickAtRelative(0.2, 0.4);
      // Close polygon by clicking on first point
      ImageView.clickAtRelative(0.2, 0.2);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each polygon label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(3);
 
        const areasResult = results.find((r: any) => r.from_name === "areas");
        const regionsResult = results.find((r: any) => r.from_name === "regions");
        const tagsResult = results.find((r: any) => r.from_name === "tags");
 
        expect(areasResult).to.exist;
        expect(regionsResult).to.exist;
        expect(tagsResult).to.exist;
 
        expect(areasResult.value.polygonlabels).to.include("Area1");
        expect(regionsResult.value.polygonlabels).to.include("Region1");
        expect(tagsResult.value.labels).to.include("Tagged");
      });
    });
  });
 
  describe("Text Object Tag", () => {
    it("should create separate results for each label block", () => {
      cy.log("Initialize LSF with Text and multiple Labels blocks");
      LabelStudio.params()
        .config(richTextLabelsConfig)
        .data(testTextData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select labels from different blocks");
      Labels.select("Animal"); // From entities block
      Labels.select("Fast"); // From sentiments block
 
      cy.log("Select text to create region");
      RichText.selectText("quick brown fox");
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const entitiesResult = results.find((r: any) => r.from_name === "entities");
        const sentimentsResult = results.find((r: any) => r.from_name === "sentiments");
 
        expect(entitiesResult).to.exist;
        expect(sentimentsResult).to.exist;
 
        expect(entitiesResult.value.labels).to.include("Animal");
        expect(sentimentsResult.value.labels).to.include("Fast");
 
        // Both should reference the same text span
        expect(entitiesResult.value.text).to.equal("quick brown fox");
        expect(sentimentsResult.value.text).to.equal("quick brown fox");
        expect(entitiesResult.value.start).to.equal(sentimentsResult.value.start);
        expect(entitiesResult.value.end).to.equal(sentimentsResult.value.end);
      });
    });
  });
 
  describe("HyperText Object Tag", () => {
    it("should create separate results for each label block", () => {
      cy.log("Initialize LSF with HyperText and multiple HyperTextLabels blocks");
      LabelStudio.params()
        .config(hyperTextLabelsConfig)
        .data(testHyperTextData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select labels from different blocks");
      Labels.select("Header"); // From elements block
      Labels.select("Important"); // From semantic block
 
      cy.log("Select text in hypertext to create region");
      RichText.selectText("Sample Article");
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const elementsResult = results.find((r: any) => r.from_name === "elements");
        const semanticResult = results.find((r: any) => r.from_name === "semantic");
 
        expect(elementsResult).to.exist;
        expect(semanticResult).to.exist;
 
        expect(elementsResult.value.hypertextlabels).to.include("Header");
        expect(semanticResult.value.hypertextlabels).to.include("Important");
      });
    });
  });
 
  describe("Paragraphs Object Tag", () => {
    it("should create separate results for each label block", () => {
      cy.log("Initialize LSF with Paragraphs and multiple ParagraphLabels blocks");
      LabelStudio.params()
        .config(paragraphsLabelsConfig)
        .data(testParagraphsData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select labels from different blocks");
      Labels.select("Introduction"); // From topics block
      Labels.select("High"); // From importance block
 
      cy.log("Select text from paragraph to create region");
      Paragraphs.selectText("Lorem ipsum dolor sit amet");
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const topicsResult = results.find((r: any) => r.from_name === "topics");
        const importanceResult = results.find((r: any) => r.from_name === "importance");
 
        expect(topicsResult).to.exist;
        expect(importanceResult).to.exist;
 
        expect(topicsResult.value.paragraphlabels).to.include("Introduction");
        expect(importanceResult.value.paragraphlabels).to.include("High");
 
        // Both results should reference the same paragraph
        expect(topicsResult.value.start).to.equal(importanceResult.value.start);
        expect(topicsResult.value.end).to.equal(importanceResult.value.end);
      });
    });
  });
 
  describe("Audio Object Tag", () => {
    it("should create separate results for each label block", () => {
      cy.log("Initialize LSF with Audio and multiple Labels blocks");
      LabelStudio.params()
        .config(audioLabelsConfig)
        .data(testAudioData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      AudioView.isReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select audio labels from different blocks");
      Labels.select("Speaker1"); // From speakers block
      Labels.select("Happy"); // From emotions block
 
      cy.log("Create audio region by drawing on waveform");
      AudioView.drawRectRelative(0.1, 0.2, 0.2, 0.3);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const speakersResult = results.find((r: any) => r.from_name === "speakers");
        const emotionsResult = results.find((r: any) => r.from_name === "emotions");
 
        expect(speakersResult).to.exist;
        expect(emotionsResult).to.exist;
 
        expect(speakersResult.value.labels).to.include("Speaker1");
        expect(emotionsResult.value.labels).to.include("Happy");
 
        // Both should reference the same audio region
        expect(speakersResult.value.start).to.approximately(emotionsResult.value.start, 0.1);
        expect(speakersResult.value.end).to.approximately(emotionsResult.value.end, 0.1);
      });
    });
  });
 
  describe("TimeSeries Object Tag", () => {
    it("should create separate results for each label block", () => {
      cy.log("Initialize LSF with TimeSeries and multiple TimeSeriesLabels blocks");
      LabelStudio.params()
        .config(timeseriesLabelsConfig)
        .data(testTimeseriesData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      TimeSeries.waitForReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select timeseries labels from different blocks");
      Labels.select("Peak"); // From events block
      Labels.select("Trend"); // From patterns block
 
      cy.log("Create timeseries region");
      TimeSeries.drawRegionRelative(0.1, 0.3);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const eventsResult = results.find((r: any) => r.from_name === "events");
        const patternsResult = results.find((r: any) => r.from_name === "patterns");
 
        expect(eventsResult).to.exist;
        expect(patternsResult).to.exist;
 
        expect(eventsResult.value.timeserieslabels).to.include("Peak");
        expect(patternsResult.value.timeserieslabels).to.include("Trend");
 
        // Both should reference the same time range
        expect(eventsResult.value.start).to.approximately(patternsResult.value.start, 0.1);
        expect(eventsResult.value.end).to.approximately(patternsResult.value.end, 0.1);
      });
    });
  });
 
  describe("Video Object Tag", () => {
    // @Todo: This test do not work because in `VideoRectangleResult` we have `mergeLabelsAndResults: true` and it just removes all labels. It should be investigated.
    it.skip("should create separate results for each label block", () => {
      cy.log("Initialize LSF with Video and multiple Labels blocks");
      LabelStudio.params()
        .config(videoLabelsConfig)
        .data(testVideoData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      Sidebar.hasNoRegions();
 
      cy.log("Select video labels from different blocks");
      Labels.select("Person"); // From objects block
      Labels.select("Walking"); // From actions block
 
      cy.log("Create video region by drawing rectangle using VideoView helper");
      VideoView.drawRectRelative(0.3, 0.3, 0.4, 0.4);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const objectsResult = results.find((r: any) => r.from_name === "objects");
        const actionsResult = results.find((r: any) => r.from_name === "actions");
 
        expect(objectsResult).to.exist;
        expect(actionsResult).to.exist;
 
        expect(objectsResult.value.labels).to.include("Person");
        expect(actionsResult.value.labels).to.include("Walking");
 
        // Both should reference the same video region
        expect(objectsResult.value.x).to.approximately(actionsResult.value.x, 1);
        expect(objectsResult.value.y).to.approximately(actionsResult.value.y, 1);
      });
    });
 
    it("should create separate results for each timeline label block", () => {
      cy.log("Initialize LSF with Video and multiple TimelineLabels blocks");
      LabelStudio.params()
        .config(videoTimelineLabelsConfig)
        .data(testVideoData)
        .withResult([])
        .withParam("settings", { continuousLabeling: false })
        .init();
 
      LabelStudio.waitForObjectsReady();
      VideoView.root.should("be.visible");
      Sidebar.hasNoRegions();
 
      cy.log("Select timeline labels from different blocks");
      Labels.select("Start"); // From events block
      Labels.select("Movement"); // From activities block
 
      cy.log("Wait for video timeline to be ready");
      VideoView.timelineContainer.should("be.visible");
 
      cy.log("Create timeline region by clicking on timeline");
      VideoView.clickAtFrame(10);
 
      cy.log("Verify region was created");
      Sidebar.hasRegions(1);
 
      cy.log("Verify separate results for each timeline label block");
      LabelStudio.serialize().then((results) => {
        expect(results).to.have.length(2);
 
        const eventsResult = results.find((r: any) => r.from_name === "events");
        const activitiesResult = results.find((r: any) => r.from_name === "activities");
 
        expect(eventsResult).to.exist;
        expect(activitiesResult).to.exist;
 
        expect(eventsResult.value.timelinelabels).to.include("Start");
        expect(activitiesResult.value.timelinelabels).to.include("Movement");
 
        // Both should reference the same timeline frame
        expect(eventsResult.value.ranges[0].start).to.equal(activitiesResult.value.ranges[0].start);
        expect(eventsResult.value.ranges[0].end).to.equal(activitiesResult.value.ranges[0].end);
      });
    });
  });
});