map.test.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isMP = platformInfo.startsWith('mp')
  3. const isWeb = platformInfo.startsWith('web')
  4. const isIos = platformInfo.startsWith('ios')
  5. const isHarmony = platformInfo.startsWith('harmony')
  6. let page;
  7. describe('web-map', () => {
  8. beforeAll(async () => {
  9. page = await program.reLaunch('/pages/component/map/map')
  10. await page.waitFor('view');
  11. if(!isIos && !isHarmony){
  12. await page.waitFor('map');
  13. }
  14. // 等待地图加载完成
  15. const waitTime = process.env.uniTestPlatformInfo.includes('firefox') ? 5000:4000
  16. await page.waitFor(waitTime)
  17. await page.callMethod('updateAutoTest',true)
  18. });
  19. it('handleMoveToLocation', async () => {
  20. await page.callMethod('handleMoveToLocation')
  21. await page.waitFor(500);
  22. const moveToLocationRes = await page.data('jestResult')
  23. if(isMP || isWeb) {
  24. // TODO 使用其他信息作为测试依据
  25. expect(1).toBe(1)
  26. } else {
  27. expect(moveToLocationRes.moveToLocationMsg).toBe("moveToLocation:ok");
  28. }
  29. });
  30. it('Check EventDetail JsonStringify', async () => {
  31. if(isMP || isWeb) {
  32. expect(1).toBe(1)
  33. } else {
  34. const res = await page.data('jestResult')
  35. console.log(res.eventDetailJsonStringify);
  36. expect(res.eventDetailJsonStringify).not.toBe("{}");
  37. }
  38. })
  39. if (!isWeb && !isMP) {
  40. it('app', () => {
  41. expect(1).toBe(1)
  42. })
  43. return
  44. }
  45. it('Check MapMethods', async () => {
  46. const mapMethods = ['addControls', 'addMarkers', 'addMarkersLabel','removeMarker','addPolyline','removePolyline', 'addPolygons','removePolygon', 'addCircles','removeCircle','includePoint']
  47. for (var i = 0; i < mapMethods.length; i++) {
  48. await page.callMethod(mapMethods[i])
  49. await page.waitFor(500);
  50. expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
  51. return 'map-' + mapMethods[i]
  52. }});
  53. await page.waitFor(500);
  54. }
  55. });
  56. it('handleGetCenterLocation', async () => {
  57. await page.callMethod('handleGetCenterLocation')
  58. await page.waitFor(500);
  59. const centerLocationRes = await page.data('jestResult')
  60. expect(centerLocationRes.centerPoints.latitude).not.toBeNull();
  61. expect(centerLocationRes.centerPoints.longitude).not.toBeNull();
  62. });
  63. it('handleGetRegion', async () => {
  64. await page.callMethod('handleGetRegion')
  65. await page.waitFor(500);
  66. const regionRes = await page.data('jestResult')
  67. const {southwest,northeast} = regionRes;
  68. expect(southwest.latitude).not.toBeFalsy();
  69. expect(southwest.longitude).not.toBeFalsy();
  70. expect(northeast.latitude).not.toBeFalsy();
  71. expect(northeast.longitude).not.toBeFalsy();
  72. });
  73. it('handleTranslateMarker', async () => {
  74. await page.callMethod('handleTranslateMarker')
  75. await page.waitFor(2000);
  76. expect(await program.screenshot()).toSaveImageSnapshot({customSnapshotIdentifier() {
  77. return 'map-handleTranslateMarker'
  78. }});
  79. const translateMarkerRes = await page.data('jestResult')
  80. expect(translateMarkerRes.animationEnd).toBeTruthy();
  81. if (!isMP && !isWeb) {
  82. expect(translateMarkerRes.translateMarkerMsg).toBe('translateMarker:ok');
  83. }
  84. });
  85. it('handleGetScale', async () => {
  86. await page.callMethod('handleGetScale')
  87. await page.waitFor(500);
  88. const scaleRes = await page.data('jestResult')
  89. expect(scaleRes.scale).toBeGreaterThanOrEqual(5);
  90. expect(scaleRes.scale).toBeLessThanOrEqual(18);
  91. console.log("jestResult",await page.data())
  92. });
  93. });