keep-alive.test.js 3.3 KB
Newer Older
DCloud-WZF's avatar
DCloud-WZF 已提交
1 2
const PAGE_PATH = '/pages/built-in-component/keep-alive/keep-alive'

3
describe('keep-alive', () => {
4
  if(process.env.uniTestPlatformInfo.toLocaleLowerCase().startsWith('ios')){
5 6 7 8 9 10
    it("IOS platform not support", async () => {
      expect(1).toBe(1);
    });
    return
  }
  
DCloud-WZF's avatar
DCloud-WZF 已提交
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  let page = null
  beforeAll(async () => {
    page = await program.reLaunch(PAGE_PATH)
    await page.waitFor('view')
  })
  it('keep-alive', async () => {
    const shouldExcludeBtns = await page.$$('.should-exclude-btn')
    for (let i = 0; i < shouldExcludeBtns.length; i++) {
      await shouldExcludeBtns[i].tap()
    }
    let shouldExcludeTexts = await page.$$('.should-exclude-text')
    for (let i = 0; i < shouldExcludeTexts.length; i++) {
      expect(await shouldExcludeTexts[i].text()).toBe('count: 1')
    }

    const showCounterBtn = await page.$('.show-counter')
    await showCounterBtn.tap()
28 29 30 31 32
		
		const activatedNum = await page.$('#activated-num')
    expect(await activatedNum.text()).toBe('activated num: 1')
    const deactivatedNum = await page.$('#deactivated-num')
    expect(await deactivatedNum.text()).toBe('deactivated num: 0')
DCloud-WZF's avatar
DCloud-WZF 已提交
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

    const counterBtns = await page.$$('.counter-btn')
    for (let i = 0; i < counterBtns.length; i++) {
      await counterBtns[i].tap()
    }

    const showShouldExcludeBtn = await page.$('.show-should-exclude')
    await showShouldExcludeBtn.tap()

    shouldExcludeTexts = await page.$$('.should-exclude-text')
    for (let i = 0; i < shouldExcludeTexts.length; i++) {
      if (i < shouldExcludeBtns.length - 1) {
        expect(await shouldExcludeTexts[i].text()).toBe('count: 0')
      } else {
        expect(await shouldExcludeTexts[i].text()).toBe('count: 1')
      }
    }

    await showCounterBtn.tap()

53 54 55
    expect(await activatedNum.text()).toBe('activated num: 2')
    expect(await deactivatedNum.text()).toBe('deactivated num: 1')

DCloud-WZF's avatar
DCloud-WZF 已提交
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    let counterTexts = await page.$$('.counter-text')
    for (let i = 0; i < counterTexts.length; i++) {
      expect(await counterTexts[i].text()).toBe('count: 1')
    }

    const showMessageBtn = await page.$('.show-message')
    await showMessageBtn.tap()

    const chnageMessageBtns = await page.$$('.change-message')
    for (let i = 0; i < chnageMessageBtns.length; i++) {
      await chnageMessageBtns[i].tap()
    }

    let messageTexts = await page.$$('.message-text')
    for (let i = 0; i < messageTexts.length; i++) {
      expect(await messageTexts[i].text()).toBe('msg: message changed')
    }

    await showCounterBtn.tap()

76 77 78
    expect(await activatedNum.text()).toBe('activated num: 3')
    expect(await deactivatedNum.text()).toBe('deactivated num: 2')

DCloud-WZF's avatar
DCloud-WZF 已提交
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
    counterTexts = await page.$$('.counter-text')
    for (let i = 0; i < counterTexts.length; i++) {
      expect(await counterTexts[i].text()).toBe('count: 1')
    }

    await showMessageBtn.tap()

    messageTexts = await page.$$('.message-text')
    for (let i = 0; i < messageTexts.length; i++) {
      expect(await messageTexts[i].text()).toBe('msg: message changed')
    }

    await showShouldExcludeBtn.tap()
    shouldExcludeTexts = await page.$$('.should-exclude-text')
    for (let i = 0; i < shouldExcludeTexts.length; i++) {
      expect(await shouldExcludeTexts[i].text()).toBe('count: 0')
    }
  })
})