Bin
2025-12-17 21f0498f62ada55651f4d232327e15fc47f498b1
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
/* global it, expect */
import Tree from "../Tree";
import "../../tags/object/Image";
import "../../tags/object/RichText";
import "../../tags/control/RectangleLabels";
import "../../tags/control/Label";
import "../../tags/control/Choices";
import "../../tags/control/Choice";
import "../../tags/visual/Header";
import { ConfigValidator } from "../DataValidator/ConfigValidator";
 
it("Should fail if a tag referenced by toName doesn't exist", () => {
  const result = ConfigValidator.validate(
    Tree.treeToModel(
      `
  <View>
    <Image name="img1" value="$image"></Image>
    <RectangleLabels name="tag" toName="img" fillOpacity="0.5" strokeWidth="5">
      <Label value="Planet"></Label>
      <Label value="Moonwalker" background="blue"></Label>
    </RectangleLabels>
  </View>
  `,
      {},
    ),
  );
 
  expect(result[0].error).toBe("ERR_TAG_NOT_FOUND");
});
 
it("Should fail if a tag referenced by toName is not image", () => {
  const result = ConfigValidator.validate(
    Tree.treeToModel(
      `
  <View>
    <HyperText name="img" value="$text"></HyperText>
    <RectangleLabels name="tag" toName="img" fillOpacity="0.5" strokeWidth="5">
      <Label value="Planet"></Label>
      <Label value="Moonwalker" background="blue"></Label>
    </RectangleLabels>
  </View>
  `,
      {},
    ),
  );
 
  expect(result[0].error).toBe("ERR_TAG_UNSUPPORTED");
});
 
it.skip("Should fail if tag lacks mandatory attribute toName", () => {
  const result = Tree.treeToModel(`
  <View>
    <Image name="img" value="$image"></Image>
    <RectangleLabels name="tag" fillOpacity="0.5" strokeWidth="5">
      <Label value="Planet"></Label>
      <Label value="Moonwalker" background="blue"></Label>
    </RectangleLabels>
  </View>
  `);
 
  const errorItem = result.validation[0];
 
  expect(errorItem.error).toBe("ERR_REQUIRED");
});
 
it("Should fail if opacity attribute is out of range", () => {
  const result = ConfigValidator.validate(
    Tree.treeToModel(
      `
  <View>
    <Image name="img" value="$image"></Image>
    <RectangleLabels name="tag" toName="img" fillOpacity="-1" strokeWidth="5">
      <Label value="Planet"></Label>
      <Label value="Moonwalker" background="blue"></Label>
    </RectangleLabels>
  </View>
  `,
      {},
    ),
  );
 
  expect(result[0].error).toBe("ERR_BAD_TYPE");
});
 
it("Should fail if color is not a proper CSS color", () => {
  const result = ConfigValidator.validate(
    Tree.treeToModel(
      `
  <View>
    <Image name="img" value="$image"></Image>
    <RectangleLabels name="tag" toName="img" fillOpacity="0.6" strokeWidth="5">
      <Label value="Planet"></Label>
      <Label value="Moonwalker" background="verywrongcolor"></Label>
    </RectangleLabels>
  </View>
  `,
      {},
    ),
  );
 
  expect(result[0].error).toBe("ERR_BAD_TYPE");
});
 
it.skip("Should fail if visual tags have name attribute", () => {
  const result = ConfigValidator.validate(
    Tree.treeToModel(
      `
    <View>
      <Header name="w3"/>
      <Text name="text1" value="Did the agent follow up to ensure that both parties were satisfied with the outcome and understood the resolution"/>
      <Image name="image" value="$image" zoom="true"/>
      <Choices name="choice" toName="label" choice="single">
        <Choice value="Yes"/>
        <Choice value="No"/>
      </Choices>
      <PolygonLabels name="label" toName="image"
                     strokeWidth="3" pointSize="small"
                     opacity="0.9">
        <Label value="Airplane" background="red"/>
        <Label value="Car" background="blue"/>
      </PolygonLabels>
    </View>
  `,
      {},
    ),
  );
 
  expect(result[0].error).toBe("ERR_GENERAL");
  expect(result[0].value).toBe("Attribute <b>name</b> is not allowed for tag <b>Header</b>.");
});