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
import { AudioView, Labels, LabelStudio, Relations } from "@humansignal/frontend-test/helpers/LSF";
import { audioOneRegionResult, audioWithLabelsConfig, audioWithLabelsData } from "../../data/audio/audio_regions";
 
// Audio regions test suite with improved stability through canvas synchronization
// Reduced retries from 3 to 1 due to improved timing and pixel sampling reliability
const suiteConfig = {
  retries: {
    runMode: 1,
    openMode: 0,
  },
};
 
describe("Audio regions", suiteConfig, () => {
  it("Should have indication of selected state", () => {
    cy.log("=== Testing audio region selected state indication ===");
    LabelStudio.params()
      .config(audioWithLabelsConfig)
      .data(audioWithLabelsData)
      .withResult(audioOneRegionResult)
      .init();
 
    LabelStudio.waitForObjectsReady();
    AudioView.isReady();
 
    // Wait for initial canvas rendering to stabilize
    AudioView.waitForCanvasStable();
    const baseRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    // Click to select region and wait for state transition
    AudioView.clickAtRelative(0.38, 0.5);
    AudioView.waitForCanvasStable();
    const selectedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    selectedRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
    });
 
    // Unselecting with ESC key
    cy.get("body").type("{esc}");
    AudioView.waitForCanvasStable();
    const unselectedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    unselectedRegionColor.then((color) => {
      baseRegionColor.should("deep.equal", color);
    });
  });
 
  it("Should have indication of active state", () => {
    cy.log("=== Testing audio region active state indication ===");
    LabelStudio.params()
      .config(audioWithLabelsConfig)
      .data(audioWithLabelsData)
      .withResult(audioOneRegionResult)
      .init();
 
    LabelStudio.waitForObjectsReady();
    AudioView.isReady();
 
    // Wait for audio visualization to stabilize before capturing baseline
    AudioView.waitForCanvasStable();
    const baseRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    // Moving the cursor to activate region
    AudioView.seekCurrentTimebox(38);
    // Allow time for active state rendering to complete
    AudioView.waitForCanvasStable();
    const activeRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    activeRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
    });
 
    // Deactivating by moving cursor away
    AudioView.seekCurrentTimebox(0);
    // Wait for inactive state to be fully rendered
    AudioView.waitForCanvasStable();
    const inactiveRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    inactiveRegionColor.then((color) => {
      baseRegionColor.should("deep.equal", color);
    });
  });
 
  it("Should have indication of highlighted state", () => {
    cy.log("=== Testing audio region highlighted state indication ===");
    LabelStudio.params()
      .config(audioWithLabelsConfig)
      .data(audioWithLabelsData)
      .withResult(audioOneRegionResult)
      .init();
 
    LabelStudio.waitForObjectsReady();
    AudioView.isReady();
 
    // Wait for initial rendering to stabilize
    AudioView.waitForCanvasStable();
    const baseRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    // Set up highlighting in relations mode
    Labels.select("Music");
    AudioView.drawRectRelative(0.1, 0.5, 0.1, 0, { force: true });
    AudioView.clickAtRelative(0.15, 0.5);
    Relations.toggleCreation();
 
    // Hover to highlight region
    AudioView.hoverAtRelative(0.4, 0.5);
    AudioView.waitForCanvasStable();
    const highlightedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    highlightedRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
    });
 
    // Unhighlighting by mouse leave
    AudioView.container.trigger("mouseleave");
    AudioView.waitForCanvasStable();
    const unhighlightedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    unhighlightedRegionColor.then((color) => {
      baseRegionColor.should("deep.equal", color);
    });
  });
 
  it("Should avoid intersection of active and highlighted states", () => {
    cy.log("=== Testing audio region state intersection avoidance ===");
    LabelStudio.params()
      .config(audioWithLabelsConfig)
      .data(audioWithLabelsData)
      .withResult(audioOneRegionResult)
      .init();
 
    LabelStudio.waitForObjectsReady();
    AudioView.isReady();
 
    // Wait for initial rendering to stabilize
    AudioView.waitForCanvasStable();
    const baseRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    // Set up highlighting in relations mode
    Labels.select("Music");
    AudioView.drawRectRelative(0.1, 0.5, 0.1, 0, { force: true });
    AudioView.clickAtRelative(0.15, 0.5);
    Relations.toggleCreation();
 
    // Hover to highlight region
    AudioView.hoverAtRelative(0.4, 0.5);
    AudioView.waitForCanvasStable();
    const highlightedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    highlightedRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
    });
 
    // Moving the cursor to activate region (while still highlighted)
    AudioView.seekCurrentTimebox(38);
    AudioView.waitForCanvasStable();
    const activeRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    activeRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
      highlightedRegionColor.should("deep.equal", color);
    });
 
    // Deactivating cursor (should still be highlighted)
    AudioView.seekCurrentTimebox(0);
    AudioView.waitForCanvasStable();
    const inactiveRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    // Should still be highlighted
    inactiveRegionColor.then((color) => {
      baseRegionColor.should("not.deep.equal", color);
      highlightedRegionColor.should("deep.equal", color);
    });
 
    // Unhighlighting by mouse leave
    AudioView.container.trigger("mouseleave");
    AudioView.waitForCanvasStable();
    const unhighlightedRegionColor = AudioView.getStablePixelColorRelative(0.36, 0.9);
 
    unhighlightedRegionColor.then((color) => {
      baseRegionColor.should("deep.equal", color);
    });
  });
});