mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
* refactor(style): adjust component size to large/default/small * refactor(components): avatar size & use flex instead of block * refactor(components): adjust check button size * refactor(components): adjust tag size * refactor(components): adjust size doc * fix(components): datetime-picker demo style width * refactor(components): color-picker size & block to flex * refactor(components): adjust slider input size * refactor(components): adjust radio input size for demo * refactor(components): adjust select size & docs * refactor(components): adjust form radio size & docs * refactor(components): add windicss for docs * refactor(components): adjust skeleton avatar size to css var * refactor(components): simplify typography size demo * refactor(components): adjust dropdown size & demo * refactor(components): adjust descriptions size * fix(components): datetime-picker showcase class pollute global button * chore(ci): upgrade docs dependencies to fix ci * fix(ci): add highlight because vitepress not export it * fix(ci): disable line for no-console * fix(ci): remove mini to fix test * fix(style): code font size * fix(style): button span flex style * fix(style): button padding horizontal default 15px * refactor(components): adjust tag padding size & demo * refactor(components): adjust form line-height for input * refactor(components): adjust dropdown menu size & button padding * fix(style): picker separator block to flex center * fix: dropdown button span items-center * style: adjust input-with-icon & size demo & fix input vitepress load * chore: upgrade dependencies * chore: upgrade dependencies * ci: fix website build * ci: regenerate pnpm-lock.yaml * ci: use dev pnpm-lock * ci: update pnpm-lock.yaml
185 lines
4.8 KiB
TypeScript
185 lines
4.8 KiB
TypeScript
import { ref, h, nextTick } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { Loading, Search } from '@element-plus/icons-vue'
|
|
import Button from '../src/button.vue'
|
|
import ButtonGroup from '../src/button-group.vue'
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
describe('Button.vue', () => {
|
|
it('create', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { type: 'primary' },
|
|
})
|
|
expect(wrapper.classes()).toContain('el-button--primary')
|
|
})
|
|
|
|
it('icon', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { icon: Search },
|
|
})
|
|
expect(wrapper.findComponent(Search).exists()).toBeTruthy()
|
|
})
|
|
it('nativeType', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { nativeType: 'submit' },
|
|
})
|
|
expect(wrapper.attributes('type')).toBe('submit')
|
|
})
|
|
it('loading', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { loading: true },
|
|
})
|
|
expect(wrapper.classes()).toContain('is-loading')
|
|
expect(wrapper.findComponent(Loading).exists()).toBeTruthy()
|
|
})
|
|
it('size', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { size: 'default' },
|
|
})
|
|
expect(wrapper.classes()).toContain('el-button--default')
|
|
})
|
|
it('plain', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { plain: true },
|
|
})
|
|
expect(wrapper.classes()).toContain('is-plain')
|
|
})
|
|
it('round', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { round: true },
|
|
})
|
|
expect(wrapper.classes()).toContain('is-round')
|
|
})
|
|
it('circle', () => {
|
|
const wrapper = mount(Button, {
|
|
props: { circle: true },
|
|
})
|
|
expect(wrapper.classes()).toContain('is-circle')
|
|
})
|
|
|
|
test('render text', () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: AXIOM,
|
|
},
|
|
})
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
})
|
|
|
|
test('handle click', async () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: AXIOM,
|
|
},
|
|
})
|
|
await wrapper.trigger('click')
|
|
expect(wrapper.emitted()).toBeDefined()
|
|
})
|
|
|
|
test('handle click inside', async () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: '<span class="inner-slot"></span>',
|
|
},
|
|
})
|
|
await (<HTMLElement>wrapper.element.querySelector('.inner-slot')).click()
|
|
expect(wrapper.emitted()).toBeDefined()
|
|
})
|
|
|
|
test('loading implies disabled', async () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: AXIOM,
|
|
},
|
|
props: { loading: true },
|
|
})
|
|
await wrapper.trigger('click')
|
|
expect(wrapper.emitted('click')).toBeUndefined()
|
|
})
|
|
|
|
it('disabled', async () => {
|
|
const wrapper = mount(Button, {
|
|
props: { disabled: true },
|
|
})
|
|
expect(wrapper.classes()).toContain('is-disabled')
|
|
await wrapper.trigger('click')
|
|
expect(wrapper.emitted('click')).toBeUndefined()
|
|
})
|
|
})
|
|
describe('Button Group', () => {
|
|
it('create', () => {
|
|
const wrapper = mount({
|
|
template: `
|
|
<el-button-group>
|
|
<el-button type="primary">Prev</el-button>
|
|
<el-button type="primary">Next</el-button>
|
|
</el-button-group>`,
|
|
components: {
|
|
'el-button-group': ButtonGroup,
|
|
'el-button': Button,
|
|
},
|
|
})
|
|
expect(wrapper.classes()).toContain('el-button-group')
|
|
expect(wrapper.findAll('button').length).toBe(2)
|
|
})
|
|
|
|
it('button group reactive size', async () => {
|
|
const size = ref('small')
|
|
const wrapper = mount({
|
|
setup() {
|
|
return () =>
|
|
h(ButtonGroup, { size: size.value }, () => [
|
|
h(Button, { type: 'primary' }, () => 'Prev'),
|
|
h(Button, { type: 'primary' }, () => 'Next'),
|
|
])
|
|
},
|
|
})
|
|
expect(wrapper.classes()).toContain('el-button-group')
|
|
expect(
|
|
wrapper.findAll('.el-button-group button.el-button--small').length
|
|
).toBe(2)
|
|
|
|
size.value = 'default'
|
|
await nextTick()
|
|
|
|
expect(
|
|
wrapper.findAll('.el-button-group button.el-button--default').length
|
|
).toBe(2)
|
|
})
|
|
|
|
it('button group type', async () => {
|
|
const wrapper = mount({
|
|
setup() {
|
|
return () =>
|
|
h(ButtonGroup, { type: 'warning' }, () => [
|
|
h(Button, { type: 'primary' }, () => 'Prev'),
|
|
h(Button, {}, () => 'Next'),
|
|
])
|
|
},
|
|
})
|
|
expect(wrapper.classes()).toContain('el-button-group')
|
|
expect(
|
|
wrapper.findAll('.el-button-group button.el-button--primary').length
|
|
).toBe(1)
|
|
expect(
|
|
wrapper.findAll('.el-button-group button.el-button--warning').length
|
|
).toBe(1)
|
|
})
|
|
|
|
it('add space in two Chinese characters', async () => {
|
|
const wrapper = mount(Button, {
|
|
slots: {
|
|
default: '中文',
|
|
},
|
|
props: {
|
|
autoInsertSpace: true,
|
|
},
|
|
})
|
|
expect(wrapper.find('.el-button span').text()).toBe('中文')
|
|
expect(wrapper.find('.el-button span').classes()).toContain(
|
|
'el-button__text--expand'
|
|
)
|
|
})
|
|
})
|