map.test.js 2.7 KB
Newer Older
1 2 3 4 5 6 7 8 9
let page;
describe('web-map', () => {
  if (!process.env.uniTestPlatformInfo.startsWith('web')) {
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  beforeAll(async () => {
10
    page = await program.reLaunch('/pages/component/map/map')
11
    await page.waitFor('view');
12
    await page.waitFor('map');
13
    // 等待地图加载完成
14 15
    const waitTime = process.env.uniTestPlatformInfo.includes('firefox') ? 5000:4000
    await page.waitFor(waitTime)
Anne_LXM's avatar
Anne_LXM 已提交
16
    await page.callMethod('updateAutoTest',true)
17 18 19
  });

  it('Check MapMethods', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
20
    const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','addPolyline', 'addPolygons', 'addCircles','includePoint']
21 22
    for (var i = 0; i < mapMethods.length; i++) {
      await page.callMethod(mapMethods[i])
Anne_LXM's avatar
Anne_LXM 已提交
23 24 25 26
      await page.waitFor(500);
      expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
        return 'map-' + mapMethods[i]
      }});
27 28 29
      await page.waitFor(500);
    }
  });
Anne_LXM's avatar
Anne_LXM 已提交
30

31 32 33
  it('handleGetCenterLocation', async () => {
    await page.callMethod('handleGetCenterLocation')
    await page.waitFor(500);
Anne_LXM's avatar
Anne_LXM 已提交
34 35 36
    const centerLocationRes = await page.data('jestResult')
    expect(centerLocationRes.centerPoints.latitude).not.toBeNull();
    expect(centerLocationRes.centerPoints.longitude).not.toBeNull();
37
  });
Anne_LXM's avatar
Anne_LXM 已提交
38

39 40 41
  it('handleGetRegion', async () => {
    await page.callMethod('handleGetRegion')
    await page.waitFor(500);
Anne_LXM's avatar
Anne_LXM 已提交
42
    const regionRes = await page.data('jestResult')
Anne_LXM's avatar
Anne_LXM 已提交
43
    const {southwest,northeast} = regionRes;
Anne_LXM's avatar
Anne_LXM 已提交
44 45 46 47
    expect(southwest.latitude).not.toBeFalsy();
    expect(southwest.longitude).not.toBeFalsy();
    expect(northeast.latitude).not.toBeFalsy();
    expect(northeast.longitude).not.toBeFalsy();
48
  });
Anne_LXM's avatar
Anne_LXM 已提交
49 50 51 52

  it('handleTranslateMarker', async () => {
    await page.callMethod('handleTranslateMarker')
    await page.waitFor(2000);
53 54 55
    expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
        return 'map-handleTranslateMarker'
      }});
Anne_LXM's avatar
Anne_LXM 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    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())
  });

77
});