mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-09 04:31:35 +08:00
test: fulfill already exist tests
This commit is contained in:
parent
76b3d80172
commit
b502414b13
@ -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">
|
||||
|
@ -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",
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/* istanbul ignore file */
|
||||
import Icon from './src/main.vue'
|
||||
|
||||
Icon.install = function (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 !== ''
|
||||
}
|
||||
]
|
||||
},
|
||||
|
@ -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)')
|
||||
|
111
test/unit/specs/packages/common/Icon/index.spec.js
Normal file
111
test/unit/specs/packages/common/Icon/index.spec.js
Normal 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)
|
||||
})
|
||||
})
|
||||
})
|
@ -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
|
||||
}])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user