2020-12-18 10:30:26 +08:00
|
|
|
import { nextTick, h } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2020-12-18 10:30:26 +08:00
|
|
|
import Space from '../src/index'
|
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Space.vue', () => {
|
|
|
|
test('render test', async () => {
|
|
|
|
const wrapper = mount(Space, {
|
|
|
|
slots: {
|
|
|
|
default: AXIOM,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
direction: 'vertical',
|
|
|
|
wrap: true,
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.find('.el-space--vertical').exists()).toBe(true)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-space').attributes('style')).toContain(
|
|
|
|
'flex-wrap: wrap'
|
|
|
|
)
|
2020-12-18 10:30:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('sizes', async () => {
|
|
|
|
const warnHandler = jest.fn()
|
|
|
|
const wrapper = mount(Space, {
|
|
|
|
slots: {
|
2021-09-04 19:29:28 +08:00
|
|
|
default: () =>
|
|
|
|
Array.from({ length: 2 }).map((_, idx) => {
|
|
|
|
return `test${idx}`
|
|
|
|
}),
|
2020-12-18 10:30:26 +08:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
size: 'large',
|
|
|
|
},
|
|
|
|
global: {
|
|
|
|
config: {
|
|
|
|
warnHandler,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
|
|
|
'margin-right: 16px'
|
|
|
|
)
|
2020-12-18 10:30:26 +08:00
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
size: 30,
|
|
|
|
})
|
|
|
|
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
|
|
|
'margin-right: 30px'
|
|
|
|
)
|
2020-12-18 10:30:26 +08:00
|
|
|
|
|
|
|
await wrapper.setProps({
|
|
|
|
size: [10, 20],
|
|
|
|
})
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
|
|
|
'margin-right: 10px'
|
|
|
|
)
|
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
|
|
|
'padding-bottom: 20px'
|
|
|
|
)
|
2020-12-18 10:30:26 +08:00
|
|
|
await wrapper.setProps({
|
|
|
|
size: 'unknown',
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(warnHandler).toHaveBeenCalledTimes(1)
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
|
|
|
'margin-right: 8px'
|
|
|
|
)
|
2020-12-18 10:30:26 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('should render with spacer', async () => {
|
|
|
|
const stringSpacer = '|'
|
|
|
|
const wrapper = mount(Space, {
|
|
|
|
slots: {
|
2021-09-04 19:29:28 +08:00
|
|
|
default: () =>
|
|
|
|
Array.from({ length: 2 }).map((_, idx) => {
|
|
|
|
return `test${idx}`
|
|
|
|
}),
|
2020-12-18 10:30:26 +08:00
|
|
|
},
|
|
|
|
props: {
|
|
|
|
size: 'large',
|
|
|
|
spacer: stringSpacer,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.element.children).toHaveLength(3)
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain(stringSpacer)
|
|
|
|
|
|
|
|
// 2 elements expecting only 1 spacer
|
|
|
|
expect(wrapper.text().split(stringSpacer)).toHaveLength(2)
|
|
|
|
const testSpacerCls = 'test-spacer-cls'
|
|
|
|
|
|
|
|
// vnode type spacer
|
|
|
|
await wrapper.setProps({
|
|
|
|
spacer: h('div', { class: testSpacerCls }, ''),
|
|
|
|
})
|
|
|
|
|
|
|
|
expect(wrapper.findAll(`.${testSpacerCls}`)).toHaveLength(1)
|
|
|
|
expect(wrapper.element.children).toHaveLength(3)
|
|
|
|
})
|
|
|
|
|
2021-07-30 11:39:07 +08:00
|
|
|
test('fill', async () => {
|
|
|
|
const wrapper = mount(Space, {
|
|
|
|
slots: {
|
|
|
|
default: () =>
|
|
|
|
Array.from({ length: 2 }).map((_, idx) => {
|
|
|
|
return `test${idx}`
|
|
|
|
}),
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
fill: true,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('.el-space').attributes('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'flex-wrap: wrap'
|
2021-07-30 11:39:07 +08:00
|
|
|
)
|
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'flex-grow: 1'
|
2021-07-30 11:39:07 +08:00
|
|
|
)
|
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'min-width: 100%'
|
2021-07-30 11:39:07 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
// custom fill ratio
|
|
|
|
await wrapper.setProps({
|
|
|
|
fillRatio: 50,
|
|
|
|
})
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('.el-space__item').attributes('style')).toContain(
|
2021-09-04 19:29:28 +08:00
|
|
|
'min-width: 50%'
|
2021-07-30 11:39:07 +08:00
|
|
|
)
|
|
|
|
})
|
2020-12-18 10:30:26 +08:00
|
|
|
})
|