test: fulfill already exist tests

This commit is contained in:
07akioni 2019-06-28 14:33:55 +08:00
parent 76b3d80172
commit b502414b13
8 changed files with 164 additions and 15 deletions

View File

@ -146,12 +146,14 @@
</div>
<div class="n-doc-section__view">
<div style="padding: 14px; background: white; margin-right: 14px; border-radius: 8px;">
<n-button
type="primary"
auto-text-color
>
with-auto-text-color
</n-button>
<div>
<n-button
type="primary"
auto-text-color
>
with-auto-text-color
</n-button>
</div>
</div>
<div style="padding: 14px; background: white; border-radius: 8px;">
<n-button type="primary">

View File

@ -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",

View File

@ -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
}

View File

@ -1,3 +1,4 @@
/* istanbul ignore file */
import Icon from './src/main.vue'
Icon.install = function (Vue) {

View File

@ -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 !== ''
}
]
},

View File

@ -48,7 +48,7 @@ describe('Button', function () {
components: {
NButton
},
template: `<div style="background-color: ${backgroundColor};"><n-button auto-text-color>test</n-button></div>`
template: `<div style="background-color: ${backgroundColor};"><div><n-button auto-text-color>test</n-button></div></div>`
}
const wrapper = mount(NButtonTestContext)
expect(wrapper.element.querySelector('.n-button__content').style.color).to.equal('rgba(6, 6, 6, 0.6)')

View File

@ -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: `<n-icon type="${type}"></n-icon>`,
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: `<n-icon type="md-alert"></n-icon>`,
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: `<n-icon type="md-alert" size="40"></n-icon>`,
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: `<n-icon type="md-alert" :size="40"></n-icon>`,
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: `<n-icon type="md-alert"></n-icon>`,
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: `<n-icon type="md-alert" color="${color}"></n-icon>`,
data () {
return {
content: null
}
}
}
const wrapper = mount(NIconTestContext)
expect(wrapper.element.style.color).to.equal(color)
})
})
})

View File

@ -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
}])
})
})
})
})