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
import { LabelStudio } from "@humansignal/frontend-test/helpers/LSF";
import { FF_DEV_3873, FF_SIMPLE_INIT } from "libs/editor/src/utils/feature-flags";
 
describe("Label Studio UI init", () => {
  it("Initialize empty Label Studio", () => {
    LabelStudio.init({
      config: "<View></View>",
      task: {
        annotations: [],
        predictions: [],
        id: 1,
        data: {
          image:
            "https://htx-pub.s3.us-east-1.amazonaws.com/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg",
        },
      },
    });
    cy.contains("No more annotations").should("be.visible");
  });
 
  it("Initialize Label Studio", () => {
    LabelStudio.init({
      config: "<View></View>",
      task: {
        annotations: [{ id: 1, result: [] }],
        predictions: [],
        id: 1,
        data: {
          image:
            "https://htx-pub.s3.us-east-1.amazonaws.com/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg",
        },
      },
    });
    cy.contains("Labeled regions will appear here").should("be.visible");
  });
 
  it("Initialize Label Studio with simple init FF (LEAP-443)", () => {
    const callApi = cy.spy().as("callApi");
 
    // testing both new UI and simple init FF
    LabelStudio.setFeatureFlagsOnPageLoad({
      [FF_SIMPLE_INIT]: true,
      [FF_DEV_3873]: true,
    });
 
    LabelStudio.init({
      onSubmitAnnotation: (annotation: object) => {
        callApi(annotation);
      },
      config: "<View></View>",
      task: {
        annotations: [
          { id: 1, result: [] },
          { id: 2, result: [] },
        ],
        predictions: [],
        id: 1,
        data: {
          image:
            "https://htx-pub.s3.us-east-1.amazonaws.com/examples/images/nick-owuor-astro-nic-visuals-wDifg5xc9Z4-unsplash.jpg",
        },
      },
    });
    cy.contains("Labeled regions will appear here").should("be.visible");
    // we already have an annotation, so we should have Update button and no Submit button
    cy.contains("Update").should("be.visible");
    cy.contains("Submit").should("not.exist");
 
    // now we create a new annotation and submit it
    cy.get('[aria-label="Create an annotation"]').click();
    cy.contains("Update").should("not.exist");
    cy.contains("Submit").should("be.visible");
 
    // submit by hotkey
    cy.get("body").type(Cypress.platform === "darwin" ? "{cmd}{enter}" : "{ctrl}{enter}");
 
    // we should have called the API once
    cy.get("@callApi").should("have.been.calledOnce");
 
    // @todo technically we should have Update button and no Submit button again,
    // @todo but currently this logic is crazy and we reload task in LSO/LSE anyway;
    // @todo so at least we check that there is only one of these two buttons.
    cy.contains("Submit").should("be.visible");
    cy.contains("Update").should("not.exist");
  });
});