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
const assert = require("assert");
 
Feature("Richtext edge cases");
 
const edgeCaseConfig = `<View>
    <Labels name="label" toName="html">
        <Label value="Highlight" background="rgb(255, 64, 182)" />
    </Labels>
    <HyperText name="html" value="$html" />
</View>`;
const edgeCaseHtml = `<p>This
is an <u><span>e</span><span>x</span><span>a</span><span>m</span><span>p</span><span>l</span><span>e</span></u><br/> of 
<abbr tytle="HyperText Markup Language"><b>HTML</b></abbr>
</p>`;
 
const edgeCaseResultValue1 = {
  start: "/p[1]/text()[2]",
  end: "/p[1]/abbr[1]/b[1]/text()[1]",
  startOffset: 1,
  endOffset: 4,
  globalOffsets: { start: 20, end: 28 },
  text: "of HTML",
  labels: ["Highlight"],
};
const edgeCaseResultValue2 = {
  start: "/p[1]/text()[2]",
  end: "/p[1]/abbr[1]/b[1]/text()[1]",
  startOffset: 2,
  endOffset: 1,
  globalOffsets: { start: 21, end: 25 },
  text: "f H",
  labels: ["Highlight"],
};
const edgeCaseResultValue3 = {
  start: "/p[1]/text()[1]",
  end: "/p[1]/abbr[1]/b[1]/text()[1]",
  startOffset: 0,
  endOffset: 4,
  globalOffsets: { start: 0, end: 28 },
  text: "This is an example\\nof HTML",
  labels: ["Highlight"],
};
const edgeCaseResultValue4 = {
  start: "/p[1]/u[1]/span[1]/text()[1]",
  end: "/p[1]/u[1]/span[7]/text()[1]",
  startOffset: 0,
  endOffset: 1,
  globalOffsets: { start: 11, end: 18 },
  text: "example",
  labels: ["Highlight"],
};
 
Scenario(
  "Creating, removing and restoring regions in not normalized HTML content",
  async ({ I, LabelStudio, AtOutliner, AtLabels, AtRichText }) => {
    I.amOnPage("/");
 
    LabelStudio.init({
      config: edgeCaseConfig,
      data: {
        html: edgeCaseHtml,
      },
      annotations: [
        {
          id: "test",
          result: [],
        },
      ],
    });
 
    LabelStudio.waitForObjectsReady();
 
    I.say('Select "of HTML"');
    AtLabels.clickLabel("Highlight");
    AtRichText.selectTextByGlobalOffset(20, 28);
 
    I.say('Select "f H"');
    AtLabels.clickLabel("Highlight");
    AtRichText.selectTextByGlobalOffset(21, 25);
 
    I.say("Select everithing");
    AtLabels.clickLabel("Highlight");
    AtRichText.selectTextByGlobalOffset(0, 28);
 
    I.say('Select "example"');
    AtLabels.clickLabel("Highlight");
    AtRichText.selectTextByGlobalOffset(11, 18);
 
    // check results
    AtOutliner.seeRegions(4);
 
    AtOutliner.clickRegion(1);
    I.seeElement(locate(".lsf-region-meta__content").withText("of HTML"));
    AtOutliner.clickRegion(2);
    I.seeElement(locate(".lsf-region-meta__content").withText("f H"));
    AtOutliner.clickRegion(3);
    I.seeElement(locate(".lsf-region-meta__content").withText("This is an example\nof HTML"));
    AtOutliner.clickRegion(4);
    I.seeElement(locate(".lsf-region-meta__content").withText("example"));
 
    const result = await LabelStudio.serialize();
 
    assert.deepStrictEqual(result[0].value, edgeCaseResultValue1);
    assert.deepStrictEqual(result[1].value, edgeCaseResultValue2);
    assert.deepStrictEqual(result[2].value, edgeCaseResultValue3);
    assert.deepStrictEqual(result[3].value, edgeCaseResultValue4);
 
    I.say("Reload and re-init to check results once again");
 
    I.amOnPage("/");
 
    LabelStudio.init({
      config: edgeCaseConfig,
      data: {
        html: edgeCaseHtml,
      },
      annotations: [
        {
          id: "test",
          result,
        },
      ],
    });
 
    LabelStudio.waitForObjectsReady();
 
    {
      // check results
      AtOutliner.seeRegions(4);
 
      AtOutliner.clickRegion(1);
      I.seeElement(locate(".lsf-region-meta__content").withText("of HTML"));
      AtOutliner.clickRegion(2);
      I.seeElement(locate(".lsf-region-meta__content").withText("f H"));
      AtOutliner.clickRegion(3);
      I.seeElement(locate(".lsf-region-meta__content").withText("This is an example\nof HTML"));
      AtOutliner.clickRegion(4);
      I.seeElement(locate(".lsf-region-meta__content").withText("example"));
 
      const result = await LabelStudio.serialize();
 
      assert.deepStrictEqual(result[0].value, edgeCaseResultValue1);
      assert.deepStrictEqual(result[1].value, edgeCaseResultValue2);
      assert.deepStrictEqual(result[2].value, edgeCaseResultValue3);
      assert.deepStrictEqual(result[3].value, edgeCaseResultValue4);
    }
  },
);