const { serialize, selectText } = require("./helpers");
const assert = require("assert");
Feature("Nested Choices");
const configSimple = `
`;
const configComplicated = `
More details about this person:`;
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: ``,
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"] });
});