get-system-info.test.js 2.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
const PAGE_PATH = '/pages/API/get-system-info/get-system-info'

describe('ExtApi-GetSystemInfo', () => {

  let page;
  let res;
  const stringProperties = [
    'appId', 'appLanguage', 'appName', 'appVersion', 'appVersionCode',
    'brand', 'deviceId', 'deviceBrand', 'deviceModel', 'deviceType', 'language',
    'model', 'osName', 'osVersion', 'osLanguage', 'platform', 'system', 'ua', 'uniCompilerVersion',
    'uniPlatform', 'uniRuntimeVersion', 'romName', 'romVersion',
  ]
  const numberProperties = [
    'osAndroidAPILevel', 'devicePixelRatio', 'pixelRatio', 'screenWidth', 'screenHeight', 'statusBarHeight',
    'windowWidth',
    'windowHeight', 'windowTop', 'windowBottom', 'screenTop',
    'uniCompilerVersionCode', 'uniRuntimeVersionCode'
18 19 20 21 22 23 24
  ]
  const booleanProperties = [
  ]
  const requiredProperties = [
    'uniCompilerVersion',
    'uniCompilerVersionCode',
    'uniRuntimeVersion',
25 26 27 28 29 30 31 32 33 34 35 36 37
    'uniRuntimeVersionCode'
  ]

  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(600);
    res = await page.callMethod('jest_getSystemInfo')
  });
  it('Check GetSystemInfoSync', async () => {
    for (const key in res) {
      const value = res[key];
      console.log("key :",key , "value :", value);
      if (stringProperties.indexOf(key) != -1) {
38
        expect(value).not.toBeNull();
39 40 41
        expect(value).not.toBe("");
      }
      if (numberProperties.indexOf(key) != -1) {
42
        expect(value).not.toBeNull();
43 44 45
        expect(value).toBeGreaterThanOrEqual(0);
      }
      if (booleanProperties.indexOf(key) != -1) {
46
        expect(value).not.toBeNull();
47 48 49 50
        expect(typeof value).toBe('boolean');
      }
      if (key == 'deviceOrientation') {
        expect(['portrait', 'landscape']).toContain(value);
taohebin@dcloud.io's avatar
taohebin@dcloud.io 已提交
51 52 53 54
      }
      if (key == "osTheme") {
        expect(['light', 'dark']).toContain(value);
      }
55 56 57
      if (key == "appTheme") {
        expect(['light', 'dark', 'auto']).toContain(value);
      }
58
    }
59 60 61 62 63 64
  });
  it('Check GetSystemInfoSync required properties', async () => {
    for (let i = 0; i < requiredProperties.length; i++) {
      const key = requiredProperties[i]
      expect(`${key} not null: ${res[key] != null}`).toBe(`${key} not null: true`)
    }
65
  })
66 67 68 69 70 71

  it('Check screenHeight at different stages', async ()=> {
    await page.callMethod('jest_getScreenHeight_at_different_stages')
    res = await page.data('jest_result');
    expect(res).toBe(true)
  })
72
});