Skip to content

Commit

Permalink
add ut
Browse files Browse the repository at this point in the history
  • Loading branch information
shallowdream218 committed Mar 28, 2024
1 parent 9fb4aad commit a2084ad
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 3 deletions.
20 changes: 20 additions & 0 deletions test/common/iServer/AttachmentsParametersSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AttachmentsParameters } from '../../../src/common/iServer';
describe('AttachmentsParameters', () => {
it('constructor destroy', () => {
var option = {
dataSourceName: 'testDataSourceName',
dataSetName: 'testDataSetName',
featureId: '1',
};
var parametersNull = new AttachmentsParameters();
expect(parametersNull).not.toBeNull();
var parameter = new AttachmentsParameters(option);
expect(parameter.dataSourceName).toEqual('testDataSourceName');
expect(parameter.dataSetName).toEqual('testDataSetName');
expect(parameter.featureId).toEqual('1');
parameter.destroy();
expect(parameter.dataSourceName).toBeNull();
expect(parameter.dataSetName).toBeNull();
expect(parameter.featureId).toBeNull();
});
});
20 changes: 20 additions & 0 deletions test/common/iServer/EditAttachmentsParametersSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { EditAttachmentsParameters } from '../../../src/common/iServer';
describe('EditAttachmentsParameters', () => {
it('constructor destroy', () => {
var option = {
file: new File(['file1 contents'], 'file1.txt', { type: 'text/plain' }),
IDs: [1,2],
editType: 'ADD',
};
var parametersNull = new EditAttachmentsParameters();
expect(parametersNull).not.toBeNull();
var parameter = new EditAttachmentsParameters(option);
expect(parameter.file).not.toBeNull();
expect(parameter.IDs).toEqual([1,2]);
expect(parameter.editType).toEqual('ADD');
parameter.destroy();
expect(parameter.file).toBeNull();
expect(parameter.IDs).toBeNull();
expect(parameter.editType).toBeNull();
});
});
55 changes: 55 additions & 0 deletions test/leaflet/services/EditFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { FeatureService } from '../../../src/leaflet/services/FeatureService';
import { EditAttachmentsParameters } from '../../../src/common/iServer/EditAttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('leaflet_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
});
var editFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
editFeatureAttachmentsService.editFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters and add a file', done => {
let file = new File(['file1 contents'], 'file1.txt', { type: 'text/plain' });
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
file:file
});
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(params.get('file') instanceof File).toBeTruthy();
expect(method).toEqual('POST');
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
expect(params).not.toBeNull();
expect(options).not.toBeNull();
return Promise.resolve(
new Response(`{"size":56,"name":"1.txt","id":-1403040659,"contentType":"text/plain"}`)
)
})
myService.editFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.succeed).toBeTruthy();
expect(serviceResult.result.name).toBe('1.txt');
expect(serviceResult.result.contentType).toBe('text/plain');
expect(serviceResult.result.size).toBe(56);
done();
});
})
});
47 changes: 47 additions & 0 deletions test/leaflet/services/GetFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FeatureService } from '../../../src/leaflet/services/FeatureService';
import { AttachmentsParameters } from '../../../src/common/iServer/AttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('leaflet_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World"
});
var getFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
getFeatureAttachmentsService.getFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
});
let resInfo = [{ "size": 56, "name": "1.txt", "id": 1966180689, "contentType": "text/plain" }, { "size": 34991, "name": "test.png", "id": 1590279732, "contentType": "image/png" }];
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(method).toEqual('GET');
expect(params).toBeUndefined();
expect(options).not.toBeNull();
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
return Promise.resolve(new Response(JSON.stringify(resInfo)));
})
myService.getFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.length).toBe(2);
done();
});
})
});
55 changes: 55 additions & 0 deletions test/mapboxgl/services/EditFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { FeatureService } from '../../../src/mapboxgl/services/FeatureService';
import { EditAttachmentsParameters } from '../../../src/common/iServer/EditAttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('mapboxgl_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
});
var editFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
editFeatureAttachmentsService.editFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters and add a file', done => {
let file = new File(['file1 contents'], 'file1.txt', { type: 'text/plain' });
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
file:file
});
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(params.get('file') instanceof File).toBeTruthy();
expect(method).toEqual('POST');
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
expect(params).not.toBeNull();
expect(options).not.toBeNull();
return Promise.resolve(
new Response(`{"size":56,"name":"1.txt","id":-1403040659,"contentType":"text/plain"}`)
)
})
myService.editFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.succeed).toBeTruthy();
expect(serviceResult.result.name).toBe('1.txt');
expect(serviceResult.result.contentType).toBe('text/plain');
expect(serviceResult.result.size).toBe(56);
done();
});
})
});
47 changes: 47 additions & 0 deletions test/mapboxgl/services/GetFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FeatureService } from '../../../src/mapboxgl/services/FeatureService';
import { AttachmentsParameters } from '../../../src/common/iServer/AttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('mapboxgl_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World"
});
var getFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
getFeatureAttachmentsService.getFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
});
let resInfo = [{ "size": 56, "name": "1.txt", "id": 1966180689, "contentType": "text/plain" }, { "size": 34991, "name": "test.png", "id": 1590279732, "contentType": "image/png" }];
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(method).toEqual('GET');
expect(params).toBeUndefined();
expect(options).not.toBeNull();
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
return Promise.resolve(new Response(JSON.stringify(resInfo)));
})
myService.getFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.length).toBe(2);
done();
});
})
});
55 changes: 55 additions & 0 deletions test/maplibregl/services/EditFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { FeatureService } from '../../../src/maplibregl/services/FeatureService';
import { EditAttachmentsParameters } from '../../../src/common/iServer/EditAttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('maplibregl_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
});
var editFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
editFeatureAttachmentsService.editFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters and add a file', done => {
let file = new File(['file1 contents'], 'file1.txt', { type: 'text/plain' });
let params = new EditAttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
file:file
});
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(params.get('file') instanceof File).toBeTruthy();
expect(method).toEqual('POST');
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
expect(params).not.toBeNull();
expect(options).not.toBeNull();
return Promise.resolve(
new Response(`{"size":56,"name":"1.txt","id":-1403040659,"contentType":"text/plain"}`)
)
})
myService.editFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.succeed).toBeTruthy();
expect(serviceResult.result.name).toBe('1.txt');
expect(serviceResult.result.contentType).toBe('text/plain');
expect(serviceResult.result.size).toBe(56);
done();
});
})
});
47 changes: 47 additions & 0 deletions test/maplibregl/services/GetFeatureAttachmentsSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FeatureService } from '../../../src/maplibregl/services/FeatureService';
import { AttachmentsParameters } from '../../../src/common/iServer/AttachmentsParameters';
import { FetchRequest } from '../../../src/common/util/FetchRequest';

