get-system-info.test.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
  2. const isAndroid = platformInfo.startsWith('android')
  3. const PAGE_PATH = '/pages/API/get-system-info/get-system-info'
  4. describe('ExtApi-GetSystemInfo', () => {
  5. let page;
  6. let res;
  7. const stringProperties = [
  8. 'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
  9. 'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
  10. 'model', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompilerVersion',
  11. 'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
  12. ]
  13. const numberProperties = [
  14. 'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
  15. 'windowWidth',
  16. 'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
  17. 'uniCompilerVersionCode', 'uniRuntimeVersionCode'
  18. ]
  19. const booleanProperties = [
  20. ]
  21. const requiredProperties = [
  22. 'uniCompilerVersion',
  23. 'uniCompilerVersionCode',
  24. 'uniRuntimeVersion',
  25. 'uniRuntimeVersionCode'
  26. ]
  27. beforeAll(async () => {
  28. page = await program.reLaunch(PAGE_PATH)
  29. await page.waitFor(600);
  30. res = await page.callMethod('jest_getSystemInfo')
  31. });
  32. it('Check GetSystemInfoSync', async () => {
  33. for (const key in res) {
  34. const value = res[key];
  35. console.log("key :",key , "value :", value);
  36. if (stringProperties.indexOf(key) != -1) {
  37. expect(value).not.toBeNull();
  38. expect(value).not.toBe("");
  39. }
  40. if (numberProperties.indexOf(key) != -1) {
  41. expect(value).not.toBeNull();
  42. expect(value).toBeGreaterThanOrEqual(0);
  43. }
  44. if (booleanProperties.indexOf(key) != -1) {
  45. expect(value).not.toBeNull();
  46. expect(typeof value).toBe('boolean');
  47. }
  48. if (key == 'deviceOrientation') {
  49. expect(['portrait', 'landscape']).toContain(value);
  50. }
  51. if (key == "osTheme") {
  52. expect(['light', 'dark']).toContain(value);
  53. }
  54. if (key == "appTheme") {
  55. expect(['light', 'dark', 'auto']).toContain(value);
  56. }
  57. }
  58. if (isAndroid) {
  59. if (res.safeAreaInsets.bottom > 0) {
  60. expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.screenHeight);
  61. } else {
  62. expect(res.safeAreaInsets.top + 44 + res.windowHeight).toBe(res.safeArea.bottom);
  63. }
  64. }
  65. });
  66. it('Check GetSystemInfoSync required properties', async () => {
  67. for (let i = 0; i < requiredProperties.length; i++) {
  68. const key = requiredProperties[i]
  69. expect(`${key} not null: ${res[key] != null}`).toBe(`${key} not null: true`)
  70. }
  71. })
  72. it('Check screenHeight at different stages', async ()=> {
  73. console.log("deviceOrientation ", res["deviceOrientation"]);
  74. if(res["deviceOrientation"] == "landscape"){
  75. expect(1).toBe(1)
  76. }else{
  77. await page.callMethod('jest_getScreenHeight_at_different_stages')
  78. const res = await page.data('jest_result');
  79. expect(res).toBe(true)
  80. }
  81. })
  82. });