storage.test.js 9.8 KB
Newer Older
1
jest.setTimeout(50000);
2

3
const PAGE_PATH = '/pages/API/storage/storage'
4 5
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isIos = platformInfo.startsWith('ios')
6 7

describe('ExtApi-StorageInfoTest', () => {
8 9 10 11 12 13 14 15
  if(
    platformInfo.indexOf('15.5') != -1 ||
    platformInfo.indexOf('14.5') != -1 ||
    platformInfo.indexOf('13.7') != -1 ||
    platformInfo.indexOf('12.4') != -1
    ){
    // TODO: 排查 ios 不兼容版本 测试异常原因
    it('ios 15.5 14.5 13.7 12.4 测试异常', () => {
16 17 18 19
      expect(1).toBe(1)
    })
    return
  }
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

  let page;
  function getData(key = '') {
    return new Promise(async (resolve, reject) => {
      const data = await page.data()
      resolve(key ? data[key] : data)
    })
  }


  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor(600);
  });

杜庆泉's avatar
杜庆泉 已提交
35 36
  it('Check async properties', async () => {
    // 异步存储测试
37 38 39 40 41 42 43 44 45 46 47 48 49
    await page.setData({
      key: "autotest_key_mock",
      data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
    })
    await page.waitFor(600)
    const btnSetStorageButtonInfo = await page.$('.btn-setstorageAsync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    const btnGetStorageButtonInfo = await page.$('.btn-getstorageAsync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
    // 测试 clear
    let btnGetStorageInfoASyncButton = await page.$('.btn-getStorageInfoASync')
    await btnGetStorageInfoASyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys[0]).toEqual("autotest_key_mock")

    const btnClearStorageInfoASyncButton = await page.$('.btn-clearStorageInfoASync')
    await btnClearStorageInfoASyncButton.tap()
    page.waitFor(600)

    await btnGetStorageInfoASyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys.length).toEqual(0)


杜庆泉's avatar
杜庆泉 已提交
67 68 69 70 71 72 73 74 75 76 77
    await page.setData({
      key: "autotest_key_mock",
      data:1100.8989
    })
    await page.waitFor(600)
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual(1100.8989)

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94

    // 测试 remove
    await btnGetStorageInfoASyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys[0]).toEqual("autotest_key_mock")

    const btnRemoveStorageInfoASyncButton = await page.$('.btn-removeStorageInfoASync')
    await btnRemoveStorageInfoASyncButton.tap()
    page.waitFor(600)

    await btnGetStorageInfoASyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys.length).toEqual(0)


杜庆泉's avatar
杜庆泉 已提交
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    await page.setData({
      key: "autotest_key_mock",
      data:123456789
    })
    await page.waitFor(600)
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual(123456789)

    let userObj = {
      name:"zhangsan",
      age:12
    }
    await page.setData({
      key: "autotest_key_mock",
      data:userObj
    })
    await page.waitFor(600)
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual(userObj)

    await page.setData({
      key: "autotest_key_mock",
123 124 125 126
      data:{
        name:"zhangsan",
        age:122
      }
杜庆泉's avatar
杜庆泉 已提交
127 128
    })
    await page.waitFor(600)
129
    await btnSetStorageButtonInfo.tap()
杜庆泉's avatar
杜庆泉 已提交
130
    await page.waitFor(600)
131
    await btnGetStorageButtonInfo.tap()
杜庆泉's avatar
杜庆泉 已提交
132
    await page.waitFor(600)
133 134 135 136
    let objRet = await getData('apiGetData')
    expect(objRet.age).toEqual(122)


杜庆泉's avatar
杜庆泉 已提交
137 138 139 140 141 142 143 144 145 146 147 148


  });


  it('Check sync properties', async () => {

    await page.setData({
      key: "autotest_key_mock",
      data:"长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。"
    })
    await page.waitFor(600)
149
    let btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
杜庆泉's avatar
杜庆泉 已提交
150 151
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
152
    let btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
杜庆泉's avatar
杜庆泉 已提交
153 154 155 156
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual("长安大道连狭斜,青牛白马七香车。玉辇纵横过主第,金鞭络绎向侯家。龙衔宝盖承朝日,凤吐流苏带晚霞。百尺游丝争绕树,一群娇鸟共啼花。游蜂戏蝶千门侧,碧树银台万种色。复道交窗作合欢,双阙连甍垂凤翼。")

157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
    // 测试clear
    const btnGetStorageInfoSyncButton = await page.$('.btn-getStorageInfoSync')
    await btnGetStorageInfoSyncButton.tap()
    await page.waitFor(600)
    let storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys[0]).toEqual("autotest_key_mock")


    const btnClearStorageInfoSyncButton = await page.$('.btn-clearStorageInfoSync')
    await btnClearStorageInfoSyncButton.tap()

    await btnGetStorageInfoSyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys.length).toEqual(0)


    await page.setData({
      key: "autotest_key_mock",
      data:12345789.235689
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual(12345789.235689)
186 187


188 189 190 191 192
    // 测试 remove
    await btnGetStorageInfoSyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys[0]).toEqual("autotest_key_mock")
193

194 195 196
    const btnRemoveStorageInfoSyncButton = await page.$('.btn-removeStorageInfoSync')
    await btnRemoveStorageInfoSyncButton.tap()
    page.waitFor(600)
197

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
    await btnGetStorageInfoSyncButton.tap()
    await page.waitFor(600)
    storageInfoRet = await getData('apiGetData')
    expect(storageInfoRet.keys.length).toEqual(0)

    await page.setData({
      key: "autotest_key_mock",
      data:0
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    expect(await getData('apiGetData')).toEqual(0)



    await page.setData({
      key: "autotest_key_mock",
      data:{
        name:"tom",
        age:10
      }
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    let objRet = await getData('apiGetData')
    expect(objRet.name).toEqual("tom")

235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
    await page.setData({
      key: "autotest_key_mock",
      data:JSON.stringify({
          name: "james",
          age: 12,
          from:"american"
      })
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    let jsonStr = await getData('apiGetData')
251 252 253 254 255 256
    // 顺序不能保证,验证长度和各个属性来区分
    let parseObj = JSON.parse(jsonStr)
    expect(jsonStr.length).toEqual(43)
    expect(parseObj['age']).toEqual(12)
    expect(parseObj['from']).toEqual('american')
    expect(parseObj['name']).toEqual('james')
257 258


259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294

    await page.setData({
      key: "autotest_key_mock",
      data:"1234567890"
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    let strRet = await getData('apiGetData')
    // 顺序不能保证,验证长度和各个属性来区分
    expect(typeof strRet).toEqual("string")
    expect(strRet).toEqual("1234567890")


    await page.setData({
      key: "autotest_key_mock",
      data:"1234567.890"
    })
    await page.waitFor(600)
    btnSetStorageButtonInfo = await page.$('.btn-setstorageSync')
    await btnSetStorageButtonInfo.tap()
    await page.waitFor(600)
    btnGetStorageButtonInfo = await page.$('.btn-getstorageSync')
    await btnGetStorageButtonInfo.tap()
    await page.waitFor(600)
    let strRet2 = await getData('apiGetData')
    // 顺序不能保证,验证长度和各个属性来区分
    expect(typeof strRet2).toEqual("string")
    expect(strRet2).toEqual("1234567.890")



295
  });
296

297
});