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
import { LabelStudio } from "@humansignal/frontend-test/helpers/LSF";
import { FF_DEV_3873 } from "../../../../src/utils/feature-flags";
 
describe("Annotation ID", () => {
  beforeEach(() => {
    LabelStudio.addFeatureFlagsOnPageLoad({
      [FF_DEV_3873]: true,
    });
  });
 
  it("should have data-annotation-id attribute on all annotation buttons", () => {
    // Initialize with multiple annotations to test with different IDs
    LabelStudio.init({
      config: `<View>
        <Text name="text" value="$text"/>
        <Choices name="choice" toName="text">
          <Choice value="Choice1"/>
          <Choice value="Choice2"/>
        </Choices>
      </View>`,
      task: {
        id: 1,
        annotations: [
          { id: 1001, result: [] },
          { id: 1002, result: [] },
          { id: 1003, result: [] },
        ],
        predictions: [],
        data: {
          text: "Sample text for annotation testing",
        },
      },
    });
 
    LabelStudio.waitForObjectsReady();
 
    // Get all annotation buttons
    cy.get(".lsf-annotation-button").should("have.length", 3);
 
    // Annotations are displayed in reverse order (newest first)
    // Verify each annotation button has the correct data-annotation-id attribute
    cy.log("Verifying data-annotation-id attributes");
    cy.get('[data-annotation-id="1003"]').should("exist");
    cy.get('[data-annotation-id="1002"]').should("exist");
    cy.get('[data-annotation-id="1001"]').should("exist");
 
    // Verify the attributes are on the annotation buttons in the correct order
    cy.get(".lsf-annotation-button").eq(0).should("have.attr", "data-annotation-id", "1003");
    cy.get(".lsf-annotation-button").eq(1).should("have.attr", "data-annotation-id", "1002");
    cy.get(".lsf-annotation-button").eq(2).should("have.attr", "data-annotation-id", "1001");
  });
 
  it("should copy the correct annotation ID to clipboard", () => {
    // Initialize with a single annotation for simpler clipboard testing
    LabelStudio.init({
      config: `<View>
        <Text name="text" value="$text"/>
        <Choices name="choice" toName="text">
          <Choice value="Choice1"/>
        </Choices>
      </View>`,
      task: {
        id: 1,
        annotations: [{ id: 5001, result: [] }],
        predictions: [],
        data: {
          text: "Sample text",
        },
      },
    });
 
    LabelStudio.waitForObjectsReady();
 
    // Stub the clipboard API
    cy.window().then((win) => {
      cy.stub(win.navigator.clipboard, "writeText").resolves();
    });
 
    // Verify the data-annotation-id attribute matches what gets copied
    cy.get('[data-annotation-id="5001"]').should("exist");
 
    // Open context menu and copy annotation ID
    cy.get(".lsf-annotation-button__trigger").click();
    cy.get(".lsf-dropdown:visible").find('[class*="option--"]').contains("Copy Annotation ID").click();
 
    // Verify clipboard was called with the same ID as the data attribute
    cy.window().then((win) => {
      expect(win.navigator.clipboard.writeText).to.have.been.calledWith("5001");
    });
  });
 
  it("should allow selecting annotation by data-annotation-id attribute", () => {
    LabelStudio.init({
      config: `<View>
        <Text name="text" value="$text"/>
        <Choices name="choice" toName="text">
          <Choice value="Choice1"/>
        </Choices>
      </View>`,
      task: {
        id: 1,
        annotations: [
          { id: 2001, result: [] },
          { id: 2002, result: [] },
        ],
        predictions: [],
        data: {
          text: "Sample text",
        },
      },
    });
 
    LabelStudio.waitForObjectsReady();
 
    // Verify we can select annotation by data-annotation-id
    cy.log("Selecting annotation with ID 2002 using data attribute");
    cy.get('[data-annotation-id="2002"]').should("exist").click();
 
    // Verify the annotation is selected
    cy.get('[data-annotation-id="2002"]').should("have.class", "lsf-annotation-button_selected");
 
    // Select different annotation
    cy.log("Selecting annotation with ID 2001 using data attribute");
    cy.get('[data-annotation-id="2001"]').should("exist").click();
 
    // Verify the new annotation is selected and the previous one is not
    cy.get('[data-annotation-id="2001"]').should("have.class", "lsf-annotation-button_selected");
    cy.get('[data-annotation-id="2002"]').should("not.have.class", "lsf-annotation-button_selected");
  });
});