editor.test.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // uni-app自动化测试教程: uni-app自动化测试教程: https://uniapp.dcloud.net.cn/worktile/auto/hbuilderx-extension/
  2. jest.setTimeout(30000);
  3. describe('editor.uvue', () => {
  4. if (!process.env.uniTestPlatformInfo.includes('web')) {
  5. it('app', () => {
  6. expect(1).toBe(1)
  7. })
  8. return
  9. }
  10. let page, editor, options = [];
  11. beforeAll(async () => {
  12. page = await program.reLaunch("/pages/component/editor/editor");
  13. await page.waitFor('view');
  14. editor = await page.$('#editor');
  15. await page.waitFor(3000);
  16. await page.setData({
  17. autoTest: true
  18. })
  19. });
  20. async function setBlur() {
  21. const start = Date.now();
  22. await page.callMethod('blur')
  23. await page.waitFor(async () => {
  24. return await page.data('blurTest') === true || (Date.now() - start > 2000)
  25. })
  26. }
  27. it('editor-wrapper', async () => {
  28. expect(await editor.attribute("placeholder")).toBe("开始输入...")
  29. expect(await editor.attribute("read-only")).toBe("false")
  30. expect(await program.screenshot()).toSaveImageSnapshot();
  31. });
  32. it('editor-toolbar', async () => {
  33. const iconfontsEl = await page.$$('.iconfont');
  34. for (var i = 0; i < iconfontsEl.length - 7; i++) {
  35. await iconfontsEl[i].tap()
  36. // await page.waitFor(500)
  37. const getFormats = await page.data('formats')
  38. const name = await iconfontsEl[i].attribute('data-name')
  39. options.push({
  40. insert: '文本内容' + name,
  41. attributes: getFormats
  42. })
  43. await page.callMethod('setContents', options)
  44. await page.setData({
  45. formats: {}
  46. })
  47. await iconfontsEl[i].tap()
  48. }
  49. });
  50. it('editor-screenshot', async () => {
  51. await setBlur()
  52. await page.waitFor(500);
  53. expect(await program.screenshot()).toSaveImageSnapshot();
  54. })
  55. it('clear', async () => {
  56. await page.callMethod('clear')
  57. expect(await editor.attribute("placeholder")).toBe("开始输入...")
  58. })
  59. it('undo-redo', async () => {
  60. await page.callMethod('insertDivider')
  61. await page.waitFor(500)
  62. await page.callMethod('undo')
  63. await page.waitFor(500)
  64. expect(await page.data('undoTest')).toBe(true)
  65. await page.callMethod('redo')
  66. expect(await page.data('redoTest')).toBe(true)
  67. })
  68. it('insertImage', async () => {
  69. await page.waitFor(500)
  70. await page.callMethod('insertImage', 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/uni-app.png')
  71. const start1 = Date.now();
  72. await page.waitFor(async () => {
  73. return await page.data('insertImageTest') === true || (Date.now() - start1 > 2000)
  74. })
  75. })
  76. it('insertImage-screenshot', async () => {
  77. await setBlur()
  78. const waitTime = process.env.uniTestPlatformInfo.includes('firefox') ? 5000 : 2000
  79. await page.waitFor(waitTime)
  80. expect(await program.screenshot()).toSaveImageSnapshot();
  81. })
  82. it('removeFormat', async () => {
  83. const bgcolorEl = await page.$('.icon-fontbgcolor');
  84. await bgcolorEl.tap()
  85. await page.waitFor(500)
  86. const getFormats = await page.data('formats')
  87. await page.callMethod('setContents', [{
  88. insert: '设置字体样式bgcolor',
  89. attributes: getFormats
  90. }])
  91. await page.waitFor(500)
  92. await page.callMethod('removeFormat')
  93. expect(await page.data('removeFormatTest')).toBe(true)
  94. expect(await page.data('formats')).toEqual({})
  95. })
  96. });