Skip to content

Commit 278e3a1

Browse files
committed
【ut】add UT
1 parent 68fbe61 commit 278e3a1

File tree

3 files changed

+206
-1
lines changed

3 files changed

+206
-1
lines changed

test/common/iServer/ImageCollectionServiceSpec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ImageRenderingRule } from '../../../src/commoniServer/ImageRenderingRule';
1+
import { ImageRenderingRule } from '../../../src/common/iServer/ImageRenderingRule';
22
import { ImageCollectionService } from '../../../src/common/iServer/ImageCollectionService';
33
import { FetchRequest } from '../../../src/common/util/FetchRequest';
44

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import {ServerTheme} from '../../../src/common/iServer/ServerTheme';
2+
import {ThemeLabel} from '../../../src/common/iServer/ThemeLabel';
3+
import {ThemeUnique} from '../../../src/common/iServer/ThemeUnique';
4+
import {ThemeGraph} from '../../../src/common/iServer/ThemeGraph';
5+
import {ThemeDotDensity} from '../../../src/common/iServer/ThemeDotDensity';
6+
import {ThemeGraduatedSymbol} from '../../../src/common/iServer/ThemeGraduatedSymbol';
7+
import {ThemeRange} from '../../../src/common/iServer/ThemeRange';
8+
import {LonLat} from '../../../src/common/commontypes/LonLat';
9+
10+
describe('ServerTheme', () => {
11+
it('constructor', () => {
12+
var serverTheme = new ServerTheme();
13+
expect(serverTheme).not.toBeNull();
14+
expect(serverTheme.CLASS_NAME).toEqual("SuperMap.ServerTheme");
15+
expect(serverTheme.theme).toBeNull();
16+
expect(serverTheme.themeElementPosition).toBeNull();
17+
18+
var options = {
19+
theme: {type: 'LABEL'},
20+
themeElementPosition: new LonLat(30, 45)
21+
};
22+
var serverTheme2 = new ServerTheme(options);
23+
expect(serverTheme2.theme).not.toBeNull();
24+
expect(serverTheme2.themeElementPosition).not.toBeNull();
25+
});
26+
27+
it('destroy', () => {
28+
var serverTheme = new ServerTheme({
29+
theme: {type: 'LABEL'},
30+
themeElementPosition: new LonLat(30, 45)
31+
});
32+
expect(serverTheme.theme).not.toBeNull();
33+
expect(serverTheme.themeElementPosition).not.toBeNull();
34+
35+
serverTheme.destroy();
36+
expect(serverTheme.theme).toBeNull();
37+
expect(serverTheme.themeElementPosition).toBeNull();
38+
});
39+
40+
it('fromJson_with_label_theme', () => {
41+
var jsonObject = {
42+
theme: {
43+
type: 'LABEL'
44+
},
45+
themeElementPosition: {
46+
x: 30,
47+
y: 45
48+
}
49+
};
50+
spyOn(ThemeLabel, 'fromObj').and.returnValue(new ThemeLabel());
51+
52+
var serverTheme = new ServerTheme();
53+
serverTheme.fromJson(jsonObject);
54+
55+
expect(serverTheme.theme).not.toBeNull();
56+
expect(serverTheme.theme instanceof ThemeLabel).toBeTruthy();
57+
expect(serverTheme.themeElementPosition).not.toBeNull();
58+
expect(serverTheme.themeElementPosition instanceof LonLat).toBeTruthy();
59+
expect(serverTheme.themeElementPosition.lon).toEqual(30);
60+
expect(serverTheme.themeElementPosition.lat).toEqual(45);
61+
});
62+
63+
it('fromJson_with_unique_theme', () => {
64+
var jsonObject = {
65+
theme: {
66+
type: 'UNIQUE'
67+
}
68+
};
69+
spyOn(ThemeUnique, 'fromObj').and.returnValue(new ThemeUnique());
70+
71+
var serverTheme = new ServerTheme();
72+
serverTheme.fromJson(jsonObject);
73+
74+
expect(serverTheme.theme).not.toBeNull();
75+
expect(serverTheme.theme instanceof ThemeUnique).toBeTruthy();
76+
});
77+
78+
it('fromJson_with_graph_theme', () => {
79+
var jsonObject = {
80+
theme: {
81+
type: 'GRAPH'
82+
}
83+
};
84+
spyOn(ThemeGraph, 'fromObj').and.returnValue(new ThemeGraph());
85+
86+
var serverTheme = new ServerTheme();
87+
serverTheme.fromJson(jsonObject);
88+
89+
expect(serverTheme.theme).not.toBeNull();
90+
expect(serverTheme.theme instanceof ThemeGraph).toBeTruthy();
91+
});
92+
93+
it('fromJson_with_dotdensity_theme', () => {
94+
var jsonObject = {
95+
theme: {
96+
type: 'DOTDENSITY'
97+
}
98+
};
99+
spyOn(ThemeDotDensity, 'fromObj').and.returnValue(new ThemeDotDensity());
100+
101+
var serverTheme = new ServerTheme();
102+
serverTheme.fromJson(jsonObject);
103+
104+
expect(serverTheme.theme).not.toBeNull();
105+
expect(serverTheme.theme instanceof ThemeDotDensity).toBeTruthy();
106+
});
107+
108+
it('fromJson_with_graduatedsymbol_theme', () => {
109+
var jsonObject = {
110+
theme: {
111+
type: 'GRADUATEDSYMBOL'
112+
}
113+
};
114+
spyOn(ThemeGraduatedSymbol, 'fromObj').and.returnValue(new ThemeGraduatedSymbol());
115+
116+
var serverTheme = new ServerTheme();
117+
serverTheme.fromJson(jsonObject);
118+
119+
expect(serverTheme.theme).not.toBeNull();
120+
expect(serverTheme.theme instanceof ThemeGraduatedSymbol).toBeTruthy();
121+
});
122+
123+
it('fromJson_with_range_theme', () => {
124+
var jsonObject = {
125+
theme: {
126+
type: 'RANGE'
127+
}
128+
};
129+
spyOn(ThemeRange, 'fromObj').and.returnValue(new ThemeRange());
130+
131+
var serverTheme = new ServerTheme();
132+
serverTheme.fromJson(jsonObject);
133+
134+
expect(serverTheme.theme).not.toBeNull();
135+
expect(serverTheme.theme instanceof ThemeRange).toBeTruthy();
136+
});
137+
138+
it('fromJson_with_unknown_theme', () => {
139+
var jsonObject = {
140+
theme: {
141+
type: 'UNKNOWN'
142+
}
143+
};
144+
145+
var serverTheme = new ServerTheme();
146+
serverTheme.fromJson(jsonObject);
147+
148+
expect(serverTheme.theme).not.toBeNull();
149+
expect(serverTheme.theme.type).toEqual('UNKNOWN');
150+
});
151+
152+
it('fromJson_without_theme', () => {
153+
var jsonObject = {
154+
themeElementPosition: {
155+
x: 30,
156+
y: 45
157+
}
158+
};
159+
160+
var serverTheme = new ServerTheme();
161+
serverTheme.fromJson(jsonObject);
162+
163+
expect(serverTheme.theme).toBeNull();
164+
expect(serverTheme.themeElementPosition).not.toBeNull();
165+
expect(serverTheme.themeElementPosition instanceof LonLat).toBeTruthy();
166+
});
167+
168+
it('toServerJSONObject', () => {
169+
// 创建具有toServerJSONObject方法的对象
170+
var position = new LonLat(30, 45);
171+
position.toServerJSONObject = jasmine.createSpy('toServerJSONObject').and.returnValue({x: 30, y: 45});
172+
173+
// 创建具有toServerJSONObject方法的主题对象
174+
var theme = new ThemeLabel();
175+
theme.toServerJSONObject = jasmine.createSpy('toServerJSONObject').and.returnValue({type: 'LABEL'});
176+
177+
var serverTheme = new ServerTheme({
178+
theme: theme,
179+
themeElementPosition: position
180+
});
181+
182+
var jsonObject = serverTheme.toServerJSONObject();
183+
expect(jsonObject.theme).not.toBeNull();
184+
expect(jsonObject.theme.type).toEqual('LABEL');
185+
expect(jsonObject.themeElementPosition).not.toBeNull();
186+
expect(jsonObject.themeElementPosition.x).toEqual(30);
187+
expect(jsonObject.themeElementPosition.y).toEqual(45);
188+
});
189+
190+
it('toServerJSONObject_without_special_methods', () => {
191+
// 测试themeElementPosition和theme没有toServerJSONObject方法的情况
192+
var position = {x: 30, y: 45};
193+
var theme = {type: 'LABEL'};
194+
195+
var serverTheme = new ServerTheme({
196+
theme: theme,
197+
themeElementPosition: position
198+
});
199+
200+
var jsonObject = serverTheme.toServerJSONObject();
201+
expect(jsonObject.theme).toEqual(theme);
202+
expect(jsonObject.themeElementPosition).toEqual(position);
203+
});
204+
});

test/test-main-common.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ import './common/iServer/ImageStretchOptionSpec';
120120
import './common/iServer/CompatibleSpec.js';
121121
import './common/iServer/AttachmentsParametersSpec.js';
122122
import './common/iServer/EditAttachmentsParametersSpec.js';
123+
import './common/iServer/ServerThemeSpec.js';
123124
/**common -- control**/
124125
import './common/control/TimeControlBaseSpec.js';
125126
import './common/control/TimeFlowControlSpec.js';

0 commit comments

Comments
 (0)