map.test.js 3.3 KB
Newer Older
雪洛's avatar
雪洛 已提交
1 2 3
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isMP = platformInfo.startsWith('mp')
const isWeb = platformInfo.startsWith('web')
4 5
let page;
describe('web-map', () => {
6

7
  beforeAll(async () => {
8
    page = await program.reLaunch('/pages/component/map/map')
9
    await page.waitFor('view');
10 11 12
    if(!platformInfo.startsWith('ios')){
      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 20 21 22
  it('handleMoveToLocation', async () => {
    await page.callMethod('handleMoveToLocation')
    await page.waitFor(500);
    const moveToLocationRes = await page.data('jestResult')
雪洛's avatar
雪洛 已提交
23 24 25 26 27 28
    if(isMP || isWeb) {
      // TODO 使用其他信息作为测试依据
      expect(1).toBe(1)
    } else {
      expect(moveToLocationRes.moveToLocationMsg).toBe("moveToLocation:ok");
    }
29 30 31 32 33 34 35 36
  });

  it('Check EventDetail JsonStringify', async () => {
    const res = await page.data('jestResult')
    console.log(res.eventDetailJsonStringify);
    expect(res.eventDetailJsonStringify).not.toBe("{}");
  })

雪洛's avatar
雪洛 已提交
37
  if (!isWeb && !isMP) {
38 39 40 41 42 43
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }

44
  it('Check MapMethods', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
45
    const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','removeMarker','addPolyline','removePolyline', 'addPolygons','removePolygon', 'addCircles','removeCircle','includePoint']
46 47
    for (var i = 0; i < mapMethods.length; i++) {
      await page.callMethod(mapMethods[i])
Anne_LXM's avatar
Anne_LXM 已提交
48 49 50 51
      await page.waitFor(500);
      expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
        return 'map-' + mapMethods[i]
      }});
52 53 54
      await page.waitFor(500);
    }
  });
Anne_LXM's avatar
Anne_LXM 已提交
55

56 57 58
  it('handleGetCenterLocation', async () => {
    await page.callMethod('handleGetCenterLocation')
    await page.waitFor(500);
Anne_LXM's avatar
Anne_LXM 已提交
59 60 61
    const centerLocationRes = await page.data('jestResult')
    expect(centerLocationRes.centerPoints.latitude).not.toBeNull();
    expect(centerLocationRes.centerPoints.longitude).not.toBeNull();
62
  });
Anne_LXM's avatar
Anne_LXM 已提交
63

64 65 66
  it('handleGetRegion', async () => {
    await page.callMethod('handleGetRegion')
    await page.waitFor(500);
Anne_LXM's avatar
Anne_LXM 已提交
67
    const regionRes = await page.data('jestResult')
Anne_LXM's avatar
Anne_LXM 已提交
68
    const {southwest,northeast} = regionRes;
Anne_LXM's avatar
Anne_LXM 已提交
69 70 71 72
    expect(southwest.latitude).not.toBeFalsy();
    expect(southwest.longitude).not.toBeFalsy();
    expect(northeast.latitude).not.toBeFalsy();
    expect(northeast.longitude).not.toBeFalsy();
73
  });
Anne_LXM's avatar
Anne_LXM 已提交
74 75 76 77

  it('handleTranslateMarker', async () => {
    await page.callMethod('handleTranslateMarker')
    await page.waitFor(2000);
78 79 80
    expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
        return 'map-handleTranslateMarker'
      }});
Anne_LXM's avatar
Anne_LXM 已提交
81 82 83 84 85
    const translateMarkerRes = await page.data('jestResult')
    expect(translateMarkerRes.animationEnd).toBeTruthy();
    expect(translateMarkerRes.translateMarkerMsg).toBe('translateMarker:ok');
  });

86

Anne_LXM's avatar
Anne_LXM 已提交
87 88 89 90 91 92 93 94 95

  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())
  });
96
});