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
const assert = require("assert");
 
Feature("Richtext regions displaying");
 
Scenario("Display correct colors", async ({ I, LabelStudio, AtLabels, AtRichText }) => {
  I.amOnPage("/");
  LabelStudio.init({
    config: `<View>
    <Labels name="label" toName="text">
        <Label value="Red" background="rgb(255,0,0)" />
        <Label value="Green" background="rgb(0,255,0)" />
        <Label value="Blue" background="rgb(0,0,255)" />
        <Label value="Yellow" background="rgb(255,255,0)" />
    </Labels>
    <Text name="text" value="$text" />
</View>`,
    data: {
      text: "Red. Green. Blue. Yellow.",
    },
    annotations: [
      {
        id: "test",
        result: [
          {
            id: "Red",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 0, end: 3, labels: ["Red"] },
          },
          {
            id: "Green",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 5, end: 10, labels: ["Green"] },
          },
        ],
      },
    ],
    settings: {
      selectAfterCreate: true,
    },
  });
 
  LabelStudio.waitForObjectsReady();
 
  {
    I.pressKey("u");
    const elementLocator = locate(".htx-highlight").withText("Red");
 
    I.say("Red is red");
    const color = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${color}`);
    assert(color.includes("(255, 0, 0"), "Oh no! Red is not red!");
    I.say("even if it's selected");
 
    I.click(elementLocator);
    const selectedColor = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${selectedColor}`);
    assert(selectedColor.includes("(255, 0, 0"), "Oh no! Red is not red!");
  }
  {
    I.pressKey("u");
    const elementLocator = locate(".htx-highlight").withText("Green");
 
    I.say("Green is green");
    const color = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${color}`);
    assert(color.includes("(0, 255, 0"), "Oh no! Green is not green!");
    I.say("even if it's selected");
 
    I.click(elementLocator);
    const selectedColor = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${selectedColor}`);
    assert(selectedColor.includes("(0, 255, 0"), "Oh no! Green is not green!");
  }
  {
    I.pressKey("u");
    I.say('Let\'s label "Blue" as `Blue`.');
    AtLabels.clickLabel("Blue");
    AtRichText.selectTextByGlobalOffset(12, 16);
 
    const elementLocator = locate(".htx-highlight").withText("Blue");
 
    I.say("Now Blue is blue");
    const color = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${color}`);
    assert(color.includes("(0, 0, 255"), "Oh no! Blue is not blue!");
    I.say("even if it's unselected");
 
    I.pressKey("u");
    const unselectedColor = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${unselectedColor}`);
    assert(unselectedColor.includes("(0, 0, 255"), "Oh no! Blue is not blue!");
  }
  {
    I.pressKey("u");
    I.say('Let\'s label "Yellow" as `Red`.');
    AtLabels.clickLabel("Red");
    AtRichText.selectTextByGlobalOffset(18, 24);
    I.say("Change it to Green");
    AtLabels.clickLabel("Green");
    I.say("and finally to Yellow");
    AtLabels.clickLabel("Yellow");
 
    const elementLocator = locate(".htx-highlight").withText("Yellow");
 
    I.say("It's really yellow now");
    const color = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${color}`);
    assert(color.includes("(255, 255, 0"), "Oh no! Yellow is not yellow!");
    I.say("even if it's unselected");
 
    I.pressKey("u");
    const unselectedColor = await I.grabCssPropertyFrom(elementLocator, "background-color");
 
    I.say(`The color of it is ${unselectedColor}`);
    assert(unselectedColor.includes("(255, 255, 0"), "Oh no! Yellow is not yellow!");
  }
});
 
Scenario("Displaying selected and highlighted regions", async ({ I, LabelStudio, AtOutliner, AtDetails }) => {
  I.amOnPage("/");
  LabelStudio.init({
    config: `<View>
    <Labels name="label" toName="text" allowempty="true">
        <Label value="Region" background="rgb(255,0,255)" />
    </Labels>
    <Text name="text" value="$text" />
</View>`,
    data: {
      text: "Region. Blank.",
    },
    annotations: [
      {
        id: "test",
        result: [
          {
            id: "Region",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 0, end: 6, labels: ["Region"] },
          },
          {
            id: "Blank",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 8, end: 13, labels: [] },
          },
        ],
      },
    ],
  });
 
  LabelStudio.waitForObjectsReady();
  AtOutliner.seeRegions(2);
 
  {
    I.say("Highlighted regions should have a different border");
    const originalBorder = await I.grabCssPropertyFrom(".htx-highlight", "border");
 
    {
      I.say("The different border should appears on hovering region");
      AtOutliner.hoverRegion(1);
 
      const hoveredBorder = await I.grabCssPropertyFrom(".htx-highlight", "border");
 
      assert.notEqual(
        originalBorder,
        hoveredBorder,
        "The border of the region hovered in outliner tree should be different from the normal state's value",
      );
    }
    {
      I.say("Unhover the region");
      I.moveCursorTo("#logo");
      const unhoveredBorder = await I.grabCssPropertyFrom(".htx-highlight", "border");
 
      assert.equal(
        originalBorder,
        unhoveredBorder,
        "The border of the region that was unhovered should be equal to the original state's value",
      );
    }
    {
      I.say('The other way to get hovered state id using the "Create relation" tool...');
      AtOutliner.clickRegion(2);
      AtDetails.clickCreateRelation();
 
      I.say("...and hover it inside the editor.");
      I.moveCursorTo(".htx-highlight");
      const hoveredBorder = await I.grabCssPropertyFrom(".htx-highlight", "border");
 
      assert.notEqual(
        originalBorder,
        hoveredBorder,
        "The border of the region hovered inside the editor tree should be different from the normal state's value",
      );
    }
  }
 
  I.say("Exit relation mode");
  I.pressKey("Escape"); // Exit linking mode
  I.say("Region should be still selected");
  I.seeElement(".htx-highlight.__active");
  I.pressKey("Escape"); // Unselect region
 
  {
    I.say("The background of the element should be visually different on selection");
    const originalBackground = await I.grabCssPropertyFrom(".htx-highlight", "background");
 
    AtOutliner.clickRegion(1);
    const selectedBackground = await I.grabCssPropertyFrom(".htx-highlight", "background");
 
    assert.notEqual(
      originalBackground,
      selectedBackground,
      "The background of the element should be visually different on selection",
    );
  }
});
 
Scenario("Displaying label in the region", async ({ I, LabelStudio, AtOutliner, AtSettings }) => {
  async function checkLabelVisibility(locator, content, shouldBeVisible = true) {
    const text = await I.grabCssPropertyFromPseudo(locator, "content", "after");
    const display = await I.grabCssPropertyFromPseudo(locator, "display", "after");
 
    assert.strictEqual(text, content, `Label name should be "${content}" but "${text}" was seen.`);
    if (shouldBeVisible) {
      assert.strictEqual(display, "inline", "Label should be visible.");
    } else {
      assert.strictEqual(display, "none", "Label should be hidden.");
    }
  }
 
  I.amOnPage("/");
  LabelStudio.init({
    config: `<View>
    <Labels name="label" toName="text" allowempty="true">
        <Label value="Region" background="rgb(255,0,255)" />
    </Labels>
    <Text name="text" value="$text" />
</View>`,
    data: {
      text: "Region. Blank.",
    },
    annotations: [
      {
        id: "test",
        result: [
          {
            id: "Region",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 0, end: 6, labels: ["Region"] },
          },
          {
            id: "Blank",
            from_name: "label",
            to_name: "text",
            type: "labels",
            value: { start: 8, end: 13, labels: [] },
          },
        ],
      },
    ],
    settings: {
      showLabels: true,
    },
  });
 
  LabelStudio.waitForObjectsReady();
  AtOutliner.seeRegions(2);
 
  await checkLabelVisibility(locate(".htx-highlight").at(1), '"1:Region"', true);
  await checkLabelVisibility(locate(".htx-highlight").at(2), '"2"', true);
 
  I.say("Hide labels in settings");
  AtSettings.open();
  AtSettings.setGeneralSettings({
    [AtSettings.GENERAL_SETTINGS.SHOW_LABELS]: false,
  });
  AtSettings.close();
  I.say("Make sure that label is hidden");
  await checkLabelVisibility(locate(".htx-highlight").at(1), '"1:Region"', false);
  await checkLabelVisibility(locate(".htx-highlight").at(2), '"2"', false);
});