test: add scene test

This commit is contained in:
thinkinggis 2020-03-07 21:04:59 +08:00
parent 541e00f45e
commit b76498a868
2 changed files with 3 additions and 148 deletions

View File

@ -1,144 +0,0 @@
import { Container } from 'inversify';
import 'reflect-metadata';
import { TYPES } from '../../../index';
import GlobalConfigService from '../ConfigService';
import { IGlobalConfigService } from '../IConfigService';
describe('ConfigService', () => {
let container: Container;
let configService: IGlobalConfigService;
beforeAll(() => {
container = new Container();
container
.bind<IGlobalConfigService>(TYPES.IGlobalConfigService)
.to(GlobalConfigService);
configService = container.get<IGlobalConfigService>(
TYPES.IGlobalConfigService,
);
});
afterAll(() => {
container.unbind(TYPES.IGlobalConfigService);
});
it("should validate scene's options according to JSON schema", () => {
const { valid, errorText } = configService.validateSceneConfig({
id: 0,
});
expect(valid).toBeFalsy();
expect(errorText).toMatch('id should be string');
expect(
configService.validateSceneConfig({
id: 'map',
}).valid,
).toBeTruthy();
});
it("should validate map's `zoom` option", () => {
const { valid, errorText } = configService.validateMapConfig({
zoom: 100,
minZoom: 100,
maxZoom: -2,
});
expect(valid).toBeFalsy();
expect(errorText).toMatch('zoom should be <= 24');
expect(errorText).toMatch('minZoom should be <= 24');
expect(errorText).toMatch('maxZoom should be >= -1');
expect(
configService.validateMapConfig({
zoom: 10,
minZoom: 1,
maxZoom: 15,
}).valid,
).toBeTruthy();
});
it("should validate map's `pitch` option", () => {
const { valid, errorText } = configService.validateMapConfig({
pitch: '1',
});
expect(valid).toBeFalsy();
expect(errorText).toMatch('pitch should be number');
expect(
configService.validateMapConfig({
pitch: 10,
}).valid,
).toBeTruthy();
});
it("should validate map's `center` option", () => {
const { valid, errorText } = configService.validateMapConfig({
center: [1, 2, 3],
});
expect(valid).toBeFalsy();
expect(errorText).toMatch('center should NOT have more than 2 items');
const { valid: v2, errorText: e2 } = configService.validateMapConfig({
center: [1],
});
expect(v2).toBeFalsy();
expect(e2).toMatch('center should NOT have fewer than 2 items');
const { valid: v3, errorText: e3 } = configService.validateMapConfig({
center: 100,
});
expect(v3).toBeFalsy();
expect(e3).toMatch('center should be array');
expect(
configService.validateMapConfig({
center: [100, 100],
}).valid,
).toBeTruthy();
});
it("should validate layer's options according to JSON schema", () => {
configService.registerLayerConfigSchemaValidator('testLayer', {
properties: {
opacity: {
type: 'number',
minimum: 0,
maximum: 1,
},
enablePicking: {
type: 'boolean',
},
},
});
const { valid, errorText } = configService.validateLayerConfig(
'testLayer',
{ opacity: 'invalid' },
);
expect(valid).toBeFalsy();
expect(errorText).toMatch('opacity should be number');
expect(
configService.validateLayerConfig('testLayer', {
opacity: 1.5,
}).valid,
).toBeFalsy();
expect(
configService.validateLayerConfig('testLayer', {
enablePicking: 1.5,
}).valid,
).toBeFalsy();
expect(
configService.validateLayerConfig('testLayer', {
opacity: 1.0,
}).valid,
).toBeTruthy();
expect(
configService.validateLayerConfig('testLayer', {
opacity: 0.0,
}).valid,
).toBeTruthy();
});
});

View File

@ -24,10 +24,9 @@ describe('template', () => {
expect(center.lng).toEqual(110.19382669582967);
expect(center.lat).toEqual(30.258134);
expect(scene.getRotation()).toEqual(-0);
expect(scene.getBounds()).toEqual([
[88.22117044582802, 9.751305353647084],
[132.1664829458271, 47.2486735705956],
]);
expect(scene.getBounds()[0].map((v) => v.toFixed(5))).toEqual(
[88.22117044582802, 9.751305353647084].map((v) => v.toFixed(5)),
);
scene.setZoom(5);
expect(scene.getZoom()).toEqual(5);
scene.setPitch(5);