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
import {
  Choices,
  DateTime,
  LabelStudio,
  Number,
  Rating,
  Textarea,
  ToolBar,
  useTextarea,
} from "@humansignal/frontend-test/helpers/LSF";
import { Hotkeys } from "@humansignal/frontend-test/helpers/LSF/Hotkeys";
import { FF_DEV_3873 } from "../../../../src/utils/feature-flags";
import { allClassificationsConfig, prediction, textData } from "../../data/control_tags/from-prediction";
 
describe("Classification from prediction", () => {
  it('by default should have origin "prediction"', () => {
    LabelStudio.params().config(allClassificationsConfig).data(textData).withPrediction(prediction).init();
    LabelStudio.waitForObjectsReady();
    LabelStudio.serialize().then((results) => {
      for (const result of results) {
        expect(result.origin).to.equal("prediction");
      }
    });
  });
 
  it('should have origin "prediction-changed" after changing prediction', () => {
    const SecondTextarea = useTextarea("&:eq(1)");
    LabelStudio.addFeatureFlagsOnPageLoad({
      [FF_DEV_3873]: true,
    });
    LabelStudio.params().config(allClassificationsConfig).data(textData).withPrediction(prediction).init();
    LabelStudio.waitForObjectsReady();
    ToolBar.clickCopyAnnotationBtn();
    LabelStudio.waitForObjectsReady();
    Choices.findChoice("Choice 2").click();
    DateTime.type("1999-11-11T11:11:11.111Z");
    Number.type("123");
    Rating.setValue(2);
    Textarea.type("Some other text{Enter}");
    SecondTextarea.clickRowEdit(1);
    SecondTextarea.rowInput(1).dblclick();
    SecondTextarea.rowType(1, " longer at the end{Enter}");
    LabelStudio.serialize().then((results) => {
      for (const result of results) {
        expect(result.origin).to.equal(
          "prediction-changed",
          `Prediction origin was not updated for "${result.from_name}"`,
        );
      }
    });
  });
 
  it("should work correctly with undo", () => {
    const SecondTextarea = useTextarea("&:eq(1)");
    LabelStudio.addFeatureFlagsOnPageLoad({
      [FF_DEV_3873]: true,
    });
    LabelStudio.params().config(allClassificationsConfig).data(textData).withPrediction(prediction).init();
    LabelStudio.waitForObjectsReady();
    ToolBar.clickCopyAnnotationBtn();
    LabelStudio.waitForObjectsReady();
    Choices.findChoice("Choice 2").click();
    DateTime.type("1999-11-11T11:11:11.111Z");
    Number.type("1");
    Rating.setValue(2);
    Textarea.type("Some other text{Enter}");
    SecondTextarea.clickRowEdit(1);
    SecondTextarea.rowInput(1).dblclick();
    SecondTextarea.rowType(1, " longer at the end{Enter}");
    for (let i = 0; i < 6; i++) {
      Hotkeys.undo();
    }
    LabelStudio.serialize().then((results) => {
      for (const result of results) {
        expect(result.origin).to.equal("prediction");
      }
    });
  });
});