From b502414b13d1a53f60d790cd804eae091a14b7c4 Mon Sep 17 00:00:00 2001
From: 07akioni <07akioni2@gmail.com>
Date: Fri, 28 Jun 2019 14:33:55 +0800
Subject: [PATCH] test: fulfill already exist tests
---
demo/components/buttonDemo.vue | 14 ++-
package.json | 1 +
packages/common/Button/src/main.vue | 2 +-
packages/common/Icon/index.js | 1 +
packages/common/Icon/src/main.vue | 7 +-
.../packages/common/Button/index.spec.js | 2 +-
.../specs/packages/common/Icon/index.spec.js | 111 ++++++++++++++++++
.../packages/common/Pagination/index.spec.js | 41 ++++++-
8 files changed, 164 insertions(+), 15 deletions(-)
create mode 100644 test/unit/specs/packages/common/Icon/index.spec.js
diff --git a/demo/components/buttonDemo.vue b/demo/components/buttonDemo.vue
index 18b00ed01..362e7c7b9 100644
--- a/demo/components/buttonDemo.vue
+++ b/demo/components/buttonDemo.vue
@@ -146,12 +146,14 @@
-
- with-auto-text-color
-
+
+
+ with-auto-text-color
+
+
diff --git a/package.json b/package.json
index 231b340f5..d28a22d93 100644
--- a/package.json
+++ b/package.json
@@ -45,6 +45,7 @@
"iview": "^3.4.2",
"jsdom": "^15.1.1",
"karma": "^4.1.0",
+ "karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.2",
"karma-jsdom-launcher": "^7.1.0",
"karma-mocha": "^1.3.0",
diff --git a/packages/common/Button/src/main.vue b/packages/common/Button/src/main.vue
index e2c2bacdc..bcbaac7f3 100644
--- a/packages/common/Button/src/main.vue
+++ b/packages/common/Button/src/main.vue
@@ -68,7 +68,7 @@ export default {
while (cursor.parentElement) {
cursor = cursor.parentElement
const backgroundColor = getComputedStyle(cursor).backgroundColor
- if (backgroundColor !== 'rgba(0, 0, 0, 0)') {
+ if (backgroundColor && backgroundColor !== 'rgba(0, 0, 0, 0)') {
this.style = {
color: backgroundColor
}
diff --git a/packages/common/Icon/index.js b/packages/common/Icon/index.js
index aefd473a7..778b93258 100644
--- a/packages/common/Icon/index.js
+++ b/packages/common/Icon/index.js
@@ -1,3 +1,4 @@
+/* istanbul ignore file */
import Icon from './src/main.vue'
Icon.install = function (Vue) {
diff --git a/packages/common/Icon/src/main.vue b/packages/common/Icon/src/main.vue
index 449c4ac01..559a1a151 100644
--- a/packages/common/Icon/src/main.vue
+++ b/packages/common/Icon/src/main.vue
@@ -22,18 +22,13 @@ export default {
color: {
type: String,
default: null
- },
- custom: {
- type: String,
- default: ''
}
},
computed: {
classes () {
return [
{
- [`${prefixCls}-${this.type}`]: this.type !== '',
- [`${this.custom}`]: this.custom !== ''
+ [`${prefixCls}-${this.type}`]: this.type !== ''
}
]
},
diff --git a/test/unit/specs/packages/common/Button/index.spec.js b/test/unit/specs/packages/common/Button/index.spec.js
index 1979a2005..6183f7f0b 100644
--- a/test/unit/specs/packages/common/Button/index.spec.js
+++ b/test/unit/specs/packages/common/Button/index.spec.js
@@ -48,7 +48,7 @@ describe('Button', function () {
components: {
NButton
},
- template: `test
`
+ template: ``
}
const wrapper = mount(NButtonTestContext)
expect(wrapper.element.querySelector('.n-button__content').style.color).to.equal('rgba(6, 6, 6, 0.6)')
diff --git a/test/unit/specs/packages/common/Icon/index.spec.js b/test/unit/specs/packages/common/Icon/index.spec.js
new file mode 100644
index 000000000..5e2e2f49a
--- /dev/null
+++ b/test/unit/specs/packages/common/Icon/index.spec.js
@@ -0,0 +1,111 @@
+import NIcon from 'packages/common/Icon'
+import { mount, createLocalVue } from '@vue/test-utils'
+import { expect } from 'chai'
+
+describe('Icon', function () {
+ const localVue = createLocalVue()
+ describe('props.type', function () {
+ it('should set class name when `type` is set', function () {
+ const type = 'md-alert'
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(Array.from(wrapper.element.classList).some(className => 1 + className.search(type)))
+ })
+ })
+ describe('props.size', function () {
+ it('should not set font-size when `size` is not set', function () {
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(wrapper.element.style.fontSize).to.equal('')
+ })
+ it('should set font-size when `size` is set as String', function () {
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(wrapper.element.style.fontSize).to.equal('40px')
+ })
+ it('should set font-size when `size` is set as Number', function () {
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(wrapper.element.style.fontSize).to.equal('40px')
+ })
+ })
+ describe('props.color', function () {
+ it('should not set font-size when `color` is not set', function () {
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(wrapper.element.style.color).to.equal('')
+ })
+ it('should set font-size when `color` is set', function () {
+ const color = 'rgba(111, 111, 111, 0.1)'
+ const NIconTestContext = {
+ localVue,
+ components: {
+ NIcon
+ },
+ template: ``,
+ data () {
+ return {
+ content: null
+ }
+ }
+ }
+ const wrapper = mount(NIconTestContext)
+ expect(wrapper.element.style.color).to.equal(color)
+ })
+ })
+})
diff --git a/test/unit/specs/packages/common/Pagination/index.spec.js b/test/unit/specs/packages/common/Pagination/index.spec.js
index 1c3cf7484..5ec63df9c 100644
--- a/test/unit/specs/packages/common/Pagination/index.spec.js
+++ b/test/unit/specs/packages/common/Pagination/index.spec.js
@@ -1,4 +1,4 @@
-import { pagesToShow, mapPagesToPageItems } from 'packages/common/Pagination/src/utils'
+import { pagesToShow, mapPagesToPageItems, pageItems } from 'packages/common/Pagination/src/utils'
import { expect } from 'chai'
describe('Pagination', function () {
@@ -82,5 +82,44 @@ describe('Pagination', function () {
])
})
})
+ describe('#pageItems', function () {
+ it('should work', function () {
+ expect(pageItems(5, 9)).to.deep.equal([{
+ type: 'page',
+ label: 1,
+ active: false
+ }, {
+ type: 'fastBackward',
+ label: 'fastBackward'
+ }, {
+ type: 'page',
+ label: 3,
+ active: false
+ }, {
+ type: 'page',
+ label: 4,
+ active: false
+ }, {
+ type: 'page',
+ label: 5,
+ active: true
+ }, {
+ type: 'page',
+ label: 6,
+ active: false
+ }, {
+ type: 'page',
+ label: 7,
+ active: false
+ }, {
+ type: 'fastForward',
+ label: 'fastForward'
+ }, {
+ type: 'page',
+ label: 9,
+ active: false
+ }])
+ })
+ })
})
})