From b369fb43b2cbecf361cf33451b14b59d493f7269 Mon Sep 17 00:00:00 2001 From: wangsongc Date: Wed, 27 Jan 2021 18:15:07 +0800 Subject: [PATCH 1/4] Add test framework --- .babelrc | 9 +++ .gitignore | 1 + jest.config.js | 28 +++++++++ package.json | 10 ++- .../__snapshots__/mavon-editor.spec.js.snap | 63 +++++++++++++++++++ tests/unit/mavon-editor.spec.js | 23 +++++++ 6 files changed, 133 insertions(+), 1 deletion(-) create mode 100644 jest.config.js create mode 100644 tests/unit/__snapshots__/mavon-editor.spec.js.snap create mode 100644 tests/unit/mavon-editor.spec.js diff --git a/.babelrc b/.babelrc index 205758282..a4644f906 100644 --- a/.babelrc +++ b/.babelrc @@ -3,8 +3,17 @@ ["env", { "modules": false }], + [ + "babel-preset-env", + { + "targets": { + "node": "current" + } + } + ], "stage-2" ], + "plugins": ["transform-runtime"], "comments": false } diff --git a/.gitignore b/.gitignore index bc39f0063..3c8ab6932 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ package-lock.json .DS_Store .ftpconfig *.swp +/tests/unit/coverage/* diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..e282da1c9 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,28 @@ +module.exports = { + transformIgnorePatterns: ["/node_modules/(?!auto-textarea|@vue|src)"], + testMatch: [ + "**/tests/unit/*.spec.js" + ], + verbose: true, + moduleFileExtensions: ['js', 'vue', 'md', 'html'], + moduleNameMapper: { + '\\.(css|scss)$': 'identity-obj-proxy', + '^@/(.*)$': '/src/$1' + }, + transform: { + "^.+\\.js$": "/node_modules/babel-jest", + "^.+\\.vue$": "/node_modules/vue-jest", + '.*\\.(yml|html|md)$': 'jest-raw-loader' + }, + // setupFiles: ['/tests/unit/setup.js'], + coverageDirectory: '/tests/unit/coverage', + collectCoverageFrom: [ + 'src/**/*.{js,vue}', + '!src/main.js', + '!src/dev/**', + '!**/node_modules/**' + ], + snapshotSerializers: [ + "jest-serializer-vue" + ] +} diff --git a/package.json b/package.json index 57ca9f626..b0362644f 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "dist/mavon-editor.js", "types": "./mavon-editor.d.ts", "scripts": { - "test": "echo true", + "test": "jest", + "test:coverage": "jest --coverage", "dev": "webpack-dev-server --open --progress --config webpack/webpack.dev.js", "build": "webpack --progress --config webpack/webpack.build.js", "lint:fix": "eslint --fix --ext .js,.vue src/", @@ -34,11 +35,13 @@ "xss": "^1.0.6" }, "devDependencies": { + "@vue/test-utils": "^1.1.2", "auto-textarea": "^1.4.0", "autoprefixer": "^8.3.0", "axios": "^0.19.0", "babel-core": "^6.0.0", "babel-eslint": "^8.0.2", + "babel-jest": "^23.6.0", "babel-loader": "^7.0.0", "babel-plugin-transform-runtime": "^6.23.0", "babel-polyfill": "^6.26.0", @@ -58,6 +61,10 @@ "github-markdown-css": "^2.6.0", "html-loader": "^0.4.5", "html-webpack-plugin": "^2.28.0", + "identity-obj-proxy": "^3.0.0", + "jest": "^23.6.0", + "jest-raw-loader": "^1.0.1", + "jest-serializer-vue": "^2.0.2", "katex": "^0.11.1", "keycode": "^2.1.9", "less": "^2.7.2", @@ -104,6 +111,7 @@ "stylus-loader": "^2.4.0", "url-loader": "^0.5.8", "vue": "^2.3.4", + "vue-jest": "^3.0.7", "vue-loader": "^12.0.3", "vue-style-loader": "^3.0.0", "vue-template-compiler": "^2.2.1", diff --git a/tests/unit/__snapshots__/mavon-editor.spec.js.snap b/tests/unit/__snapshots__/mavon-editor.spec.js.snap new file mode 100644 index 000000000..0b33fa4d5 --- /dev/null +++ b/tests/unit/__snapshots__/mavon-editor.spec.js.snap @@ -0,0 +1,63 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snapshot snapshot 1`] = ` +
+
+
+ + + + + +
+
+
+
+
+
+

+
+
+
+
+ +
+ + + +
+ + + + +
+
+
+
+`; diff --git a/tests/unit/mavon-editor.spec.js b/tests/unit/mavon-editor.spec.js new file mode 100644 index 000000000..ac63b40cd --- /dev/null +++ b/tests/unit/mavon-editor.spec.js @@ -0,0 +1,23 @@ +import { mount } from '@vue/test-utils' +import MavonEditor from '@/mavon-editor.vue' +import autoTextarea from 'auto-textarea/auto-textarea.vue' + +/*eslint-disable */ +const factory = (propsData) => { + return mount(MavonEditor, { + propsData: { + ...propsData + }, + stubs: { + "v-autoTextarea": autoTextarea + } + }) +} + +describe('snapshot', () => { + it('snapshot', () => { + const wrapper = new factory() + expect(wrapper.html()).toMatchSnapshot() + }) +}) + From 3303f1e8e56c4d8c24c87e91699b71fa7c1ed250 Mon Sep 17 00:00:00 2001 From: wangsongc Date: Fri, 29 Jan 2021 17:44:17 +0800 Subject: [PATCH 2/4] add left-toolbars test --- tests/unit/button.spec.js | 252 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 252 insertions(+) create mode 100644 tests/unit/button.spec.js diff --git a/tests/unit/button.spec.js b/tests/unit/button.spec.js new file mode 100644 index 000000000..9dd47e078 --- /dev/null +++ b/tests/unit/button.spec.js @@ -0,0 +1,252 @@ +import { mount } from '@vue/test-utils' +import MavonEditor from '@/mavon-editor.vue' +import autoTextarea from 'auto-textarea/auto-textarea.vue' + +/*eslint-disable */ +const factory = (propsData, mocks) => { + return mount(MavonEditor, { + propsData: { + ...propsData + }, + mocks: { + ...mocks + }, + stubs: { + "v-autoTextarea": autoTextarea + } + }) +} +let textValueClass = '.auto-textarea-block' +let htmlValueClass = '.v-show-content-html.scroll-style.scroll-style-border-radius' +describe.only('toolbars测试', () => { + let wrapper + function checkButton(buttonClass, inputValue, htmlValue) { + expect(wrapper.find(buttonClass).exists()).toBe(true) + wrapper.find(buttonClass).trigger('click') + wrapper.vm.$nextTick(() => { + expect(wrapper.find(textValueClass).text()).toEqual(inputValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue) + }) + } + + beforeEach(() => { + wrapper = new factory({ d_words: null, value: " " }) + }) + afterEach(() => { + wrapper.destroy() + }) + + it('粗体按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-bold' + let eInputValue = '**粗体**' + let eHtmlValue = '

粗体

' + expect.assertions(6) + await checkButton(buttonClass, eInputValue, eHtmlValue) + eInputValue = '粗体' + eHtmlValue = '

粗体

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('斜体按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-italic' + let eInputValue = '*斜体*' + let eHtmlValue = '

斜体

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + eInputValue = '斜体' + eHtmlValue = '

斜体

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('标题按钮', async () => { + let buttonClass = '.op-header.popup-dropdown.transition span' + let eInputValue = '# 一级标题' + let eHtmlValue = '

一级标题

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('下划线按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-underline' + let eInputValue = '++下划线++' + let eHtmlValue = '

下划线

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + eInputValue = '下划线' + eHtmlValue = '

下划线

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('下划线按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-underline' + let eInputValue = '++下划线++' + let eHtmlValue = '

下划线

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('中划线按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-strikethrough' + let eInputValue = '~~中划线~~' + let eHtmlValue = '

中划线

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('标记按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-thumb-tack' + let eInputValue = '==标记==' + let eHtmlValue = '

标记

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('上角标按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-superscript' + let eInputValue = '^上角标^' + let eHtmlValue = '

上角标

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('下角标按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-subscript' + let eInputValue = '~下角标~' + let eHtmlValue = '

下角标

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('居左按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-align-left' + let eInputValue = '::: hljs-left\n\n居左\n\n:::' + let eHtmlValue = '
\n

居左

\n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('居中按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-align-center' + let eInputValue = '::: hljs-center\n\n居中\n\n:::' + let eHtmlValue = '
\n

居中

\n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('居右按钮', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-align-right' + let eInputValue = '::: hljs-right\n\n居右\n\n:::' + let eHtmlValue = '
\n

居右

\n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('段落引用', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-quote-left' + let eInputValue = '> 段落引用' + let eHtmlValue = '
\n

段落引用

\n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + eInputValue = '段落引用' + eHtmlValue = '

段落引用

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('有序列表', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-list-ol' + let eInputValue = '1.' + let eHtmlValue = '
    \n
  1. \n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('无序列表', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-list-ul' + let eInputValue = '-' + let eHtmlValue = '
    \n
  • \n
' + + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('链接', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-link' + let linktext = '.link-text.input-wrapper input' + let linkaddr = '.link-addr.input-wrapper input' + let surebutten = '.op-btn.sure' + let eInputValue = '[mylink](http://xxx.com)' + let eHtmlValue = '

mylink

' + + await wrapper.find(buttonClass).trigger('click') + wrapper.find(linktext).setValue('mylink') + wrapper.find(linkaddr).setValue('http://xxx.com') + await wrapper.find(surebutten).trigger('click') + + expect(wrapper.find(textValueClass).text()).toEqual(eInputValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(eHtmlValue) + }) + + it('图片链接添加', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-picture-o.dropdown.dropdown-wrapper' + let addimagelink = '.op-image.popup-dropdown.transition div span' + let linktext = '.link-text.input-wrapper input' + let linkaddr = '.link-addr.input-wrapper input' + let surebutten = '.op-btn.sure' + let eInputValue = '![mylink](http://xxx.com)' + let eHtmlValue = '

mylink

' + + await wrapper.find(buttonClass).trigger('click') + await wrapper.find(addimagelink).trigger('click') + wrapper.find(linktext).setValue('mylink') + wrapper.find(linkaddr).setValue('http://xxx.com') + await wrapper.find(surebutten).trigger('click') + + expect(wrapper.find(textValueClass).text()).toEqual(eInputValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(eHtmlValue) + }) + + it('代码块', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-code' + let eInputValue = '```\nlanguage\n\n```' + let eHtmlValue = '
language\n\n
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('表格', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-table' + let eInputValue = `|column1|column2|column3|\n|-|-|-|\n|content1|content2|content3|` + let eHtmlValue = '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '\n' + + '
column1column2column3
content1content2content3
' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('上一步/下一步', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-undo' + let eInputValue = 'first' + let eHtmlValue = '

first

' + await wrapper.setData({ + d_history: ['first', 'second', 'third'], + d_history_index: 1 + }) + + await checkButton(buttonClass, eInputValue, eHtmlValue) + buttonClass = '.op-icon.fa.fa-mavon-repeat' + eInputValue = 'second' + eHtmlValue = '

second

' + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('清空', async () => { + let buttonClass = '.op-icon.fa.fa-mavon-trash-o' + let eInputValue = '' + let eHtmlValue = '' + await wrapper.setData({ d_value: 'first' }) + await checkButton(buttonClass, eInputValue, eHtmlValue) + }) + + it('保存', () => { + let buttonClass = '.op-icon.fa.fa-mavon-trash-o' + //检查字体加粗元素是否渲染 + expect(wrapper.find(buttonClass).exists()).toBe(true) + }) +}) \ No newline at end of file From 6a130e1e846a1b2cb8869e52ce9d312017b0cd2e Mon Sep 17 00:00:00 2001 From: wangsongc Date: Fri, 29 Jan 2021 17:50:56 +0800 Subject: [PATCH 3/4] add ci --- .github/workflows/gha.yml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 .github/workflows/gha.yml diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml new file mode 100644 index 000000000..2fd3950d0 --- /dev/null +++ b/.github/workflows/gha.yml @@ -0,0 +1,21 @@ +name: CI +on: + push: + branches: [ test-framework ] + pull_request: + branches: [ test-framework ] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: install dependence + run: | + npm i + - name: run eslint + run: | + npm run lint + - name: run test + run: | + npm run test \ No newline at end of file From f6cef4d51ea8d36c5696c323df23a0e9aa0a44ee Mon Sep 17 00:00:00 2001 From: wangsongc Date: Sat, 30 Jan 2021 09:45:04 +0800 Subject: [PATCH 4/4] update for test --- .github/workflows/gha.yml | 6 +- package.json | 8 +- tests/unit/button.spec.js | 194 +++++++++++++++++++------------------- 3 files changed, 105 insertions(+), 103 deletions(-) diff --git a/.github/workflows/gha.yml b/.github/workflows/gha.yml index 2fd3950d0..46fb7a303 100644 --- a/.github/workflows/gha.yml +++ b/.github/workflows/gha.yml @@ -1,9 +1,9 @@ name: CI on: push: - branches: [ test-framework ] + branches: [ master ] pull_request: - branches: [ test-framework ] + branches: [ master ] jobs: build: @@ -18,4 +18,4 @@ jobs: npm run lint - name: run test run: | - npm run test \ No newline at end of file + npm run test diff --git a/package.json b/package.json index b0362644f..77c817217 100644 --- a/package.json +++ b/package.json @@ -5,12 +5,12 @@ "main": "dist/mavon-editor.js", "types": "./mavon-editor.d.ts", "scripts": { - "test": "jest", - "test:coverage": "jest --coverage", "dev": "webpack-dev-server --open --progress --config webpack/webpack.dev.js", "build": "webpack --progress --config webpack/webpack.build.js", - "lint:fix": "eslint --fix --ext .js,.vue src/", - "lint": "eslint --ext .js,.vue src/" + "test": "jest", + "test:coverage": "jest --coverage", + "lint": "eslint --ext .js,.vue src/", + "lint:fix": "eslint --fix --ext .js,.vue src/" }, "repository": { "type": "git", diff --git a/tests/unit/button.spec.js b/tests/unit/button.spec.js index 9dd47e078..e726cbae7 100644 --- a/tests/unit/button.spec.js +++ b/tests/unit/button.spec.js @@ -16,19 +16,22 @@ const factory = (propsData, mocks) => { } }) } -let textValueClass = '.auto-textarea-block' -let htmlValueClass = '.v-show-content-html.scroll-style.scroll-style-border-radius' -describe.only('toolbars测试', () => { - let wrapper - function checkButton(buttonClass, inputValue, htmlValue) { - expect(wrapper.find(buttonClass).exists()).toBe(true) - wrapper.find(buttonClass).trigger('click') - wrapper.vm.$nextTick(() => { - expect(wrapper.find(textValueClass).text()).toEqual(inputValue) - expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue) - }) - } - +let wrapper, + buttonClass, + textValue, + htmlValue, + textValueClass = '.auto-textarea-block', + htmlValueClass = '.v-show-content-html.scroll-style.scroll-style-border-radius' + +function checkButton(buttonClass, textValue, htmlValue) { + expect(wrapper.find(buttonClass).exists()).toBe(true) + wrapper.find(buttonClass).trigger('click') + wrapper.vm.$nextTick(() => { + expect(wrapper.find(textValueClass).text()).toEqual(textValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue) + }) +} +describe('left-toolbars测试', () => { beforeEach(() => { wrapper = new factory({ d_words: null, value: " " }) }) @@ -37,122 +40,122 @@ describe.only('toolbars测试', () => { }) it('粗体按钮', async () => { - let buttonClass = '.op-icon.fa.fa-mavon-bold' - let eInputValue = '**粗体**' - let eHtmlValue = '

粗体

' + buttonClass = '.op-icon.fa.fa-mavon-bold' + textValue = '**粗体**' + htmlValue = '

粗体

' expect.assertions(6) - await checkButton(buttonClass, eInputValue, eHtmlValue) - eInputValue = '粗体' - eHtmlValue = '

粗体

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + await checkButton(buttonClass, textValue, htmlValue) + textValue = '粗体' + htmlValue = '

粗体

' + await checkButton(buttonClass, textValue, htmlValue) }) it('斜体按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-italic' - let eInputValue = '*斜体*' - let eHtmlValue = '

斜体

' - await checkButton(buttonClass, eInputValue, eHtmlValue) - eInputValue = '斜体' - eHtmlValue = '

斜体

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '*斜体*' + let htmlValue = '

斜体

' + await checkButton(buttonClass, textValue, htmlValue) + textValue = '斜体' + htmlValue = '

斜体

' + await checkButton(buttonClass, textValue, htmlValue) }) it('标题按钮', async () => { let buttonClass = '.op-header.popup-dropdown.transition span' - let eInputValue = '# 一级标题' - let eHtmlValue = '

一级标题

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '# 一级标题' + let htmlValue = '

一级标题

' + await checkButton(buttonClass, textValue, htmlValue) }) it('下划线按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-underline' - let eInputValue = '++下划线++' - let eHtmlValue = '

下划线

' - await checkButton(buttonClass, eInputValue, eHtmlValue) - eInputValue = '下划线' - eHtmlValue = '

下划线

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '++下划线++' + let htmlValue = '

下划线

' + await checkButton(buttonClass, textValue, htmlValue) + textValue = '下划线' + htmlValue = '

下划线

' + await checkButton(buttonClass, textValue, htmlValue) }) it('下划线按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-underline' - let eInputValue = '++下划线++' - let eHtmlValue = '

下划线

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '++下划线++' + let htmlValue = '

下划线

' + await checkButton(buttonClass, textValue, htmlValue) }) it('中划线按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-strikethrough' - let eInputValue = '~~中划线~~' - let eHtmlValue = '

中划线

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '~~中划线~~' + let htmlValue = '

中划线

' + await checkButton(buttonClass, textValue, htmlValue) }) it('标记按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-thumb-tack' - let eInputValue = '==标记==' - let eHtmlValue = '

标记

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '==标记==' + let htmlValue = '

标记

' + await checkButton(buttonClass, textValue, htmlValue) }) it('上角标按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-superscript' - let eInputValue = '^上角标^' - let eHtmlValue = '

上角标

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '^上角标^' + let htmlValue = '

上角标

' + await checkButton(buttonClass, textValue, htmlValue) }) it('下角标按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-subscript' - let eInputValue = '~下角标~' - let eHtmlValue = '

下角标

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '~下角标~' + let htmlValue = '

下角标

' + await checkButton(buttonClass, textValue, htmlValue) }) it('居左按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-align-left' - let eInputValue = '::: hljs-left\n\n居左\n\n:::' - let eHtmlValue = '
\n

居左

\n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '::: hljs-left\n\n居左\n\n:::' + let htmlValue = '
\n

居左

\n
' + await checkButton(buttonClass, textValue, htmlValue) }) it('居中按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-align-center' - let eInputValue = '::: hljs-center\n\n居中\n\n:::' - let eHtmlValue = '
\n

居中

\n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '::: hljs-center\n\n居中\n\n:::' + let htmlValue = '
\n

居中

\n
' + await checkButton(buttonClass, textValue, htmlValue) }) it('居右按钮', async () => { let buttonClass = '.op-icon.fa.fa-mavon-align-right' - let eInputValue = '::: hljs-right\n\n居右\n\n:::' - let eHtmlValue = '
\n

居右

\n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '::: hljs-right\n\n居右\n\n:::' + let htmlValue = '
\n

居右

\n
' + await checkButton(buttonClass, textValue, htmlValue) }) it('段落引用', async () => { let buttonClass = '.op-icon.fa.fa-mavon-quote-left' - let eInputValue = '> 段落引用' - let eHtmlValue = '
\n

段落引用

\n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) - eInputValue = '段落引用' - eHtmlValue = '

段落引用

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '> 段落引用' + let htmlValue = '
\n

段落引用

\n
' + await checkButton(buttonClass, textValue, htmlValue) + textValue = '段落引用' + htmlValue = '

段落引用

' + await checkButton(buttonClass, textValue, htmlValue) }) it('有序列表', async () => { let buttonClass = '.op-icon.fa.fa-mavon-list-ol' - let eInputValue = '1.' - let eHtmlValue = '
    \n
  1. \n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '1.' + let htmlValue = '
    \n
  1. \n
' + await checkButton(buttonClass, textValue, htmlValue) }) it('无序列表', async () => { let buttonClass = '.op-icon.fa.fa-mavon-list-ul' - let eInputValue = '-' - let eHtmlValue = '
    \n
  • \n
' + let textValue = '-' + let htmlValue = '
    \n
  • \n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + await checkButton(buttonClass, textValue, htmlValue) }) it('链接', async () => { @@ -160,16 +163,16 @@ describe.only('toolbars测试', () => { let linktext = '.link-text.input-wrapper input' let linkaddr = '.link-addr.input-wrapper input' let surebutten = '.op-btn.sure' - let eInputValue = '[mylink](http://xxx.com)' - let eHtmlValue = '

mylink

' + let textValue = '[mylink](http://xxx.com)' + let htmlValue = '

mylink

' await wrapper.find(buttonClass).trigger('click') wrapper.find(linktext).setValue('mylink') wrapper.find(linkaddr).setValue('http://xxx.com') await wrapper.find(surebutten).trigger('click') - expect(wrapper.find(textValueClass).text()).toEqual(eInputValue) - expect(wrapper.find(htmlValueClass).text()).toEqual(eHtmlValue) + expect(wrapper.find(textValueClass).text()).toEqual(textValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue) }) it('图片链接添加', async () => { @@ -178,8 +181,8 @@ describe.only('toolbars测试', () => { let linktext = '.link-text.input-wrapper input' let linkaddr = '.link-addr.input-wrapper input' let surebutten = '.op-btn.sure' - let eInputValue = '![mylink](http://xxx.com)' - let eHtmlValue = '

mylink

' + let textValue = '![mylink](http://xxx.com)' + let htmlValue = '

mylink

' await wrapper.find(buttonClass).trigger('click') await wrapper.find(addimagelink).trigger('click') @@ -187,21 +190,21 @@ describe.only('toolbars测试', () => { wrapper.find(linkaddr).setValue('http://xxx.com') await wrapper.find(surebutten).trigger('click') - expect(wrapper.find(textValueClass).text()).toEqual(eInputValue) - expect(wrapper.find(htmlValueClass).text()).toEqual(eHtmlValue) + expect(wrapper.find(textValueClass).text()).toEqual(textValue) + expect(wrapper.find(htmlValueClass).text()).toEqual(htmlValue) }) it('代码块', async () => { let buttonClass = '.op-icon.fa.fa-mavon-code' - let eInputValue = '```\nlanguage\n\n```' - let eHtmlValue = '
language\n\n
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + let textValue = '```\nlanguage\n\n```' + let htmlValue = '
language\n\n
' + await checkButton(buttonClass, textValue, htmlValue) }) it('表格', async () => { let buttonClass = '.op-icon.fa.fa-mavon-table' - let eInputValue = `|column1|column2|column3|\n|-|-|-|\n|content1|content2|content3|` - let eHtmlValue = '\n' + + let textValue = `|column1|column2|column3|\n|-|-|-|\n|content1|content2|content3|` + let htmlValue = '
\n' + '\n' + '\n' + '\n' + @@ -217,36 +220,35 @@ describe.only('toolbars测试', () => { '\n' + '\n' + '
column1
' - await checkButton(buttonClass, eInputValue, eHtmlValue) + await checkButton(buttonClass, textValue, htmlValue) }) it('上一步/下一步', async () => { let buttonClass = '.op-icon.fa.fa-mavon-undo' - let eInputValue = 'first' - let eHtmlValue = '

first

' + let textValue = 'first' + let htmlValue = '

first

' await wrapper.setData({ d_history: ['first', 'second', 'third'], d_history_index: 1 }) - await checkButton(buttonClass, eInputValue, eHtmlValue) + await checkButton(buttonClass, textValue, htmlValue) buttonClass = '.op-icon.fa.fa-mavon-repeat' - eInputValue = 'second' - eHtmlValue = '

second

' - await checkButton(buttonClass, eInputValue, eHtmlValue) + textValue = 'second' + htmlValue = '

second

' + await checkButton(buttonClass, textValue, htmlValue) }) it('清空', async () => { let buttonClass = '.op-icon.fa.fa-mavon-trash-o' - let eInputValue = '' - let eHtmlValue = '' + let textValue = '' + let htmlValue = '' await wrapper.setData({ d_value: 'first' }) - await checkButton(buttonClass, eInputValue, eHtmlValue) + await checkButton(buttonClass, textValue, htmlValue) }) it('保存', () => { let buttonClass = '.op-icon.fa.fa-mavon-trash-o' - //检查字体加粗元素是否渲染 expect(wrapper.find(buttonClass).exists()).toBe(true) }) -}) \ No newline at end of file +})