var url = GlobeParameter.dataServiceURL;
describe('maplibregl_GetFeatureAttachments', () => {
var originalTimeout;
beforeEach(() => {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
});
afterEach(() => {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it('incomplete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World"
});
var getFeatureAttachmentsService = new FeatureService(url, {});
spyOn(FetchRequest, 'commit');
getFeatureAttachmentsService.getFeatureAttachments(params);
expect(FetchRequest.commit).not.toHaveBeenCalled();
done();
});
it('complete parameters', done => {
let params = new AttachmentsParameters({
dataSourceName: "World",
dataSetName: "Countries",
featureId: 1,
});
let resInfo = [{ "size": 56, "name": "1.txt", "id": 1966180689, "contentType": "text/plain" }, { "size": 34991, "name": "test.png", "id": 1590279732, "contentType": "image/png" }];
let myService = new FeatureService(url)
spyOn(FetchRequest, 'commit').and.callFake((method, url, params, options) => {
expect(method).toEqual('GET');
expect(params).toBeUndefined();
expect(options).not.toBeNull();
expect(url).toEqual('http://localhost:9876/iserver/services/data-world/rest/data/datasources/World/datasets/Countries/features/1/attachments');
return Promise.resolve(new Response(JSON.stringify(resInfo)));
})
myService.getFeatureAttachments(params).then(res => {
let serviceResult = res;
expect(serviceResult.result.length).toBe(2);
done();
});
})
});
Loading

0 comments on commit a2084ad

Please sign in to comment.