get-location.test.js 5.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
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')

describe("get-location", () => {
    beforeAll(async () => {
      page = await program.reLaunch(PAGE_PATH)
      await page.waitFor(600)
    });

    //system 定位
    it("system+type=wgs84+success", async () => {

      await page.setData({
        jest_provider: 'system',
        jest_type: 'wgs84',
        jest_isAltitude: true,
        jest_isGeocode: false,
        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_longitude']).toBeGreaterThanOrEqual(-180);
        expect((await page.data())['jest_longitude']).toBeLessThanOrEqual(180);
        expect((await page.data())['jest_latitude']).toBeGreaterThanOrEqual(-90);
        expect((await page.data())['jest_latitude']).toBeLessThanOrEqual(90);
        //判断海拔是否正确
        expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
zhaofengliang920817's avatar
zhaofengliang920817 已提交
42
        expect((await page.data())['jest_altitude']).not.toEqual(0);
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
      }
    });

    //system 定位
    it("system+type=wgs84+success+geocode=true", async () => {

      await page.setData({
        jest_provider: 'system',
        jest_type: 'wgs84',
        jest_isAltitude: true,
        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) {
        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 {
zhaofengliang920817's avatar
zhaofengliang920817 已提交
97
        expect((await page.data())['jest_altitude']).toEqual(0);
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
      }
    });

    //system 定位
    it("system+type=gcj02+fail", async () => {
      await page.setData({
        jest_provider: 'system',
        jest_type: 'gcj02',
        jest_isAltitude: true,
        jest_isGeocode: true,
        jest_isHighAccuracy: false
      })
      await page.callMethod('jestGetLocation')
      await page.waitFor(async () => {
        return await page.data('jest_complete') === true;
      });
114 115 116
      if (isApp) {
        expect((await page.data())['jest_errCode']).toEqual(1505601);
      }
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
    });


    //tencent 定位
    it("tencent+type=gcj02+success", async () => {
        await page.setData({
          jest_provider: 'tencent',
          jest_type: 'gcj02',
          jest_isAltitude: true,
          jest_isGeocode: true,
          jest_isHighAccuracy: true
        })
        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_address']).toEqual(expect.any(String));
          //判断经纬度是否在正常范围
          expect((await page.data())['jest_longitude']).toBeGreaterThanOrEqual(-180);
          expect((await page.data())['jest_longitude']).toBeLessThanOrEqual(180);
          expect((await page.data())['jest_latitude']).toBeGreaterThanOrEqual(-90);
          expect((await page.data())['jest_latitude']).toBeLessThanOrEqual(90);
          //判断海拔是否正确
          expect((await page.data())['jest_altitude']).toEqual(expect.any(Number));
zhaofengliang920817's avatar
zhaofengliang920817 已提交
150
          expect((await page.data())['jest_altitude']).not.toEqual(0);
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
        }
    });

    //tencent 定位
    it("tencent+type=wgs84+fail", async () => {
      await page.setData({
        jest_provider: 'tencent',
        jest_type: 'wgs84',
        jest_isAltitude: true,
        jest_isGeocode: true,
        jest_isHighAccuracy: true
      })
      await page.callMethod('jestGetLocation')
      await page.waitFor(async () => {
        return await page.data('jest_complete') === true;
      });
      if (isApp) {
          expect((await page.data())['jest_errCode']).toEqual(1505607);
      }
    });
});