yzt
2023-05-05 634ab285812bcc3eb802cacb9ec54f489bc2728f
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
import {
  MetadataClass,
  MetadataComponentType,
  MetadataEnum,
  MetadataType,
} from "../../Source/Cesium.js";
 
describe("Scene/MetadataClass", function () {
  it("creates class with default values", function () {
    var buildingClass = new MetadataClass({
      id: "building",
      class: {},
    });
 
    expect(buildingClass.id).toBe("building");
    expect(buildingClass.properties).toEqual({});
    expect(buildingClass.propertiesBySemantic).toEqual({});
    expect(buildingClass.name).toBeUndefined();
    expect(buildingClass.description).toBeUndefined();
    expect(buildingClass.extras).toBeUndefined();
    expect(buildingClass.extensions).toBeUndefined();
  });
 
  it("creates class", function () {
    var extras = {
      cityInfo: {
        name: "city",
      },
    };
    var extensions = {
      EXT_other_extension: {},
    };
 
    var buildingClass = new MetadataClass({
      id: "building",
      class: {
        name: "Building",
        description: "Building Class",
        extras: extras,
        extensions: extensions,
        properties: {
          height: {
            componentType: "FLOAT32",
          },
          position: {
            type: "ARRAY",
            componentType: "FLOAT32",
            componentCount: 3,
            semantic: "_POSITION",
          },
          color: {
            componentType: "STRING",
            semantic: "_COLOR",
          },
        },
      },
    });
 
    expect(buildingClass.id).toBe("building");
    expect(buildingClass.name).toBe("Building");
    expect(buildingClass.description).toBe("Building Class");
    expect(buildingClass.extras).toBe(extras);
    expect(buildingClass.extensions).toBe(extensions);
 
    var properties = buildingClass.properties;
    var heightProperty = properties.height;
    var positionProperty = properties.position;
    var colorProperty = properties.color;
 
    expect(heightProperty.type).toBe(MetadataType.SINGLE);
    expect(heightProperty.componentType).toBe(MetadataComponentType.FLOAT32);
    expect(positionProperty.type).toBe(MetadataType.ARRAY);
    expect(positionProperty.componentType).toBe(MetadataComponentType.FLOAT32);
    expect(colorProperty.type).toBe(MetadataType.SINGLE);
    expect(colorProperty.componentType).toBe(MetadataComponentType.STRING);
    expect(Object.keys(properties).sort()).toEqual([
      "color",
      "height",
      "position",
    ]);
 
    var propertiesBySemantic = buildingClass.propertiesBySemantic;
    expect(propertiesBySemantic._COLOR).toBe(colorProperty);
    expect(propertiesBySemantic._POSITION).toBe(positionProperty);
    expect(Object.keys(propertiesBySemantic).sort()).toEqual([
      "_COLOR",
      "_POSITION",
    ]);
  });
 
  it("creates class with enum property", function () {
    var colorEnum = new MetadataEnum({
      id: "color",
      enum: {
        values: [
          {
            name: "RED",
            value: 0,
          },
        ],
      },
    });
 
    var enums = {
      color: colorEnum,
    };
 
    var buildingClass = new MetadataClass({
      id: "building",
      class: {
        properties: {
          color: {
            componentType: "ENUM",
            enumType: "color",
          },
        },
      },
      enums: enums,
    });
 
    expect(buildingClass.properties.color.type).toBe(MetadataType.SINGLE);
    expect(buildingClass.properties.color.componentType).toBe(
      MetadataComponentType.ENUM
    );
    expect(buildingClass.properties.color.enumType).toBe(colorEnum);
  });
 
  it("constructor throws without id", function () {
    expect(function () {
      return new MetadataClass({
        class: {},
      });
    }).toThrowDeveloperError();
  });
 
  it("constructor throws without class", function () {
    expect(function () {
      return new MetadataClass({
        id: "classId",
      });
    }).toThrowDeveloperError();
  });
});