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
const { serialize, selectText } = require("./helpers");
 
const assert = require("assert");
 
Feature("Nested Choices");
 
const configSimple = `
  <View>
    <Text name="text" value="$reviewText" valueType="text" />
    <Choices name="sentiment" toName="text" showInLine="true">
      <Choice value="Positive" />
      <Choice value="Negative" />
      <Choice value="Neutral" />
    </Choices>
    <Choices
      name="ch"
      toName="text"
      choice="single"
      showInLine="true"
      visibleWhen="choice-selected"
    >
      <Choice value="Descriptive" />
      <Choice value="Emotional" />
    </Choices>
  </View>`;
 
const configComplicated = `
  <View>
    <Labels name="ner" toName="my_text" choice="multiple">
      <Label value="Person" background="red"/>
      <Label value="Organization" background="darkorange"/>
      <Label value="Fact" background="orange"/>
      <Label value="Money" background="green"/>
      <Label value="Date" background="darkblue"/>
      <Label value="Time" background="blue"/>
      <Label value="Ordinal" background="purple"/>
      <Label value="Percent" background="#842"/>
      <Label value="Product" background="#428"/>
      <Label value="Language" background="#482"/>
      <Label value="Location" background="rgba(0,0,0,0.8)"/>
    </Labels>
    <Text name="my_text" value="$reviewText"/>
    <Choices name="sentiment" toName="my_text" choice="single" showInLine="true">
      <Choice value="Positive"/>
      <Choice value="Negative"/>
      <Choice value="Neutral"/>
    </Choices>
    <Choices name="positive" toName="my_text"
             visibleWhen="choice-selected"
             whenTagName="sentiment"
             whenChoiceValue="Positive">
      <Choice value="Smile" />
      <Choice value="Laughter" />
    </Choices>
    <View visibleWhen="region-selected" whenLabelValue="Person">
      <Header>More details about this person:</Header>
      <Textarea name="description" toName="my_text" perRegion="true"
                choice="single" showInLine="true" whenLabelValue="Person">
      </Textarea>
      <Choices name="gender" toName="my_text" perRegion="true"
               choice="single" showInLine="true" whenLabelValue="Person">
        <Choice value="Female"/>
        <Choice value="Male"/>
      </Choices>
    </View>
    <Choices name="currency" toName="my_text" perRegion="true"
             choice="single" showInLine="true" whenLabelValue="Money">
      <Choice value="USD"/>
      <Choice value="EUR"/>
    </Choices>
    <Choices name="sentiment2" toName="my_text"
             choice="single" showInLine="true" perRegion="true">
      <Choice value="Positive"/>
      <Choice value="Negative"/>
    </Choices>
  </View>`;
 
const reviewText =
  "Not much to write about here, but it does exactly what it's supposed to. filters out the pop sounds. now my recordings are much more crisp. it is one of the lowest prices pop filters on amazon so might as well buy it, they honestly work the same despite their pricing,";
 
Scenario("Check simple nested Choices for Text", async ({ I, LabelStudio }) => {
  const params = {
    config: configSimple,
    data: { reviewText },
  };
 
  I.amOnPage("/");
  LabelStudio.init(params);
 
  I.see("Positive");
  I.dontSee("Emotional");
  I.click("Positive");
  I.see("Emotional");
  I.click("Emotional");
 
  const result = await I.executeScript(serialize);
 
  assert.equal(result.length, 2);
  assert.deepEqual(result[0].value, { choices: ["Positive"] });
  assert.deepEqual(result[1].value, { choices: ["Emotional"] });
});
 
Scenario("Check good nested Choice for Text", async ({ I, LabelStudio, AtLabels, AtOutliner }) => {
  const params = {
    config: configComplicated,
    data: { reviewText },
  };
 
  I.amOnPage("/");
  LabelStudio.init(params);
 
  I.click("Positive");
  I.see("Laughter");
  I.click("Laughter");
 
  const personTag = AtLabels.locateLabel("Person");
 
  I.seeElement(personTag);
  I.click(personTag);
  I.executeScript(selectText, {
    selector: ".lsf-htx-richtext",
    rangeStart: 51,
    rangeEnd: 55,
  });
  AtOutliner.seeRegions(1);
  I.dontSee("Female");
 
  // select this region
  AtOutliner.clickRegion(1);
 
  AtOutliner.seeRegions(1);
  I.see("More details"); // View with visibleWhen
 
  I.click("Female");
  // second click on already assigned label should do nothing
  I.click(personTag);
 
  const result = await I.executeScript(serialize);
 
  assert.equal(result.length, 4);
  assert.deepEqual(result[0].value.choices, ["Positive"]);
  assert.deepEqual(result[1].value.choices, ["Laughter"]);
  assert.deepEqual(result[2].value.labels, ["Person"]);
  assert.deepEqual(result[3].value.choices, ["Female"]);
});
 
Scenario("Check removing unexpected results based on visibleWhen parameter", async ({ I, LabelStudio }) => {
  const params = {
    config: `<View>
  <Text name="text" value="$reviewText" valueType="text" />
  <Choices name="sentiment" toName="text" showInLine="true">
    <Choice value="Positive" />
    <Choice value="Negative" />
    <Choice value="Neutral" />
  </Choices>
  <Choices
    name="rate" toName="text" choice="single" showInLine="true"
    visibleWhen="choice-unselected"
    whenTagName="sentiment"
    whenChoiceValue="Neutral"
  >
    <Choice value="One" />
    <Choice value="Two" />
    <Choice value="Three" />
    <Choice value="Four" />
    <Choice value="Five" />
  </Choices>
</View>`,
    data: { reviewText },
  };
 
  I.amOnPage("/");
  LabelStudio.init(params);
 
  I.see("Neutral");
  I.see("Five");
  // Choose rate
  I.click("Five");
  // Then hide it by choosing value from the visibleWhen="choice-unselected" dependency
  I.click("Neutral");
  let result = await I.executeScript(serialize);
 
  // The hidden choose should not make a result
  assert.equal(result.length, 1);
  assert.deepEqual(result[0].value, { choices: ["Neutral"] });
 
  // Check that it still works in case of no hidding
  I.click("Positive");
  result = await I.executeScript(serialize);
  assert.equal(result.length, 2);
  assert.deepEqual(result[0].value, { choices: ["Five"] });
  assert.deepEqual(result[1].value, { choices: ["Positive"] });
});