提交 88ded457 编写于 作者: DCloud-WZF's avatar DCloud-WZF 💬

test(getLocation): 优化代码,规避小程序平台

上级 7f6d6836
const PAGE_PATH = "/pages/API/get-location/get-location";
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos
const PAGE_PATH = "/pages/API/get-location/get-location";
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
const isApp = isAndroid || isIos
const isWeb = platformInfo.startsWith('web')
const isMP = platformInfo.startsWith('mp')
describe("get-location", () => {
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
if(isMP) {
// 微信上会有权限弹框,暂时屏蔽测试
it('not support', async () => {
expect(1).toBe(1)
})
}
describe("get-location", () => {
if(isMP) {
// 微信上会有权限弹框,暂时屏蔽测试
it('not support', async () => {
expect(1).toBe(1)
})
return
}
beforeAll(async () => {
page = await program.reLaunch(PAGE_PATH)
await page.waitFor(600)
});
});
//system 定位
it("system+type=wgs84+success", async () => {
it("system+type=wgs84+success", async () => {
await page.setData({
jest_provider: 'system',
......@@ -33,11 +33,11 @@ describe("get-location", () => {
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
if (jest_errCode > 0) {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
//判断经纬度是否在正常范围
......@@ -48,10 +48,10 @@ describe("get-location", () => {
//判断海拔是否正确
expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
}
});
});
//system 定位
it("system+type=wgs84+success+geocode=true", async () => {
it("system+type=wgs84+success+geocode=true", async () => {
await page.setData({
jest_provider: 'system',
......@@ -64,45 +64,45 @@ describe("get-location", () => {
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
if (isIos) {
expect((await page.data())['jest_errCode']).toEqual(1505603);
} else if (isAndroid) {
expect((await page.data())['jest_errCode']).toEqual(1505700);
} else {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
if (isIos) {
expect((await page.data())['jest_errCode']).toEqual(1505603);
} else if (isAndroid) {
expect((await page.data())['jest_errCode']).toEqual(1505700);
} else {
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
}
}
});
//system 定位
it("system+type=wgs84+success+altitude=false", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'wgs84',
jest_isAltitude: false,
jest_isGeocode: true,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
//如果定位出错
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
expect((await page.data())['jest_altitude']).toEqual(0);
}
});
//system 定位
it("system+type=wgs84+success+altitude=false", async () => {
await page.setData({
jest_provider: 'system',
jest_type: 'wgs84',
jest_isAltitude: false,
jest_isGeocode: true,
jest_isHighAccuracy: false
})
await page.callMethod('jestGetLocation')
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
//如果定位出错
expect((await page.data())['jest_errCode']).toEqual(expect.any(Number));
} else {
expect((await page.data())['jest_altitude']).toEqual(0);
}
});
//system 定位
......@@ -118,8 +118,8 @@ describe("get-location", () => {
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505601);
if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505601);
}
});
......@@ -138,7 +138,7 @@ describe("get-location", () => {
return await page.data('jest_complete') === true;
});
const data = await page.data()
const data = await page.data()
const jest_errCode = data['jest_errCode']
if (jest_errCode > 0) {
......@@ -170,8 +170,8 @@ describe("get-location", () => {
await page.waitFor(async () => {
return await page.data('jest_complete') === true;
});
if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505607);
if (isApp) {
expect((await page.data())['jest_errCode']).toEqual(1505607);
}
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册