Skip to content

Commit

Permalink
update for test
Browse files Browse the repository at this point in the history
  • Loading branch information
wangsongc committed Jan 30, 2021
1 parent 6a130e1 commit f6cef4d
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 103 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gha.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI
on:
push:
branches: [ test-framework ]
branches: [ master ]
pull_request:
branches: [ test-framework ]
branches: [ master ]

jobs:
build:
Expand All @@ -18,4 +18,4 @@ jobs:
npm run lint
- name: run test
run: |
npm run test
npm run test
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
194 changes: 98 additions & 96 deletions tests/unit/button.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: " " })
})
Expand All @@ -37,139 +40,139 @@ describe.only('toolbars测试', () => {
})

it('粗体按钮', async () => {
let buttonClass = '.op-icon.fa.fa-mavon-bold'
let eInputValue = '**粗体**'
let eHtmlValue = '<p><strong>粗体</strong></p>'
buttonClass = '.op-icon.fa.fa-mavon-bold'
textValue = '**粗体**'
htmlValue = '<p><strong>粗体</strong></p>'
expect.assertions(6)
await checkButton(buttonClass, eInputValue, eHtmlValue)
eInputValue = '粗体'
eHtmlValue = '<p>粗体</p>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
await checkButton(buttonClass, textValue, htmlValue)
textValue = '粗体'
htmlValue = '<p>粗体</p>'
await checkButton(buttonClass, textValue, htmlValue)
})

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

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

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

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

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

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

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

it('下角标按钮', async () => {
let buttonClass = '.op-icon.fa.fa-mavon-subscript'
let eInputValue = '~下角标~'
let eHtmlValue = '<p><sub>下角标</sub></p>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '~下角标~'
let htmlValue = '<p><sub>下角标</sub></p>'
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 = '<div class="hljs-left">\n<p>居左</p>\n</div>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '::: hljs-left\n\n居左\n\n:::'
let htmlValue = '<div class="hljs-left">\n<p>居左</p>\n</div>'
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 = '<div class="hljs-center">\n<p>居中</p>\n</div>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '::: hljs-center\n\n居中\n\n:::'
let htmlValue = '<div class="hljs-center">\n<p>居中</p>\n</div>'
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 = '<div class="hljs-right">\n<p>居右</p>\n</div>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '::: hljs-right\n\n居右\n\n:::'
let htmlValue = '<div class="hljs-right">\n<p>居右</p>\n</div>'
await checkButton(buttonClass, textValue, htmlValue)
})

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

it('有序列表', async () => {
let buttonClass = '.op-icon.fa.fa-mavon-list-ol'
let eInputValue = '1.'
let eHtmlValue = '<ol>\n<li></li>\n</ol>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '1.'
let htmlValue = '<ol>\n<li></li>\n</ol>'
await checkButton(buttonClass, textValue, htmlValue)
})

it('无序列表', async () => {
let buttonClass = '.op-icon.fa.fa-mavon-list-ul'
let eInputValue = '-'
let eHtmlValue = '<ul>\n<li></li>\n</ul>'
let textValue = '-'
let htmlValue = '<ul>\n<li></li>\n</ul>'

await checkButton(buttonClass, eInputValue, eHtmlValue)
await checkButton(buttonClass, textValue, htmlValue)
})

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 = '<p><a href=\"http://xxx.com\" target=\"_blank\">mylink</a></p>'
let textValue = '[mylink](http://xxx.com)'
let htmlValue = '<p><a href=\"http://xxx.com\" target=\"_blank\">mylink</a></p>'

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 () => {
Expand All @@ -178,30 +181,30 @@ 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 = '<p><img src="http://xxx.com" alt="mylink" /></p>'
let textValue = '![mylink](http://xxx.com)'
let htmlValue = '<p><img src="http://xxx.com" alt="mylink" /></p>'

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)
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 = '<pre><code class="lang-">language\n\n</code></pre>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
let textValue = '```\nlanguage\n\n```'
let htmlValue = '<pre><code class="lang-">language\n\n</code></pre>'
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 = '<table>\n' +
let textValue = `|column1|column2|column3|\n|-|-|-|\n|content1|content2|content3|`
let htmlValue = '<table>\n' +
'<thead>\n' +
'<tr>\n' +
'<th>column1</th>\n' +
Expand All @@ -217,36 +220,35 @@ describe.only('toolbars测试', () => {
'</tr>\n' +
'</tbody>\n' +
'</table>'
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 = '<p>first</p>'
let textValue = 'first'
let htmlValue = '<p>first</p>'
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 = '<p>second</p>'
await checkButton(buttonClass, eInputValue, eHtmlValue)
textValue = 'second'
htmlValue = '<p>second</p>'
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)
})
})
})

0 comments on commit f6cef4d

Please sign in to comment.