Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
2d28862f
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6060
Star
93
Fork
166
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
2d28862f
编写于
7月 18, 2024
作者:
Anne_LXM
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
test(map.test.js): 调整测试例
上级
51418f5c
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
104 addition
and
38 deletion
+104
-38
pages/component/map/map.test.js
pages/component/map/map.test.js
+42
-32
pages/component/map/map.uvue
pages/component/map/map.uvue
+62
-6
未找到文件。
pages/component/map/map.test.js
浏览文件 @
2d28862f
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
(
2000
);
}
else
{
await
page
.
waitFor
(
500
);
await
page
.
waitFor
(
500
);
}
expect
(
await
program
.
screenshot
()).
toSaveImageSnapshot
({
customSnapshotIdentifier
()
{
expect
(
await
program
.
screenshot
()).
toSaveImageSnapshot
();
return
'
map-
'
+
mapMethods
[
i
]
}});
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
(
'
getCenterLocationTes
t
'
)
const
centerLocationRes
=
await
page
.
data
(
'
jestResul
t
'
)
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
}
const
northeastExp
=
{
latitude
:
40.0149408585477
,
longitude
:
116.56799353271484
}
// 在Safari中返回的经纬度
// southwest: { latitude: 39.64483423532459, longitude: 115.88249286914063 },
// 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
(
southwest
.
latitude
).
not
.
toBeFalsy
();
expect
(
northeastExp
.
longitude
).
not
.
toBeFalsy
();
expect
(
southwest
.
longitude
).
not
.
toBeFalsy
();
expect
(
northeastExp
.
latitude
).
not
.
toBeFalsy
();
expect
(
northeast
.
latitude
).
not
.
toBeFalsy
();
}
expect
(
northeast
.
longitude
).
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
())
});
});
});
pages/component/map/map.uvue
浏览文件 @
2d28862f
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录