import {spatialAnalystService} from '../../../src/leaflet/services/SpatialAnalystService';
import {GenerateSpatialDataParameters} from '../../../src/common/iServer/GenerateSpatialDataParameters';
import {DataReturnOption} from '../../../src/common/iServer/DataReturnOption';
import {DataReturnMode} from '../../../src/common/REST';
import request from 'request';

var spatialAnalystURL = GlobeParameter.spatialAnalystURL_Changchun;
var options = {
    serverType: 'iServer'
};

describe('leaflet_SpatialAnalystService_generateSpatialData', () => {
    var serviceResult;
    var originalTimeout;
    beforeEach(() => {
        originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
        jasmine.DEFAULT_TIMEOUT_INTERVAL = 50000;
        serviceResult = null;
    });
    afterEach(() => {
        jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
    });

    var resultDataset = "GenerateSpatialData_leafletTest";
    it('generateSpatialData', (done) => {
        var generateSpatialDataParameters = new GenerateSpatialDataParameters({
            routeTable: "RouteDT_road@Changchun",
            routeIDField: "RouteID",
            eventTable: "LinearEventTabDT@Changchun",
            eventRouteIDField: "RouteID",
            measureField: "",
            measureStartField: "LineMeasureFrom",
            measureEndField: "LineMeasureTo",
            measureOffsetField: "",
            errorInfoField: "",
            dataReturnOption: new DataReturnOption({
                expectCount: 1000,
                dataset: resultDataset,
                deleteExistResultDataset: true,
                dataReturnMode: DataReturnMode.DATASET_ONLY
            })
        });
        var generateSpatialDataService = spatialAnalystService(spatialAnalystURL, options);
        generateSpatialDataService.generateSpatialData(generateSpatialDataParameters, (result) => {
            serviceResult = result;

        });
        setTimeout(() => {
            try {
                expect(generateSpatialDataService).not.toBeNull();
                expect(generateSpatialDataService.options.serverType).toBe('iServer');
                expect(serviceResult).not.toBeNull();
                expect(serviceResult.type).toEqual("processCompleted");
                expect(serviceResult.result).not.toBeNull();
                expect(serviceResult.result.succeed).toBe(true);
                expect(serviceResult.result.dataset).toEqual(resultDataset + "@Changchun");
                generateSpatialDataService.destroy();
                done();
            } catch (exception) {
                console.log("'generateSpatialData_test'案例失败" + exception.name + ":" + exception.message);
                generateSpatialDataService.destroy();
                expect(false).toBeTruthy();
                done();
            }
        }, 5000);
    });

    // 删除测试过程中产生的测试数据集
    it('delete test resources', (done) => {
        var testResult = GlobeParameter.datachangchunURL + resultDataset;
        request.delete(testResult);
        done();
    });
});
@@ -355,16 +355,71 @@
 equest';
+%0Aimport %7BFetchRequest%7D from %22@supermap/iclient-common%22;
 %0A%0Avar sp
@@ -1819,16 +1819,1098 @@
 tions);%0A
+        spyOn(FetchRequest, 'commit').and.callFake((method, testUrl, params, options) =%3E %7B%0A            expect(method).toBe(%22POST%22);%0A            expect(testUrl).toBe(spatialAnalystURL + %22/datasets/RouteDT_road@Changchun/linearreferencing/generatespatialdata.json?returnContent=true%22);%0A            var expectParams = %60%7B'routeTable':%22RouteDT_road@Changchun%22,'routeIDField':%22RouteID%22,'attributeFilter':null,'eventTable':%22LinearEventTabDT@Changchun%22,'eventRouteIDField':%22RouteID%22,'measureField':%22%22,'measureStartField':%22LineMeasureFrom%22,'measureEndField':%22LineMeasureTo%22,'measureOffsetField':%22%22,'errorInfoField':%22%22,'retainedFields':null,'dataReturnOption':%7B'expectCount':1000,'dataset':%22GenerateSpatialData_leafletTest%22,'dataReturnMode':%22DATASET_ONLY%22,'deleteExistResultDataset':true%7D%7D%60;%0A            expect(params).toBe(expectParams);%0A            expect(options).not.toBeNull();%0A            var resultJSON = %60%7B%22succeed%22:true,%22recordset%22:null,%22message%22:null,%22dataset%22:%22GenerateSpatialData_leafletTest@Changchun%22%7D%60;%0A            return Promise.resolve(new Response(resultJSON));%0A        %7D);%0A
         
@@ -3497,13 +3497,15 @@
 toBe
-(true
+Truthy(
 );%0A 
@@ -3949,16 +3949,16 @@
       %7D%0A
+
         
@@ -3978,210 +3978,8 @@
  %7D);
-%0A%0A    // %E5%88%A0%E9%99%A4%E6%B5%8B%E8%AF%95%E8%BF%87%E7%A8%8B%E4%B8%AD%E4%BA%A7%E7%94%9F%E7%9A%84%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE%E9%9B%86%0A    it('delete test resources', (done) =%3E %7B%0A        var testResult = GlobeParameter.datachangchunURL + resultDataset;%0A        request.delete(testResult);%0A        done();%0A    %7D);
 %0A%7D);

优化空间分析的动态分析测试案例，将其改为真实请求改为mork review by sunxiaoyu