提交 2d28862f 编写于 作者: Anne_LXM's avatar Anne_LXM

test(map.test.js): 调整测试例

上级 51418f5c
let page; let page;
describe('web-map', () => { describe('web-map', () => {
console.log("uniTestPlatformInfo",process.env.uniTestPlatformInfo)
if (!process.env.uniTestPlatformInfo.startsWith('web')) { if (!process.env.uniTestPlatformInfo.startsWith('web')) {
it('app', () => { it('app', () => {
expect(1).toBe(1) expect(1).toBe(1)
...@@ -12,52 +11,63 @@ describe('web-map', () => { ...@@ -12,52 +11,63 @@ describe('web-map', () => {
await page.waitFor('view'); await page.waitFor('view');
// 等待地图加载完成 // 等待地图加载完成
await page.waitFor(4000); await page.waitFor(4000);
await page.setData({autoTest:true}) await page.callMethod('updateAutoTest',true)
}); });
it('Check MapMethods', async () => { it('Check MapMethods', async () => {
const mapMethods = ['changeScale', 'addMarkers', 'addPolyline', 'addPolygons', 'addCircles', const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','addPolyline', 'addPolygons', 'addCircles','includePoint']
'includePoint', 'handleTranslateMarker'
]
for (var i = 0; i < mapMethods.length; i++) { for (var i = 0; i < mapMethods.length; i++) {
await page.callMethod(mapMethods[i]) await page.callMethod(mapMethods[i])
if (mapMethods[i] == 'handleTranslateMarker') { await page.waitFor(500);
await page.waitFor(2000); expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
} else { return 'map-' + mapMethods[i]
await page.waitFor(500); }});
}
expect(await program.screenshot()).toSaveImageSnapshot();
await page.waitFor(500); await page.waitFor(500);
} }
}); });
it('handleGetCenterLocation', async () => { it('handleGetCenterLocation', async () => {
await page.callMethod('handleGetCenterLocation') await page.callMethod('handleGetCenterLocation')
await page.waitFor(500); await page.waitFor(500);
const centerLocationRes = await page.data('getCenterLocationTest') const centerLocationRes = await page.data('jestResult')
expect(centerLocationRes.latitude).not.toBeNull(); expect(centerLocationRes.centerPoints.latitude).not.toBeNull();
expect(centerLocationRes.longitude).not.toBeNull(); expect(centerLocationRes.centerPoints.longitude).not.toBeNull();
}); });
it('handleGetRegion', async () => { it('handleGetRegion', async () => {
await page.callMethod('handleGetRegion') await page.callMethod('handleGetRegion')
await page.waitFor(500); await page.waitFor(500);
const regionRes = await page.data('getRegionTest') const regionRes = await page.data('jestResult')
console.log('regionRes', regionRes);
const {southwest,northeast} = regionRes; const {southwest,northeast} = regionRes;
const southwestExp ={ latitude: 39.88334279187766, longitude: 116.31050146728515 } expect(southwest.latitude).not.toBeFalsy();
const northeastExp ={ latitude: 40.0149408585477, longitude: 116.56799353271484 } expect(southwest.longitude).not.toBeFalsy();
// 在Safari中返回的经纬度 expect(northeast.latitude).not.toBeFalsy();
// southwest: { latitude: 39.64483423532459, longitude: 115.88249286914063 }, expect(northeast.longitude).not.toBeFalsy();
// northeast: { latitude: 40.17153735946949, longitude: 116.91246113085938 },
if(!process.env.uniTestPlatformInfo.includes('Safari')){
expect(southwest.latitude).toBeCloseTo(southwestExp.latitude, 3);
expect(southwest.longitude).toBeCloseTo(southwestExp.longitude, 3);
expect(northeast.latitude).toBeCloseTo(northeastExp.latitude, 3);
expect(northeast.longitude).toBeCloseTo(northeastExp.longitude, 3);
}else{
expect(southwest.longitude).not.toBeFalsy();
expect(southwest.latitude).not.toBeFalsy();
expect(northeastExp.longitude).not.toBeFalsy();
expect(northeastExp.latitude).not.toBeFalsy();
}
}); });
it('handleTranslateMarker', async () => {
await page.callMethod('handleTranslateMarker')
await page.waitFor(2000);
expect(await program.screenshot()).toSaveImageSnapshot();
const translateMarkerRes = await page.data('jestResult')
expect(translateMarkerRes.animationEnd).toBeTruthy();
expect(translateMarkerRes.translateMarkerMsg).toBe('translateMarker:ok');
});
it('handleMoveToLocation', async () => {
await page.callMethod('handleMoveToLocation')
await page.waitFor(500);
const moveToLocationRes = await page.data('jestResult')
expect(moveToLocationRes.moveToLocationMsg).toBe("moveToLocation:ok");
});
it('handleGetScale', async () => {
await page.callMethod('handleGetScale')
await page.waitFor(500);
const scaleRes = await page.data('jestResult')
expect(scaleRes.scale).toBeGreaterThanOrEqual(5);
expect(scaleRes.scale).toBeLessThanOrEqual(18);
console.log("jestResult",await page.data())
});
}); });
...@@ -126,6 +126,16 @@ ...@@ -126,6 +126,16 @@
clickable?: boolean; clickable?: boolean;
} }
type TypeJestResult = {
translateMarkerMsg:string,
animationEnd:boolean,
centerPoints: Points,
southwest: Points,
northeast: Points,
moveToLocationMsg:string,
scale:number
}
const testMarkers = [{ const testMarkers = [{
id: 0, id: 0,
latitude: 39.989631, latitude: 39.989631,
...@@ -314,7 +324,32 @@ ...@@ -314,7 +324,32 @@
const location = ref({ longitude: 116.39742, latitude: 39.909 }); const location = ref({ longitude: 116.39742, latitude: 39.909 });
const rotate = ref(0); const rotate = ref(0);
const skew = ref(0); const skew = ref(0);
// 自动化测试
const autoTest = ref(false); const autoTest = ref(false);
const updateAutoTest = (value: boolean) => {
autoTest.value = value
}
const jestResult = reactive({
translateMarkerMsg:"",
animationEnd:false,
centerPoints: {
latitude : 0,
longitude : 0
},
southwest: {
latitude : 0,
longitude : 0
},
northeast: {
latitude : 0,
longitude : 0
},
moveToLocationMsg:"",
scale:0,
} as TypeJestResult);
onReady(() => { onReady(() => {
map.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!) map.value = uni.createMapContext("map1", getCurrentInstance()!.proxy!)
...@@ -434,13 +469,12 @@ ...@@ -434,13 +469,12 @@
}; };
const getCenterLocationTest = ref({});
const handleGetCenterLocation = () => { const handleGetCenterLocation = () => {
if (map.value) { if (map.value) {
map.value.getCenterLocation({ map.value.getCenterLocation({
success: ret => { success: ret => {
// console.log('getCenterLocation',ret); // console.log('getCenterLocation',ret);
getCenterLocationTest.value = ret; jestResult.centerPoints = ret;
if(!autoTest.value){ if(!autoTest.value){
uni.showModal({ uni.showModal({
content: JSON.stringify(ret) content: JSON.stringify(ret)
...@@ -451,13 +485,13 @@ ...@@ -451,13 +485,13 @@
} }
}; };
const getRegionTest = ref({});
const handleGetRegion = () => { const handleGetRegion = () => {
if (map.value) { if (map.value) {
map.value.getRegion({ map.value.getRegion({
success: ret => { success: ret => {
// console.log('getRegion',JSON.stringify(ret)); // console.log('getRegion',JSON.stringify(ret));
getRegionTest.value = ret; jestResult.southwest = ret.southwest;
jestResult.northeast = ret.northeast
if(!autoTest.value){ if(!autoTest.value){
uni.showModal({ uni.showModal({
content: JSON.stringify(ret) content: JSON.stringify(ret)
...@@ -481,10 +515,12 @@ ...@@ -481,10 +515,12 @@
rotate:10, rotate:10,
duration: 2000, duration: 2000,
animationEnd: () => { animationEnd: () => {
console.log('动画结束'); // console.log('动画结束');
jestResult.animationEnd = true;
}, },
success: ret => { success: ret => {
console.log('handleTranslateMarker',JSON.stringify(ret)); // console.log('handleTranslateMarker',JSON.stringify(ret));
jestResult.translateMarkerMsg = ret.errMsg;
}, },
fail: error => { fail: error => {
console.log(error) console.log(error)
...@@ -500,6 +536,7 @@ ...@@ -500,6 +536,7 @@
success: res => { success: res => {
// console.log('getScale',res); // console.log('getScale',res);
scale.value = res.scale scale.value = res.scale
jestResult.scale = res.scale
if(!autoTest.value){ if(!autoTest.value){
uni.showModal({ uni.showModal({
content: '当前地图的缩放级别为:'+ res.scale content: '当前地图的缩放级别为:'+ res.scale
...@@ -520,6 +557,7 @@ ...@@ -520,6 +557,7 @@
longitude: 116.39742, longitude: 116.39742,
success: res => { success: res => {
// console.log('moveToLocation',res); // console.log('moveToLocation',res);
jestResult.moveToLocationMsg = res.errMsg;
if(!autoTest.value){ if(!autoTest.value){
uni.showModal({ uni.showModal({
content: JSON.stringify(res) content: JSON.stringify(res)
...@@ -576,6 +614,24 @@ ...@@ -576,6 +614,24 @@
}); });
}; };
defineExpose({
jestResult,
autoTest,
updateAutoTest,
addControls,
addMarkers,
addMarkersLabel,
addPolyline,
addPolygons,
addCircles,
includePoint,
handleGetCenterLocation,
handleGetRegion,
handleTranslateMarker,
handleMoveToLocation,
handleGetScale
})
</script> </script>
<style> <style>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册