From ae794bc61d3792f25e1010a9b5034a8fa9587b1b Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Tue, 27 Jun 2023 17:10:52 +0800 Subject: [PATCH 01/10] Initilize PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 src/test/PV_PREVIEW.test.ts diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts new file mode 100644 index 0000000..321ea4a --- /dev/null +++ b/src/test/PV_PREVIEW.test.ts @@ -0,0 +1,70 @@ +import { CARTA } from "carta-protobuf"; +import { checkConnection, Stream} from './myClient'; +import { MessageController } from "./MessageController"; +import config from "./config.json"; + +let testServerUrl: string = config.serverURL0; +let testSubdirectory: string = config.path.QA; +let connectTimeout: number = config.timeout.connection; +let openFileTimeout: number = config.timeout.openFile; + +interface AssertItem { + filelist: CARTA.IFileListRequest; + fileOpen: CARTA.IOpenFile[]; + addTilesReq: CARTA.IAddRequiredTiles[]; +}; + +let assertItem: AssertItem = { + filelist: { directory: testSubdirectory }, + fileOpen: [ + { + directory: testSubdirectory, + file: "HD163296_CO_2_1.fits", + hdu: "0", + fileId: 0, + renderMode: CARTA.RenderMode.RASTER, + }, + { + directory: testSubdirectory, + file: "HD163296_CO_2_1.image", + hdu: "0", + fileId: 0, + renderMode: CARTA.RenderMode.RASTER, + }, + { + directory: testSubdirectory, + file: "HD163296_CO_2_1.hdf5", + hdu: "0", + fileId: 1, + renderMode: CARTA.RenderMode.RASTER, + }, + ], + addTilesReq: [ + { + fileId: 0, + compressionQuality: 11, + compressionType: CARTA.CompressionType.ZFP, + tiles: [0], + }, + ], +}; + +let basepath: string; +describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", () => { + const msgController = MessageController.Instance; + describe(`Register a session`, () => { + beforeAll(async ()=> { + await msgController.connect(testServerUrl); + }, connectTimeout); + + checkConnection(); + test(`Get basepath`, async () => { + let fileListResponse = await msgController.getFileList("$BASE",0); + basepath = fileListResponse.directory; + for (let i=0; i msgController.closeConnection()); + }); +}); \ No newline at end of file From 28040c0358b5dfb0e28ff217d4b2e45369b461be Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Tue, 4 Jul 2023 17:19:31 +0800 Subject: [PATCH 02/10] finish Step 4 in PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 108 +++++++++++++++++++++++++++++++----- 1 file changed, 94 insertions(+), 14 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 321ea4a..b06e1f7 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -12,6 +12,9 @@ interface AssertItem { filelist: CARTA.IFileListRequest; fileOpen: CARTA.IOpenFile[]; addTilesReq: CARTA.IAddRequiredTiles[]; + setCursor: CARTA.ISetCursor[]; + setRegion: CARTA.ISetRegion[]; + setPVRequest: CARTA.IPvRequest[]; }; let assertItem: AssertItem = { @@ -35,7 +38,7 @@ let assertItem: AssertItem = { directory: testSubdirectory, file: "HD163296_CO_2_1.hdf5", hdu: "0", - fileId: 1, + fileId: 0, renderMode: CARTA.RenderMode.RASTER, }, ], @@ -47,24 +50,101 @@ let assertItem: AssertItem = { tiles: [0], }, ], + setCursor: [ + { + fileId: 0, + point: { x: 1, y: 1 }, + }, + ], + setRegion: [ + { + fileId: 0, + regionId: -1, + previewRegion: false, + regionInfo: { + regionType: CARTA.RegionType.LINE, + controlPoints: [{ x: 79, y: 77 }, { x: 362, y: 360 }], + rotation: 135, + } + }, + ], + setPVRequest: [ + { + fileId: 0, + regionId: 1, + width: 3, + keep: true, + reverse: false, + spectralRange: {min: 0, max: 249}, + previewSettings: { + animationCompressionQuality: 9, + compressionType: CARTA.CompressionType.ZFP, + imageCompressionQuality: 11, + previewId: 0, + rebinXy: 1, + rebinZ: 1, + regionId: -1, + } + } + ] }; let basepath: string; describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", () => { - const msgController = MessageController.Instance; - describe(`Register a session`, () => { - beforeAll(async ()=> { - await msgController.connect(testServerUrl); - }, connectTimeout); + for (let i=0; i { + const msgController = MessageController.Instance; + beforeAll(async ()=> { + await msgController.connect(testServerUrl); + }, connectTimeout); - checkConnection(); - test(`Get basepath`, async () => { - let fileListResponse = await msgController.getFileList("$BASE",0); - basepath = fileListResponse.directory; - for (let i=0; i { + let fileListResponse = await msgController.getFileList("$BASE",0); + basepath = fileListResponse.directory; assertItem.fileOpen[i].directory = basepath + "/" + assertItem.filelist.directory; - } + }); + + test(`(Step 1): Open image`, async () => { + msgController.closeFile(-1); + let OpenFileResponse = await msgController.loadFile(assertItem.fileOpen[i]); + let RegionHistogramData = await Stream(CARTA.RegionHistogramData,1); + + expect(OpenFileResponse.success).toEqual(true); + expect(OpenFileResponse.fileInfo.name).toEqual(assertItem.fileOpen[i].file); + expect(RegionHistogramData.length).toEqual(1); + }); + + test(`(Stpe 2): Set cursor and add required tiles`, async () => { + msgController.addRequiredTiles(assertItem.addTilesReq[0]); + let RasterTileDataResponse = await Stream(CARTA.RasterTileData,assertItem.addTilesReq[0].tiles.length + 2); + + msgController.setCursor(assertItem.setCursor[0].fileId, assertItem.setCursor[0].point.x, assertItem.setCursor[0].point.y); + let SpatialProfileDataResponse1 = await Stream(CARTA.SpatialProfileData,1); + }); + + test(`(Step 3): set region`, async () => { + let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[0].fileId, assertItem.setRegion[0].regionId, assertItem.setRegion[0].regionInfo); + expect(setRegionAckResponse.regionId).toEqual(1); + expect(setRegionAckResponse.success).toEqual(true); + }); + + let regionHistogramData = []; + test(`(Step 4): set PV request`, async () => { + let regionHistogramDataPromise = new Promise((resolve)=>{ + msgController.histogramStream.subscribe({ + next: (data) => { + regionHistogramData.push(data) + resolve(regionHistogramData) + } + }) + }); + let PVresponse = await msgController.requestPV(assertItem.setPVRequest[0]); + // console.log(PVresponse); + // console.log(regionHistogramDataPromise); + }); + + afterAll(() => msgController.closeConnection()); }); - afterAll(() => msgController.closeConnection()); - }); + } }); \ No newline at end of file From 497f4152c4a89a5ae122b3b429ee8e553052b7c6 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Wed, 5 Jul 2023 17:29:24 +0800 Subject: [PATCH 03/10] step 5 of PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 96 +++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 9 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index b06e1f7..827e62a 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -2,6 +2,7 @@ import { CARTA } from "carta-protobuf"; import { checkConnection, Stream} from './myClient'; import { MessageController } from "./MessageController"; import config from "./config.json"; +import exp from "constants"; let testServerUrl: string = config.serverURL0; let testSubdirectory: string = config.path.QA; @@ -15,6 +16,13 @@ interface AssertItem { setCursor: CARTA.ISetCursor[]; setRegion: CARTA.ISetRegion[]; setPVRequest: CARTA.IPvRequest[]; + pvResponse: CARTA.IPvResponse; + histogramBinsIndex: Number[]; + histogramBinsValue: Number[]; + imageDataIndex: Number[]; + imageDataValue: Number[]; + precisionDigits: number; + setSpatialReq: CARTA.ISetSpatialRequirements[]; }; let assertItem: AssertItem = { @@ -86,7 +94,47 @@ let assertItem: AssertItem = { regionId: -1, } } - ] + ], + pvResponse: { + success: true, + previewData: { + compressionQuality: 11, + compressionType: CARTA.CompressionType.ZFP, + height: 250, + width: 401, + histogram: { + binWidth: 0.0022617133799940348, + firstBinCenter: -0.04723597317934036, + mean: 0.004336727754377657, + numBins: 316, + stdDev: 0.040239019771367436, + }, + histogramBounds: { + max: 0.6663346290588379, + min: -0.04836682975292206, + }, + imageInfo: { + axesNumbers: { + spatialX: 1, + spectral: 2, + stokes: 3, + } + }, + nanEncodings: new Uint8Array([154, 135, 1, 0]), + }, + }, + histogramBinsIndex: [0, 100, 200, 300], + histogramBinsValue: [4, 8, 4, 1], + imageDataIndex: [0, 5000, 10000, 20000, 30000, 40000, 50000, 60000, 70000], + imageDataValue: [241, 69, 198, 204, 61, 200, 226, 216, 77], + precisionDigits: 8, + setSpatialReq: [ + { + fileId: -2, + regionId: 0, + spatialProfiles: [{coordinate:"x", mip:1, width: undefined}, {coordinate:"y", mip:1, width: undefined}] + } + ], }; let basepath: string; @@ -113,7 +161,7 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( expect(OpenFileResponse.success).toEqual(true); expect(OpenFileResponse.fileInfo.name).toEqual(assertItem.fileOpen[i].file); expect(RegionHistogramData.length).toEqual(1); - }); + }, openFileTimeout); test(`(Stpe 2): Set cursor and add required tiles`, async () => { msgController.addRequiredTiles(assertItem.addTilesReq[0]); @@ -129,19 +177,49 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( expect(setRegionAckResponse.success).toEqual(true); }); - let regionHistogramData = []; + let pVProgressData = []; test(`(Step 4): set PV request`, async () => { - let regionHistogramDataPromise = new Promise((resolve)=>{ - msgController.histogramStream.subscribe({ + let pvProgressPromise = new Promise((resolve)=>{ + msgController.pvProgressStream.subscribe({ next: (data) => { - regionHistogramData.push(data) - resolve(regionHistogramData) + pVProgressData.push(data) + resolve(pVProgressData) } }) }); let PVresponse = await msgController.requestPV(assertItem.setPVRequest[0]); - // console.log(PVresponse); - // console.log(regionHistogramDataPromise); + + expect(pVProgressData[pVProgressData.length-1].progress).toEqual(1); + expect(PVresponse.success).toEqual(assertItem.pvResponse.success); + expect(PVresponse.previewData.compressionQuality).toEqual(assertItem.pvResponse.previewData.compressionQuality); + expect(PVresponse.previewData.compressionType).toEqual(assertItem.pvResponse.previewData.compressionType); + expect(PVresponse.previewData.height).toEqual(assertItem.pvResponse.previewData.height); + expect(PVresponse.previewData.width).toEqual(assertItem.pvResponse.previewData.width); + expect(PVresponse.previewData.histogram.binWidth).toBeCloseTo(assertItem.pvResponse.previewData.histogram.binWidth, assertItem.precisionDigits); + assertItem.histogramBinsIndex.map((input, index) => { + expect(PVresponse.previewData.histogram.bins[input]).toEqual(assertItem.histogramBinsValue[index]); + }); + expect(PVresponse.previewData.histogram.firstBinCenter).toBeCloseTo(assertItem.pvResponse.previewData.histogram.firstBinCenter, assertItem.precisionDigits); + expect(PVresponse.previewData.histogram.mean).toBeCloseTo(assertItem.pvResponse.previewData.histogram.mean, assertItem.precisionDigits); + expect(PVresponse.previewData.histogram.numBins).toEqual(assertItem.pvResponse.previewData.histogram.numBins); + expect(PVresponse.previewData.histogram.stdDev).toBeCloseTo(assertItem.pvResponse.previewData.histogram.stdDev, assertItem.precisionDigits); + expect(PVresponse.previewData.histogramBounds.max).toBeCloseTo(assertItem.pvResponse.previewData.histogramBounds.max, assertItem.precisionDigits); + expect(PVresponse.previewData.histogramBounds.min).toBeCloseTo(assertItem.pvResponse.previewData.histogramBounds.min, assertItem.precisionDigits); + assertItem.imageDataIndex.map((input, index) => { + expect(PVresponse.previewData.imageData[input]).toEqual(assertItem.imageDataValue[index]); + }); + expect(PVresponse.previewData.imageInfo.axesNumbers.spatialX).toEqual(assertItem.pvResponse.previewData.imageInfo.axesNumbers.spatialX); + expect(PVresponse.previewData.imageInfo.axesNumbers.spectral).toEqual(assertItem.pvResponse.previewData.imageInfo.axesNumbers.spectral); + expect(PVresponse.previewData.imageInfo.axesNumbers.stokes).toEqual(assertItem.pvResponse.previewData.imageInfo.axesNumbers.stokes); + for (i=0; i { + msgController.setSpatialRequirements(assertItem.setSpatialReq[0]); + let ErrorResponse = await Stream(CARTA.ErrorData,1); + expect(ErrorResponse[0].message).toContain("File id -2 not found"); }); afterAll(() => msgController.closeConnection()); From dd2440a40e1aa6f927f538f3e0c9b7aba2aa3eb0 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Wed, 5 Jul 2023 17:41:19 +0800 Subject: [PATCH 04/10] step 6 in PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 827e62a..bf6b4a8 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -23,6 +23,7 @@ interface AssertItem { imageDataValue: Number[]; precisionDigits: number; setSpatialReq: CARTA.ISetSpatialRequirements[]; + closepvpreview: CARTA.IClosePvPreview; }; let assertItem: AssertItem = { @@ -135,6 +136,9 @@ let assertItem: AssertItem = { spatialProfiles: [{coordinate:"x", mip:1, width: undefined}, {coordinate:"y", mip:1, width: undefined}] } ], + closepvpreview: { + previewId: 0 + } }; let basepath: string; @@ -222,6 +226,16 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( expect(ErrorResponse[0].message).toContain("File id -2 not found"); }); + test(`(Step 6): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { + let receiveNumberCurrent = msgController.messageReceiving(); + msgController.closePvPreview(assertItem.closepvpreview.previewId); + setTimeout(() => { + let receiveNumberLatter = msgController.messageReceiving(); + expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Have received number is equal during 1000 ms + done(); + }, 1000) + }); + afterAll(() => msgController.closeConnection()); }); } From 4aa421d396eb0683a5b101989d7983b5498bbdc0 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Mon, 10 Jul 2023 15:49:20 +0800 Subject: [PATCH 05/10] finish Step 7 in PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 51 ++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index bf6b4a8..0a12210 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -24,6 +24,9 @@ interface AssertItem { precisionDigits: number; setSpatialReq: CARTA.ISetSpatialRequirements[]; closepvpreview: CARTA.IClosePvPreview; + spatialProfileDataResponse: CARTA.ISpatialProfileData; + spatialProfileDataRawValueIndex: Number[]; + spatialProfileDataRawValue: Number[]; }; let assertItem: AssertItem = { @@ -134,11 +137,34 @@ let assertItem: AssertItem = { fileId: -2, regionId: 0, spatialProfiles: [{coordinate:"x", mip:1, width: undefined}, {coordinate:"y", mip:1, width: undefined}] - } + }, + { + fileId: -2, + regionId: 0, + spatialProfiles: [] + }, + { + fileId: 0, + regionId: 1, + spatialProfiles: [{coordinate: "", mip: 1, width: 3}] + }, ], closepvpreview: { previewId: 0 - } + }, + spatialProfileDataResponse: { + regionId: 1, + profiles: [{ + end: 400, + lineAxis: { + cdelt: 0.05000000074505806, + crpix: 200, + unit: "arcsec" + } + }] + }, + spatialProfileDataRawValueIndex: [0,500,1000,1500, 1603], + spatialProfileDataRawValue: [152, 10, 220, 106, 186], }; let basepath: string; @@ -231,11 +257,30 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( msgController.closePvPreview(assertItem.closepvpreview.previewId); setTimeout(() => { let receiveNumberLatter = msgController.messageReceiving(); - expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Have received number is equal during 1000 ms + expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Received the number is equal during 1000 ms done(); }, 1000) }); + test(`(Step 7): the SET_SPATIAL_REQUIREMENTS of frontend after closing the pv previes`, async () => { + msgController.setSpatialRequirements(assertItem.setSpatialReq[1]); + let ErrorResponse = await Stream(CARTA.ErrorData,1); + expect(ErrorResponse[0].message).toContain("File id -2 not found"); + + msgController.setSpatialRequirements(assertItem.setSpatialReq[2]); + let SpatialProfileDataResponse = await Stream(CARTA.SpatialProfileData,1); + + expect(SpatialProfileDataResponse[0].regionId).toEqual(assertItem.spatialProfileDataResponse.regionId); + expect(SpatialProfileDataResponse[0].profiles[0].end).toEqual(assertItem.spatialProfileDataResponse.profiles[0].end); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.cdelt).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.cdelt); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.crpix).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.crpix); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.unit).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.unit); + assertItem.spatialProfileDataRawValueIndex.map((input, index) => { + expect(SpatialProfileDataResponse[0].profiles[0].rawValuesFp32[input]).toEqual(assertItem.spatialProfileDataRawValue[index]); + }); + + }); + afterAll(() => msgController.closeConnection()); }); } From d99c64932f1d6ddd976c0b734ed2138c1ba0e4de Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Tue, 11 Jul 2023 14:33:07 +0800 Subject: [PATCH 06/10] add pvPreviewStream --- src/test/PV_PREVIEW.test.ts | 115 ++++++++++++++++++++++++++++-------- src/test/myClient.ts | 11 ++++ 2 files changed, 101 insertions(+), 25 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 0a12210..58d7905 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -27,6 +27,9 @@ interface AssertItem { spatialProfileDataResponse: CARTA.ISpatialProfileData; spatialProfileDataRawValueIndex: Number[]; spatialProfileDataRawValue: Number[]; + pvPreviewStream: CARTA.IPvPreviewData; + pvPreviewStreamImageDataIndex: Number[]; + pvPreviewStreamImageDataValue: Number[]; }; let assertItem: AssertItem = { @@ -39,20 +42,20 @@ let assertItem: AssertItem = { fileId: 0, renderMode: CARTA.RenderMode.RASTER, }, - { - directory: testSubdirectory, - file: "HD163296_CO_2_1.image", - hdu: "0", - fileId: 0, - renderMode: CARTA.RenderMode.RASTER, - }, - { - directory: testSubdirectory, - file: "HD163296_CO_2_1.hdf5", - hdu: "0", - fileId: 0, - renderMode: CARTA.RenderMode.RASTER, - }, + // { + // directory: testSubdirectory, + // file: "HD163296_CO_2_1.image", + // hdu: "0", + // fileId: 0, + // renderMode: CARTA.RenderMode.RASTER, + // }, + // { + // directory: testSubdirectory, + // file: "HD163296_CO_2_1.hdf5", + // hdu: "0", + // fileId: 0, + // renderMode: CARTA.RenderMode.RASTER, + // }, ], addTilesReq: [ { @@ -79,6 +82,26 @@ let assertItem: AssertItem = { rotation: 135, } }, + { + fileId: 0, + regionId: 1, + previewRegion: false, + regionInfo: { + regionType: CARTA.RegionType.LINE, + controlPoints: [{ x: 30, y: 30 }, { x: 300, y: 300 }], + rotation: 135, + } + }, + { + fileId: 0, + regionId: 1, + previewRegion: true, + regionInfo: { + regionType: CARTA.RegionType.LINE, + controlPoints: [{ x: 106, y: 34 }, { x: 376, y: 304 }], + rotation: 135, + } + }, ], setPVRequest: [ { @@ -165,6 +188,24 @@ let assertItem: AssertItem = { }, spatialProfileDataRawValueIndex: [0,500,1000,1500, 1603], spatialProfileDataRawValue: [152, 10, 220, 106, 186], + pvPreviewStream: { + height: 250, + width: 381, + histogram: { + binWidth: 0.0022551496513187885, + firstBinCenter: -0.04696602001786232, + mean: 0.004437232558026276, + numBins: 308, + stdDev: 0.04092432589528144 + }, + histogramBounds: { + max: 0.6464924812316895, + min: -0.04809359461069107, + }, + nanEncodings: new Uint8Array([18, 116, 1, 0]), + }, + pvPreviewStreamImageDataIndex: [0, 50, 100, 200, 300], + pvPreviewStreamImageDataValue: [3, 25, 9, 4, 8] }; let basepath: string; @@ -202,7 +243,7 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( }); test(`(Step 3): set region`, async () => { - let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[0].fileId, assertItem.setRegion[0].regionId, assertItem.setRegion[0].regionInfo); + let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[0].fileId, assertItem.setRegion[0].regionId, assertItem.setRegion[0].regionInfo, assertItem.setRegion[0].previewRegion); expect(setRegionAckResponse.regionId).toEqual(1); expect(setRegionAckResponse.success).toEqual(true); }); @@ -252,17 +293,17 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( expect(ErrorResponse[0].message).toContain("File id -2 not found"); }); - test(`(Step 6): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { - let receiveNumberCurrent = msgController.messageReceiving(); - msgController.closePvPreview(assertItem.closepvpreview.previewId); - setTimeout(() => { - let receiveNumberLatter = msgController.messageReceiving(); - expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Received the number is equal during 1000 ms - done(); - }, 1000) - }); + // test(`(Step 6): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { + // let receiveNumberCurrent = msgController.messageReceiving(); + // msgController.closePvPreview(assertItem.closepvpreview.previewId); + // setTimeout(() => { + // let receiveNumberLatter = msgController.messageReceiving(); + // expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Received the number is equal during 1000 ms + // done(); + // }, 1000) + // }); - test(`(Step 7): the SET_SPATIAL_REQUIREMENTS of frontend after closing the pv previes`, async () => { + test(`(Step 6): the SET_SPATIAL_REQUIREMENTS of frontend after closing the pv previes`, async () => { msgController.setSpatialRequirements(assertItem.setSpatialReq[1]); let ErrorResponse = await Stream(CARTA.ErrorData,1); expect(ErrorResponse[0].message).toContain("File id -2 not found"); @@ -278,7 +319,31 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( assertItem.spatialProfileDataRawValueIndex.map((input, index) => { expect(SpatialProfileDataResponse[0].profiles[0].rawValuesFp32[input]).toEqual(assertItem.spatialProfileDataRawValue[index]); }); + }); + test(`(Step 7): moving SET_REGION with previewRegion = false`, async () => { + let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[1].fileId, assertItem.setRegion[1].regionId, assertItem.setRegion[1].regionInfo, assertItem.setRegion[1].previewRegion); + let pVPreviewStream = await Stream(CARTA.PvPreviewData, 1); + let SpatialProfileData = await Stream(CARTA.SpatialProfileData, 1); + + expect(setRegionAckResponse.success).toEqual(true); + expect(setRegionAckResponse.regionId).toEqual(assertItem.setRegion[1].regionId); + expect(pVPreviewStream[0].height).toEqual(assertItem.pvPreviewStream.height); + expect(pVPreviewStream[0].width).toEqual(assertItem.pvPreviewStream.width); + expect(pVPreviewStream[0].histogram.binWidth).toEqual(assertItem.pvPreviewStream.histogram.binWidth); + assertItem.pvPreviewStreamImageDataIndex.map((input, index) => { + expect(pVPreviewStream[0].histogram.bins[input]).toEqual(assertItem.pvPreviewStreamImageDataValue[index]); + }); + expect(pVPreviewStream[0].histogram.firstBinCenter).toEqual(assertItem.pvPreviewStream.histogram.firstBinCenter); + expect(pVPreviewStream[0].histogram.mean).toEqual(assertItem.pvPreviewStream.histogram.mean); + expect(pVPreviewStream[0].histogram.numBins).toEqual(assertItem.pvPreviewStream.histogram.numBins); + expect(pVPreviewStream[0].histogram.stdDev).toEqual(assertItem.pvPreviewStream.histogram.stdDev); + expect(pVPreviewStream[0].histogramBounds.max).toEqual(assertItem.pvPreviewStream.histogramBounds.max); + expect(pVPreviewStream[0].histogramBounds.min).toEqual(assertItem.pvPreviewStream.histogramBounds.min); + expect(pVPreviewStream[0].imageData.length).toEqual(68224); + for (i=0; i msgController.closeConnection()); diff --git a/src/test/myClient.ts b/src/test/myClient.ts index b30ced6..fa973ca 100644 --- a/src/test/myClient.ts +++ b/src/test/myClient.ts @@ -129,6 +129,17 @@ function Stream(cartaType: any, InputNum?: number) { } }) break; + case CARTA.PvPreviewData: + let pvPreviewStream : any [] = []; + let resPvPreviewStream = msgController.pvPreviewStream.pipe(take(InputNum)); + resPvPreviewStream.subscribe(data => { + pvPreviewStream.push(data); + _count++; + if (_count === InputNum) { + resolve(pvPreviewStream); + } + }) + break; } }) } From cff3bb1a0ab2d5fb7de257323e3d248439836fee Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Wed, 12 Jul 2023 17:20:12 +0800 Subject: [PATCH 07/10] add specialsetRegion in MessageController.ts and finish step 8 in PV_PREVIEW.test.ts --- src/test/MessageController.ts | 21 +++++ src/test/PV_PREVIEW.test.ts | 165 ++++++++++++++++++++++++---------- 2 files changed, 139 insertions(+), 47 deletions(-) diff --git a/src/test/MessageController.ts b/src/test/MessageController.ts index 71ce69a..fed143c 100644 --- a/src/test/MessageController.ts +++ b/src/test/MessageController.ts @@ -524,6 +524,27 @@ export class MessageController { return false; } + spectialSetRegion(fileId: number, regionId: number, region: RegionStore, isRequestingPreview?: boolean): boolean { + if (this.connectionStatus === ConnectionStatus.ACTIVE) { + const message = CARTA.SetRegion.create({ + fileId, + regionId, + regionInfo: { + regionType: region.regionType, + rotation: region.rotation, + controlPoints: region.controlPoints.slice() + }, + previewRegion: isRequestingPreview + }); + const requestId = this.eventCounter; + this.logEvent(CARTA.EventType.SET_REGION, requestId, message, false); + if (this.sendEvent(CARTA.EventType.SET_REGION, CARTA.SetRegion.encode(message).finish())) { + return true; + } + } + return false; + } + async setRegion(fileId: number, regionId: number, region: RegionStore, isRequestingPreview?: boolean): Promise { if (this.connectionStatus !== ConnectionStatus.ACTIVE) { throw new Error("Not connected"); diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 58d7905..8dadf42 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -24,10 +24,10 @@ interface AssertItem { precisionDigits: number; setSpatialReq: CARTA.ISetSpatialRequirements[]; closepvpreview: CARTA.IClosePvPreview; - spatialProfileDataResponse: CARTA.ISpatialProfileData; + spatialProfileDataResponse: CARTA.ISpatialProfileData[]; spatialProfileDataRawValueIndex: Number[]; spatialProfileDataRawValue: Number[]; - pvPreviewStream: CARTA.IPvPreviewData; + pvPreviewStream: CARTA.IPvPreviewData[]; pvPreviewStreamImageDataIndex: Number[]; pvPreviewStreamImageDataValue: Number[]; }; @@ -98,7 +98,7 @@ let assertItem: AssertItem = { previewRegion: true, regionInfo: { regionType: CARTA.RegionType.LINE, - controlPoints: [{ x: 106, y: 34 }, { x: 376, y: 304 }], + controlPoints: [{x: 106, y: 34}, {x: 376, y: 304}], rotation: 135, } }, @@ -175,35 +175,59 @@ let assertItem: AssertItem = { closepvpreview: { previewId: 0 }, - spatialProfileDataResponse: { - regionId: 1, - profiles: [{ - end: 400, - lineAxis: { - cdelt: 0.05000000074505806, - crpix: 200, - unit: "arcsec" - } - }] - }, + spatialProfileDataResponse: [ + { + regionId: 1, + profiles: [{ + end: 400, + lineAxis: { + cdelt: 0.05000000074505806, + crpix: 200, + unit: "arcsec" + } + }] + }, + { + regionId: 1, + profiles: [{ + end: 380, + lineAxis: { + cdelt: 0.04999999701976776, + crpix: 190, + unit: "arcsec" + } + }] + } + ], spatialProfileDataRawValueIndex: [0,500,1000,1500, 1603], spatialProfileDataRawValue: [152, 10, 220, 106, 186], - pvPreviewStream: { - height: 250, - width: 381, - histogram: { - binWidth: 0.0022551496513187885, - firstBinCenter: -0.04696602001786232, - mean: 0.004437232558026276, - numBins: 308, - stdDev: 0.04092432589528144 + pvPreviewStream: [ + { + height: 250, + width: 381, + histogram: { + binWidth: 0.0022551496513187885, + firstBinCenter: -0.04696602001786232, + mean: 0.004437232558026276, + numBins: 308, + stdDev: 0.04092432589528144 + }, + histogramBounds: { + max: 0.6464924812316895, + min: -0.04809359461069107, + }, + nanEncodings: new Uint8Array([18, 116, 1, 0]), }, - histogramBounds: { - max: 0.6464924812316895, - min: -0.04809359461069107, + { + height: 250, + width: 381, + histogramBounds: { + max: 0.3305862545967102, + min: -0.04476132243871689, + }, + nanEncodings: new Uint8Array([18, 116, 1, 0]), }, - nanEncodings: new Uint8Array([18, 116, 1, 0]), - }, + ], pvPreviewStreamImageDataIndex: [0, 50, 100, 200, 300], pvPreviewStreamImageDataValue: [3, 25, 9, 4, 8] }; @@ -311,11 +335,11 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( msgController.setSpatialRequirements(assertItem.setSpatialReq[2]); let SpatialProfileDataResponse = await Stream(CARTA.SpatialProfileData,1); - expect(SpatialProfileDataResponse[0].regionId).toEqual(assertItem.spatialProfileDataResponse.regionId); - expect(SpatialProfileDataResponse[0].profiles[0].end).toEqual(assertItem.spatialProfileDataResponse.profiles[0].end); - expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.cdelt).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.cdelt); - expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.crpix).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.crpix); - expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.unit).toEqual(assertItem.spatialProfileDataResponse.profiles[0].lineAxis.unit); + expect(SpatialProfileDataResponse[0].regionId).toEqual(assertItem.spatialProfileDataResponse[0].regionId); + expect(SpatialProfileDataResponse[0].profiles[0].end).toEqual(assertItem.spatialProfileDataResponse[0].profiles[0].end); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.cdelt).toEqual(assertItem.spatialProfileDataResponse[0].profiles[0].lineAxis.cdelt); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.crpix).toEqual(assertItem.spatialProfileDataResponse[0].profiles[0].lineAxis.crpix); + expect(SpatialProfileDataResponse[0].profiles[0].lineAxis.unit).toEqual(assertItem.spatialProfileDataResponse[0].profiles[0].lineAxis.unit); assertItem.spatialProfileDataRawValueIndex.map((input, index) => { expect(SpatialProfileDataResponse[0].profiles[0].rawValuesFp32[input]).toEqual(assertItem.spatialProfileDataRawValue[index]); }); @@ -323,26 +347,73 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( test(`(Step 7): moving SET_REGION with previewRegion = false`, async () => { let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[1].fileId, assertItem.setRegion[1].regionId, assertItem.setRegion[1].regionInfo, assertItem.setRegion[1].previewRegion); - let pVPreviewStream = await Stream(CARTA.PvPreviewData, 1); - let SpatialProfileData = await Stream(CARTA.SpatialProfileData, 1); - + let pVPreviewStream = []; + let SpatialProfileData = []; + let pVPreviewStreamPromise = new Promise((resolve)=>{ + msgController.pvPreviewStream.subscribe({ + next: (data) => { + pVPreviewStream.push(data) + resolve(pVPreviewStream) + } + }) + }); + let SpatialProfileDataPromise = new Promise((resolve)=>{ + msgController.spatialProfileStream.subscribe({ + next: (data) => { + SpatialProfileData.push(data) + resolve(SpatialProfileData) + } + }) + }); + let pVPreviewStreamResponse = await pVPreviewStreamPromise; + let SpatialProfileDataResponse = await SpatialProfileDataPromise; + expect(setRegionAckResponse.success).toEqual(true); expect(setRegionAckResponse.regionId).toEqual(assertItem.setRegion[1].regionId); - expect(pVPreviewStream[0].height).toEqual(assertItem.pvPreviewStream.height); - expect(pVPreviewStream[0].width).toEqual(assertItem.pvPreviewStream.width); - expect(pVPreviewStream[0].histogram.binWidth).toEqual(assertItem.pvPreviewStream.histogram.binWidth); + expect(pVPreviewStream[0].height).toEqual(assertItem.pvPreviewStream[0].height); + expect(pVPreviewStream[0].width).toEqual(assertItem.pvPreviewStream[0].width); + expect(pVPreviewStream[0].histogram.binWidth).toEqual(assertItem.pvPreviewStream[0].histogram.binWidth); assertItem.pvPreviewStreamImageDataIndex.map((input, index) => { expect(pVPreviewStream[0].histogram.bins[input]).toEqual(assertItem.pvPreviewStreamImageDataValue[index]); }); - expect(pVPreviewStream[0].histogram.firstBinCenter).toEqual(assertItem.pvPreviewStream.histogram.firstBinCenter); - expect(pVPreviewStream[0].histogram.mean).toEqual(assertItem.pvPreviewStream.histogram.mean); - expect(pVPreviewStream[0].histogram.numBins).toEqual(assertItem.pvPreviewStream.histogram.numBins); - expect(pVPreviewStream[0].histogram.stdDev).toEqual(assertItem.pvPreviewStream.histogram.stdDev); - expect(pVPreviewStream[0].histogramBounds.max).toEqual(assertItem.pvPreviewStream.histogramBounds.max); - expect(pVPreviewStream[0].histogramBounds.min).toEqual(assertItem.pvPreviewStream.histogramBounds.min); + expect(pVPreviewStream[0].histogram.firstBinCenter).toEqual(assertItem.pvPreviewStream[0].histogram.firstBinCenter); + expect(pVPreviewStream[0].histogram.mean).toEqual(assertItem.pvPreviewStream[0].histogram.mean); + expect(pVPreviewStream[0].histogram.numBins).toEqual(assertItem.pvPreviewStream[0].histogram.numBins); + expect(pVPreviewStream[0].histogram.stdDev).toEqual(assertItem.pvPreviewStream[0].histogram.stdDev); + expect(pVPreviewStream[0].histogramBounds.max).toBeCloseTo(assertItem.pvPreviewStream[0].histogramBounds.max, assertItem.precisionDigits); + expect(pVPreviewStream[0].histogramBounds.min).toBeCloseTo(assertItem.pvPreviewStream[0].histogramBounds.min, assertItem.precisionDigits); expect(pVPreviewStream[0].imageData.length).toEqual(68224); - for (i=0; i { + msgController.spectialSetRegion(assertItem.setRegion[2].fileId, assertItem.setRegion[2].regionId, assertItem.setRegion[2].regionInfo, assertItem.setRegion[2].previewRegion); + let pVPreviewStream = []; + let pVPreviewStreamPromise = new Promise((resolve)=>{ + msgController.pvPreviewStream.subscribe({ + next: (data) => { + pVPreviewStream.push(data) + resolve(pVPreviewStream) + } + }) + }); + let pVPreviewStreamResponse = await pVPreviewStreamPromise; + + expect(pVPreviewStream[0].height).toEqual(assertItem.pvPreviewStream[1].height); + expect(pVPreviewStream[0].width).toEqual(assertItem.pvPreviewStream[1].width); + expect(pVPreviewStream[0].histogram).toEqual(null); + expect(pVPreviewStream[0].histogramBounds.max).toBeCloseTo(assertItem.pvPreviewStream[1].histogramBounds.max, assertItem.precisionDigits); + expect(pVPreviewStream[0].histogramBounds.min).toBeCloseTo(assertItem.pvPreviewStream[1].histogramBounds.min, assertItem.precisionDigits); + expect(pVPreviewStream[0].imageData.length).toEqual(49792); + for (i=0; i Date: Thu, 13 Jul 2023 03:59:34 +0800 Subject: [PATCH 08/10] finish PV_PREVIEW.test.ts --- src/test/PV_PREVIEW.test.ts | 38 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 8dadf42..6cef15c 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -42,20 +42,20 @@ let assertItem: AssertItem = { fileId: 0, renderMode: CARTA.RenderMode.RASTER, }, - // { - // directory: testSubdirectory, - // file: "HD163296_CO_2_1.image", - // hdu: "0", - // fileId: 0, - // renderMode: CARTA.RenderMode.RASTER, - // }, - // { - // directory: testSubdirectory, - // file: "HD163296_CO_2_1.hdf5", - // hdu: "0", - // fileId: 0, - // renderMode: CARTA.RenderMode.RASTER, - // }, + { + directory: testSubdirectory, + file: "HD163296_CO_2_1.image", + hdu: "0", + fileId: 0, + renderMode: CARTA.RenderMode.RASTER, + }, + { + directory: testSubdirectory, + file: "HD163296_CO_2_1.hdf5", + hdu: "0", + fileId: 0, + renderMode: CARTA.RenderMode.RASTER, + }, ], addTilesReq: [ { @@ -417,6 +417,16 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( } }); + test(`(Step 9): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { + let receiveNumberCurrent = msgController.messageReceiving(); + msgController.closePvPreview(assertItem.closepvpreview.previewId); + setTimeout(() => { + let receiveNumberLatter = msgController.messageReceiving(); + expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Received the number is equal during 1000 ms + done(); + }, 1000) + }); + afterAll(() => msgController.closeConnection()); }); } From d1747c391dede543a942caa172dea35e475346e4 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Thu, 13 Jul 2023 15:18:40 +0800 Subject: [PATCH 09/10] add PV_PREVIEW_CANCEL.test.ts --- src/test/PV_PREVIEW_CANCEL.test.ts | 115 +++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 src/test/PV_PREVIEW_CANCEL.test.ts diff --git a/src/test/PV_PREVIEW_CANCEL.test.ts b/src/test/PV_PREVIEW_CANCEL.test.ts new file mode 100644 index 0000000..1627a36 --- /dev/null +++ b/src/test/PV_PREVIEW_CANCEL.test.ts @@ -0,0 +1,115 @@ +import { CARTA } from "carta-protobuf"; +import { checkConnection, Stream} from './myClient'; +import { MessageController } from "./MessageController"; +import config from "./config.json"; +import exp from "constants"; + +let testServerUrl: string = config.serverURL0; +let testSubdirectory: string = config.path.QA; +let connectTimeout: number = config.timeout.connection; +let openFileTimeout: number = config.timeout.openFile; + +interface AssertItem { + filelist: CARTA.IFileListRequest; + fileOpen: CARTA.IOpenFile[]; + addTilesReq: CARTA.IAddRequiredTiles[]; + setCursor: CARTA.ISetCursor[]; + setRegion: CARTA.ISetRegion[]; + setPVRequest: CARTA.IPvRequest[]; +}; + +let assertItem: AssertItem = { + filelist: { directory: testSubdirectory }, + fileOpen: [ + { + directory: testSubdirectory, + file: "S255_IR_sci.spw25.cube.I.pbcor.fits", + hdu: "0", + fileId: 0, + renderMode: CARTA.RenderMode.RASTER, + }, + ], + addTilesReq: [ + { + fileId: 0, + compressionQuality: 11, + compressionType: CARTA.CompressionType.ZFP, + tiles: [0], + }, + ], + setCursor: [ + { + fileId: 0, + point: { x: 1, y: 1 }, + }, + ], + setRegion: [ + { + fileId: 0, + regionId: -1, + previewRegion: false, + regionInfo: { + regionType: CARTA.RegionType.LINE, + controlPoints: [{ x: 79, y: 77 }, { x: 362, y: 360 }], + rotation: 135, + } + }, + ], + setPVRequest: [ + { + fileId: 0, + regionId: 1, + width: 3, + keep: true, + reverse: false, + spectralRange: {min: 0, max: 249}, + previewSettings: { + animationCompressionQuality: 9, + compressionType: CARTA.CompressionType.ZFP, + imageCompressionQuality: 11, + previewId: 0, + rebinXy: 1, + rebinZ: 1, + regionId: -1, + } + } + ], +}; + +let basepath: string; +describe("PV_PREVIEW_CANCEL test: Testing PV preview with cancel request", () => { + const msgController = MessageController.Instance; + describe(`Register a session`, () => { + beforeAll(async ()=> { + await msgController.connect(testServerUrl); + }, connectTimeout); + + checkConnection(); + test(`Get basepath and modify the directory path`, async () => { + let fileListResponse = await msgController.getFileList("$BASE",0); + basepath = fileListResponse.directory; + assertItem.fileOpen[0].directory = basepath + "/" + assertItem.fileOpen[0].directory; + }); + + describe(`Preparation`, () => { + test(`(step 1): Open image`, async () => { + msgController.closeFile(-1); + let OpenFileResponse = await msgController.loadFile(assertItem.fileOpen[0]); + let RegionHistogramData = await Stream(CARTA.RegionHistogramData,1); + + expect(OpenFileResponse.success).toBe(true); + expect(OpenFileResponse.fileInfo.name).toEqual(assertItem.fileOpen[0].file); + }); + + test(`(Stpe 2): Set cursor and add required tiles`, async () => { + msgController.addRequiredTiles(assertItem.addTilesReq[0]); + let RasterTileDataResponse = await Stream(CARTA.RasterTileData,assertItem.addTilesReq[0].tiles.length + 2); + + msgController.setCursor(assertItem.setCursor[0].fileId, assertItem.setCursor[0].point.x, assertItem.setCursor[0].point.y); + let SpatialProfileDataResponse1 = await Stream(CARTA.SpatialProfileData,1); + }); + }); + + afterAll(() => msgController.closeConnection()); + }); +}); \ No newline at end of file From f68e95ce8f83b2fa795dd1aef5d44e13b9fb1ad9 Mon Sep 17 00:00:00 2001 From: Ming-Yi Lin Date: Thu, 13 Jul 2023 15:59:17 +0800 Subject: [PATCH 10/10] finish PV_PREVIEW_CANCEL.test.ts --- src/test/PV_PREVIEW.test.ts | 22 ++++----------- src/test/PV_PREVIEW_CANCEL.test.ts | 44 ++++++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/src/test/PV_PREVIEW.test.ts b/src/test/PV_PREVIEW.test.ts index 6cef15c..4e5bd1c 100644 --- a/src/test/PV_PREVIEW.test.ts +++ b/src/test/PV_PREVIEW.test.ts @@ -266,14 +266,14 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( let SpatialProfileDataResponse1 = await Stream(CARTA.SpatialProfileData,1); }); - test(`(Step 3): set region`, async () => { + test(`(Step 3): Set region`, async () => { let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[0].fileId, assertItem.setRegion[0].regionId, assertItem.setRegion[0].regionInfo, assertItem.setRegion[0].previewRegion); expect(setRegionAckResponse.regionId).toEqual(1); expect(setRegionAckResponse.success).toEqual(true); }); let pVProgressData = []; - test(`(Step 4): set PV request`, async () => { + test(`(Step 4): Set PV request`, async () => { let pvProgressPromise = new Promise((resolve)=>{ msgController.pvProgressStream.subscribe({ next: (data) => { @@ -311,22 +311,12 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( } }); - test(`(Step 5): set spatial requirement`, async () => { + test(`(Step 5): Set spatial requirement`, async () => { msgController.setSpatialRequirements(assertItem.setSpatialReq[0]); let ErrorResponse = await Stream(CARTA.ErrorData,1); expect(ErrorResponse[0].message).toContain("File id -2 not found"); }); - // test(`(Step 6): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { - // let receiveNumberCurrent = msgController.messageReceiving(); - // msgController.closePvPreview(assertItem.closepvpreview.previewId); - // setTimeout(() => { - // let receiveNumberLatter = msgController.messageReceiving(); - // expect(receiveNumberCurrent).toEqual(receiveNumberLatter); //Received the number is equal during 1000 ms - // done(); - // }, 1000) - // }); - test(`(Step 6): the SET_SPATIAL_REQUIREMENTS of frontend after closing the pv previes`, async () => { msgController.setSpatialRequirements(assertItem.setSpatialReq[1]); let ErrorResponse = await Stream(CARTA.ErrorData,1); @@ -345,7 +335,7 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( }); }); - test(`(Step 7): moving SET_REGION with previewRegion = false`, async () => { + test(`(Step 7): Moving SET_REGION with previewRegion = false`, async () => { let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[1].fileId, assertItem.setRegion[1].regionId, assertItem.setRegion[1].regionInfo, assertItem.setRegion[1].previewRegion); let pVPreviewStream = []; let SpatialProfileData = []; @@ -393,7 +383,7 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( expect(SpatialProfileData[0].profiles[0].lineAxis.unit).toEqual(assertItem.spatialProfileDataResponse[1].profiles[0].lineAxis.unit); }); - test(`(Step 8): moving SET_REGION with previewRegion = true`, async () => { + test(`(Step 8): Moving SET_REGION with previewRegion = true`, async () => { msgController.spectialSetRegion(assertItem.setRegion[2].fileId, assertItem.setRegion[2].regionId, assertItem.setRegion[2].regionInfo, assertItem.setRegion[2].previewRegion); let pVPreviewStream = []; let pVPreviewStreamPromise = new Promise((resolve)=>{ @@ -417,7 +407,7 @@ describe("PV_PREVIEW test: Testing PV preview with FITS, CASA, and HDF5 file", ( } }); - test(`(Step 9): close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { + test(`(Step 9): Close the pv preview and NO message from the backend (timeout of 1000ms)`, done => { let receiveNumberCurrent = msgController.messageReceiving(); msgController.closePvPreview(assertItem.closepvpreview.previewId); setTimeout(() => { diff --git a/src/test/PV_PREVIEW_CANCEL.test.ts b/src/test/PV_PREVIEW_CANCEL.test.ts index 1627a36..4f27de0 100644 --- a/src/test/PV_PREVIEW_CANCEL.test.ts +++ b/src/test/PV_PREVIEW_CANCEL.test.ts @@ -16,6 +16,7 @@ interface AssertItem { setCursor: CARTA.ISetCursor[]; setRegion: CARTA.ISetRegion[]; setPVRequest: CARTA.IPvRequest[]; + pvCancelMessage: String; }; let assertItem: AssertItem = { @@ -50,7 +51,7 @@ let assertItem: AssertItem = { previewRegion: false, regionInfo: { regionType: CARTA.RegionType.LINE, - controlPoints: [{ x: 79, y: 77 }, { x: 362, y: 360 }], + controlPoints: [{ x: 260, y: 287 }, { x: 1613, y: 1640 }], rotation: 135, } }, @@ -59,21 +60,22 @@ let assertItem: AssertItem = { { fileId: 0, regionId: 1, - width: 3, - keep: true, + width: 5, + keep: false, reverse: false, - spectralRange: {min: 0, max: 249}, + spectralRange: {min: 0, max: 400}, previewSettings: { animationCompressionQuality: 9, compressionType: CARTA.CompressionType.ZFP, imageCompressionQuality: 11, previewId: 0, - rebinXy: 1, - rebinZ: 1, + rebinXy: 4, + rebinZ: 4, regionId: -1, } } ], + pvCancelMessage: "PV image preview cancelled", }; let basepath: string; @@ -108,6 +110,36 @@ describe("PV_PREVIEW_CANCEL test: Testing PV preview with cancel request", () => msgController.setCursor(assertItem.setCursor[0].fileId, assertItem.setCursor[0].point.x, assertItem.setCursor[0].point.y); let SpatialProfileDataResponse1 = await Stream(CARTA.SpatialProfileData,1); }); + + test(`(Step 3): Set region`, async () => { + let setRegionAckResponse = await msgController.setRegion(assertItem.setRegion[0].fileId, assertItem.setRegion[0].regionId, assertItem.setRegion[0].regionInfo, assertItem.setRegion[0].previewRegion); + expect(setRegionAckResponse.regionId).toEqual(1); + expect(setRegionAckResponse.success).toEqual(true); + }); + + test(`(Step 4): Set PV request`, async () => { + let pVProgressData = []; + let pvProgressPromise = new Promise((resolve)=>{ + msgController.pvProgressStream.subscribe({ + next: (data) => { + pVProgressData.push(data) + if (pVProgressData.length === 1) { + msgController.cancelRequestingPV(assertItem.setRegion[0].fileId); + msgController.stopPvPreview(assertItem.setRegion[0].fileId); + resolve(pVProgressData); + } + } + }) + }); + + try { + let PVresponse = await msgController.requestPV(assertItem.setPVRequest[0]); + } catch (err) { + expect(err).toContain(assertItem.pvCancelMessage); + } + let pvProgressReponse = await pvProgressPromise; + expect(pvProgressReponse[0].progress).toBeLessThan(1); + }); }); afterAll(() => msgController.closeConnection());