map.test.js 3.4 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
  });

  it('Check EventDetail JsonStringify', async () => {
32 33 34 35 36 37 38
    if(isMP || isWeb) {
      expect(1).toBe(1)
    } else {
      const res = await page.data('jestResult')
      console.log(res.eventDetailJsonStringify);
      expect(res.eventDetailJsonStringify).not.toBe("{}");
    }
39 40
  })

雪洛's avatar
雪洛 已提交
41
  if (!isWeb && !isMP) {
42 43 44 45 46 47
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }

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

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

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

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

90

Anne_LXM's avatar
Anne_LXM 已提交
91 92 93 94 95 96 97 98 99

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