map.test.js 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
let page;
describe('web-map', () => {
  console.log("uniTestPlatformInfo",process.env.uniTestPlatformInfo)
  if (!process.env.uniTestPlatformInfo.startsWith('web')) {
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  beforeAll(async () => {
Anne_LXM's avatar
Anne_LXM 已提交
11
    page = await program.reLaunch('/pages/API/map/map')
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 42 43 44 45 46 47 48 49 50 51
    await page.waitFor('view');
    // 等待地图加载完成
    await page.waitFor(4000);
    await page.setData({autoTest:true})
  });

  it('Check MapMethods', async () => {
    const mapMethods = ['changeScale', 'addMarkers', 'addPolyline', 'addPolygons', 'addCircles',
      'includePoint', 'handleTranslateMarker'
    ]
    for (var i = 0; i < mapMethods.length; i++) {
      await page.callMethod(mapMethods[i])
      if (mapMethods[i] == 'handleTranslateMarker') {
        await page.waitFor(2000);
      } else {
        await page.waitFor(500);
      }
      expect(await program.screenshot()).toSaveImageSnapshot();
      await page.waitFor(500);
    }
  });
  it('handleGetCenterLocation', async () => {
    await page.callMethod('handleGetCenterLocation')
    await page.waitFor(500);
    const centerLocationRes = await page.data('getCenterLocationTest')
    expect(centerLocationRes.latitude).not.toBeNull();
    expect(centerLocationRes.longitude).not.toBeNull();
  });
  it('handleGetRegion', async () => {
    await page.callMethod('handleGetRegion')
    await page.waitFor(500);
    const regionRes = await page.data('getRegionTest')
    const getRegionExpected = {
      southwest: { latitude: 39.88334279187766, longitude: 116.31050146728515 },
      northeast: { latitude: 40.0149408585477, longitude: 116.56799353271484 },
      errMsg: 'getRegion:ok'
    }
    expect(regionRes).toEqual(expect.objectContaining(getRegionExpected));
  });
});