show-loading.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const isIOS = platformInfo.startsWith('ios')
  4. const isHarmony = platformInfo.startsWith('harmony')
  5. const isApp = isAndroid || isIOS || isHarmony
  6. describe('API-loading', () => {
  7. let page;
  8. const screeShotParams = {
  9. deviceShot: true,
  10. fullPage: true
  11. }
  12. beforeAll(async () => {
  13. page = await program.reLaunch('/pages/API/show-loading/show-loading')
  14. await page.waitFor('view');
  15. if (isApp) {
  16. const windowInfo = await program.callUniMethod('getWindowInfo');
  17. const topSafeArea = windowInfo.safeAreaInsets.top;
  18. screeShotParams.area = {
  19. x: 0,
  20. y: topSafeArea + 44
  21. }
  22. }
  23. });
  24. async function toScreenshot(imgName) {
  25. const image = await program.screenshot(screeShotParams);
  26. expect(image).toSaveImageSnapshot({customSnapshotIdentifier() {
  27. return imgName
  28. }})
  29. await page.waitFor(500);
  30. }
  31. it('onload-loading-test', async () => {
  32. await toScreenshot('loading-onload')
  33. })
  34. it('show-loading-with-different-titles', async () => {
  35. const radios = await page.$$('.radio')
  36. for (let i = 0; i < radios.length; i++) {
  37. await radios[i].tap()
  38. await page.waitFor(100)
  39. await page.callMethod('showLoading')
  40. await page.waitFor(300)
  41. const radioText = await radios[i].text()
  42. await toScreenshot(`loading-title-${radioText}`)
  43. }
  44. })
  45. it('manual-hide-loading', async () => {
  46. await page.callMethod('showLoading')
  47. await page.waitFor(100)
  48. await toScreenshot('loading-manual-show')
  49. await page.callMethod('hideLoading')
  50. await page.waitFor(300)
  51. await toScreenshot('loading-manual-hide')
  52. })
  53. });