editor.test.js 3.4 KB
Newer Older
Anne_LXM's avatar
Anne_LXM 已提交
1
// uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
Anne_LXM's avatar
Anne_LXM 已提交
2
jest.setTimeout(30000);
Anne_LXM's avatar
Anne_LXM 已提交
3 4 5
const platformInfo = process.env.uniTestPlatformInfo.toLocaleLowerCase()
const isAndroid = platformInfo.startsWith('android')
const isIos = platformInfo.startsWith('ios')
Anne_LXM's avatar
Anne_LXM 已提交
6
describe('editor.uvue', () => {
Anne_LXM's avatar
Anne_LXM 已提交
7
  if (isAndroid || isIos) {
Anne_LXM's avatar
Anne_LXM 已提交
8 9 10 11 12 13 14 15 16 17 18
    it('app', () => {
      expect(1).toBe(1)
    })
    return
  }
  let page, editor, options = [];
  beforeAll(async () => {
    page = await program.reLaunch("/pages/component/editor/editor");
    await page.waitFor('view');
    editor = await page.$('#editor');
    await page.waitFor(3000);
DCloud-WZF's avatar
DCloud-WZF 已提交
19 20 21
    await page.setData({
      autoTest: true
    })
Anne_LXM's avatar
Anne_LXM 已提交
22 23
  });

Anne_LXM's avatar
Anne_LXM 已提交
24 25 26 27 28 29 30 31
  async function setBlur() {
    const start = Date.now();
    await page.callMethod('blur')
    await page.waitFor(async () => {
      return await page.data('blurTest') === true || (Date.now() - start > 2000)
    })
  }

Anne_LXM's avatar
Anne_LXM 已提交
32 33 34
  it('editor-wrapper', async () => {
    expect(await editor.attribute("placeholder")).toBe("开始输入...")
    expect(await editor.attribute("read-only")).toBe("false")
35
    expect(await program.screenshot()).toSaveImageSnapshot();
Anne_LXM's avatar
Anne_LXM 已提交
36 37 38 39 40 41 42 43 44 45
  });

  it('editor-toolbar', async () => {
    const iconfontsEl = await page.$$('.iconfont');
    for (var i = 0; i < iconfontsEl.length - 7; i++) {
      await iconfontsEl[i].tap()
      // await page.waitFor(500)
      const getFormats = await page.data('formats')
      const name = await iconfontsEl[i].attribute('data-name')
      options.push({
DCloud-WZF's avatar
DCloud-WZF 已提交
46
        insert: '文本内容' + name,
Anne_LXM's avatar
Anne_LXM 已提交
47 48 49 50 51 52 53 54 55 56 57
        attributes: getFormats
      })
      await page.callMethod('setContents', options)
      await page.setData({
        formats: {}
      })
      await iconfontsEl[i].tap()
    }
  });

  it('editor-screenshot', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
58
    await setBlur()
Anne_LXM's avatar
Anne_LXM 已提交
59
    await page.waitFor(500);
Anne_LXM's avatar
Anne_LXM 已提交
60
    expect(await program.screenshot()).toSaveImageSnapshot();
Anne_LXM's avatar
Anne_LXM 已提交
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
  })

  it('clear', async () => {
    await page.callMethod('clear')
    expect(await editor.attribute("placeholder")).toBe("开始输入...")
  })

  it('undo-redo', async () => {
    await page.callMethod('insertDivider')
    await page.waitFor(500)
    await page.callMethod('undo')
    await page.waitFor(500)
    expect(await page.data('undoTest')).toBe(true)
    await page.callMethod('redo')
    expect(await page.data('redoTest')).toBe(true)
  })

  it('insertImage', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
79
    await page.waitFor(500)
DCloud-WZF's avatar
DCloud-WZF 已提交
80
    await page.callMethod('insertImage', 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png')
Anne_LXM's avatar
Anne_LXM 已提交
81 82 83 84
    const start1 = Date.now();
    await page.waitFor(async () => {
      return await page.data('insertImageTest') === true || (Date.now() - start1 > 2000)
    })
Anne_LXM's avatar
Anne_LXM 已提交
85 86 87
  })

  it('insertImage-screenshot', async () => {
Anne_LXM's avatar
Anne_LXM 已提交
88
    await setBlur()
DCloud-WZF's avatar
DCloud-WZF 已提交
89
    const waitTime = process.env.uniTestPlatformInfo.includes('firefox') ? 5000 : 2000
Anne_LXM's avatar
Anne_LXM 已提交
90
    await page.waitFor(waitTime)
Anne_LXM's avatar
Anne_LXM 已提交
91 92 93 94
    expect(await program.screenshot()).toSaveImageSnapshot();
  })

  it('removeFormat', async () => {
DCloud-WZF's avatar
DCloud-WZF 已提交
95 96 97 98 99 100 101 102 103 104 105 106
    const bgcolorEl = await page.$('.icon-fontbgcolor');
    await bgcolorEl.tap()
    await page.waitFor(500)
    const getFormats = await page.data('formats')
    await page.callMethod('setContents', [{
      insert: '设置字体样式bgcolor',
      attributes: getFormats
    }])
    await page.waitFor(500)
    await page.callMethod('removeFormat')
    expect(await page.data('removeFormatTest')).toBe(true)
    expect(await page.data('formats')).toEqual({})
Anne_LXM's avatar
Anne_LXM 已提交
107 108 109
  })

});