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
import { generateSampleTaskFromConfig } from "../generateSampleTask";
 
describe("generateSampleTaskFromConfig", () => {
  it("should handle empty config", async () => {
    const result = await generateSampleTaskFromConfig("");
    expect(result).toEqual({
      id: 1,
      data: {},
      annotations: [{ id: 1, result: [] }],
      predictions: [],
    });
  });
 
  it("should handle invalid XML", async () => {
    const result = await generateSampleTaskFromConfig("<invalid>");
    expect(result).toEqual({
      id: 1,
      data: {},
      annotations: [{ id: 1, result: [] }],
      predictions: [],
    });
  });
 
  it("should generate sample data for image config", async () => {
    const config = `
      <View>
        <Image name="image" value="$image"/>
        <RectangleLabels name="labels" toName="image">
          <Label value="Person" background="#ff0000"/>
          <Label value="Car" background="#00ff00"/>
        </RectangleLabels>
      </View>
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("image");
    expect(result.data.image).toBe("https://app.heartex.ai/static/samples/sample.jpg");
  });
 
  it("should generate sample data for audio config", async () => {
    const config = `
      <View>
        <Audio name="audio" value="$audio"/>
        <Labels name="labels" toName="audio">
          <Label value="Speech" background="#ff0000"/>
          <Label value="Music" background="#00ff00"/>
        </Labels>
      </View>
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("audio");
    expect(result.data.audio).toBe(
      "https://upload.wikimedia.org/wikipedia/commons/9/9d/Bach_-_Cello_Suite_no._1_in_G_major,_BWV_1007_-_I._Pr%C3%A9lude.ogg",
    );
  });
 
  it("should generate sample data for text config", async () => {
    const config = `
      <View>
        <Text name="text" value="$text"/>
        <Labels name="labels" toName="text">
          <Label value="Positive" background="#ff0000"/>
          <Label value="Negative" background="#00ff00"/>
        </Labels>
      </View>
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("text");
    expect(result.data.text).toBe("Sample: Your text will go here.");
  });
 
  it("should handle user data in comments", async () => {
    const config = `
      <View>
        <Text name="text" value="$text"/>
      </View>
      <!-- {"data": {"text": "Custom sample text"}} -->
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("text");
    expect(result.data.text).toBe("Custom sample text");
  });
 
  it("should handle user annotation in comments", async () => {
    const config = `
      <View>
        <Text name="text" value="$text"/>
      </View>
      <!-- {"annotation": {"from_name": "labels", "to_name": "text", "type": "labels", "value": {"start": 0, "end": 5, "labels": ["Positive"]}}} -->
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.annotations).toBeDefined();
    if (result.annotations) {
      expect(result.annotations).toHaveLength(1);
      expect(result.annotations[0].result).toHaveLength(1);
      expect(result.annotations[0].result[0]).toEqual({
        from_name: "labels",
        to_name: "text",
        type: "labels",
        value: { start: 0, end: 5, labels: ["Positive"] },
      });
    }
  });
 
  it("should handle valueList attributes", async () => {
    const config = `
      <View>
        <Image name="image" valueList="$images"/>
        <RectangleLabels name="labels" toName="image">
          <Label value="Person" background="#ff0000"/>
        </RectangleLabels>
      </View>
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("images");
    expect(Array.isArray(result.data.images)).toBe(true);
    expect(result.data.images).toHaveLength(2);
  });
 
  it("should handle valueType='url' attribute", async () => {
    const config = `
      <View>
        <Text name="text" valueType="url" value="$url"/>
      </View>
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("url");
    expect(result.data.url).toBe("Sample: Your text will go here.");
  });
 
  it("should handle top level data in comments", async () => {
    const config = `
      <View>
        <Header value="Video timeline segmentation via Audio sync trick"/>
        <HyperText name="video" value="$video"/>
        <Labels name="tricks" toName="audio" choice="multiple">
          <Label value="Kickflip" background="#1BB500" />
          <Label value="360 Flip" background="#FFA91D" />
          <Label value="Trick" background="#358EF3" />
        </Labels>
        <Audio name="audio" value="$videoSource" speed="false"/>
      </View>
 
      <!--
        It's very important to prepare task data correctly,
        it includes HyperText $video and
        it must be like this example below:
      -->
 
      <!-- {
      "videoSource": "https://app.heartex.ai/static/samples/opossum_snow_alt.mp4"
      } -->
    `;
    const result = await generateSampleTaskFromConfig(config);
    expect(result.data).toHaveProperty("videoSource");
    expect(result.data.videoSource).toBe("https://app.heartex.ai/static/samples/opossum_snow_alt.mp4");
  });
});