get-window-info.test.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const PAGE_PATH = '/pages/API/get-window-info/get-window-info'
  4. describe('ExtApi-GetWindowInfo', () => {
  5. let page;
  6. let res;
  7. const numberProperties = [
  8. 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
  9. 'windowWidth',
  10. 'windowHeight', 'windowTop', 'windowBottom', 'screenTop'
  11. ]
  12. beforeAll(async () => {
  13. page = await program.reLaunch(PAGE_PATH)
  14. await page.waitFor(600);
  15. res = await program.callUniMethod('getWindowInfo');
  16. });
  17. it('Check GetWindowInfo', async () => {
  18. for (const key in res) {
  19. const value = res[key];
  20. expect(value).not.toBeNull();
  21. if (numberProperties.indexOf(key) != -1) {
  22. expect(value).toBeGreaterThanOrEqual(0);
  23. }
  24. }
  25. if (isAndroid) {
  26. if (res.safeAreaInsets.bottom > 0) {
  27. expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.screenHeight);
  28. } else {
  29. expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.safeArea.bottom);
  30. }
  31. }
  32. });
  33. });