map.test.js 3.2 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
    await page.waitFor('map');
11
    // 等待地图加载完成
12 13
    const waitTime = process.env.uniTestPlatformInfo.includes('firefox') ? 5000:4000
    await page.waitFor(waitTime)
Anne_LXM's avatar
Anne_LXM 已提交
14
    await page.callMethod('updateAutoTest',true)
15 16
  });

17 18 19 20
  it('handleMoveToLocation', async () => {
    await page.callMethod('handleMoveToLocation')
    await page.waitFor(500);
    const moveToLocationRes = await page.data('jestResult')
雪洛's avatar
雪洛 已提交
21 22 23 24 25 26
    if(isMP || isWeb) {
      // TODO 使用其他信息作为测试依据
      expect(1).toBe(1)
    } else {
      expect(moveToLocationRes.moveToLocationMsg).toBe("moveToLocation:ok");
    }
27 28 29 30 31 32 33 34
  });

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

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

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

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

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

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

84

Anne_LXM's avatar
Anne_LXM 已提交
85 86 87 88 89 90 91 92 93

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