2022-06-01 13:08:19 +08:00
|
|
|
import { nextTick, ref } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, it, test } from 'vitest'
|
2021-08-24 13:36:48 +08:00
|
|
|
import Row from '@element-plus/components/row'
|
2022-05-30 11:14:58 +08:00
|
|
|
import Col from '../src/col.vue'
|
2020-07-31 18:20:03 +08:00
|
|
|
|
|
|
|
describe('Col', () => {
|
|
|
|
it('create', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Col />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-col')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('span', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Col span={12} />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-col-12')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('pull', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Col span={12} pull={3} />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-col-pull-3')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('push', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Col span={12} push={3} />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-col-push-3')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('gutter', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
setup() {
|
|
|
|
return () => (
|
2022-03-01 23:21:42 +08:00
|
|
|
<Row gutter={20}>
|
|
|
|
<Col span={12} ref="col"></Col>
|
|
|
|
</Row>
|
2022-06-01 13:08:19 +08:00
|
|
|
)
|
|
|
|
},
|
2022-03-01 23:21:42 +08:00
|
|
|
})
|
2022-06-01 13:08:19 +08:00
|
|
|
|
2020-07-31 18:20:03 +08:00
|
|
|
const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement
|
|
|
|
expect(colElm.style.paddingLeft === '10px').toBe(true)
|
|
|
|
expect(colElm.style.paddingRight === '10px').toBe(true)
|
|
|
|
})
|
2021-03-01 21:10:18 +08:00
|
|
|
|
|
|
|
it('change gutter value', async () => {
|
|
|
|
const outer = ref(20)
|
2022-06-01 13:08:19 +08:00
|
|
|
|
|
|
|
const wrapper = mount({
|
|
|
|
setup() {
|
|
|
|
return () => (
|
2022-03-01 23:21:42 +08:00
|
|
|
<Row gutter={outer.value} ref="row">
|
|
|
|
<Col span={12} ref="col" />
|
|
|
|
</Row>
|
2022-06-01 13:08:19 +08:00
|
|
|
)
|
|
|
|
},
|
2022-03-01 23:21:42 +08:00
|
|
|
})
|
2021-03-01 21:10:18 +08:00
|
|
|
|
|
|
|
const rowElm = wrapper.findComponent({ ref: 'row' }).element as HTMLElement
|
|
|
|
const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement
|
|
|
|
expect(rowElm.style.marginLeft === '-10px').toBe(true)
|
|
|
|
expect(rowElm.style.marginRight === '-10px').toBe(true)
|
|
|
|
expect(colElm.style.paddingLeft === '10px').toBe(true)
|
|
|
|
expect(colElm.style.paddingRight === '10px').toBe(true)
|
|
|
|
|
|
|
|
outer.value = 40 // change gutter value
|
|
|
|
await nextTick()
|
|
|
|
expect(rowElm.style.marginLeft === '-20px').toBe(true)
|
|
|
|
expect(rowElm.style.marginRight === '-20px').toBe(true)
|
|
|
|
expect(colElm.style.paddingLeft === '20px').toBe(true)
|
|
|
|
expect(colElm.style.paddingRight === '20px').toBe(true)
|
|
|
|
})
|
|
|
|
|
2020-07-31 18:20:03 +08:00
|
|
|
it('responsive', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
setup() {
|
|
|
|
return () => (
|
2022-03-01 23:21:42 +08:00
|
|
|
<Row gutter={20}>
|
|
|
|
<Col
|
|
|
|
ref="col"
|
|
|
|
sm={{ span: 4, offset: 2 }}
|
|
|
|
md={8}
|
|
|
|
lg={{ span: 6, offset: 3 }}
|
|
|
|
/>
|
|
|
|
</Row>
|
2022-06-01 13:08:19 +08:00
|
|
|
)
|
|
|
|
},
|
2022-03-01 23:21:42 +08:00
|
|
|
})
|
2022-06-01 13:08:19 +08:00
|
|
|
|
2020-07-31 18:20:03 +08:00
|
|
|
const colElmClass = wrapper.findComponent({ ref: 'col' }).classes()
|
|
|
|
expect(colElmClass.includes('el-col-sm-4')).toBe(true)
|
|
|
|
expect(colElmClass.includes('el-col-sm-4')).toBe(true)
|
|
|
|
expect(colElmClass.includes('el-col-sm-offset-2')).toBe(true)
|
|
|
|
expect(colElmClass.includes('el-col-lg-6')).toBe(true)
|
|
|
|
expect(colElmClass.includes('el-col-lg-offset-3')).toBe(true)
|
|
|
|
expect(colElmClass.includes('el-col-md-8')).toBe(true)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Row', () => {
|
|
|
|
test('create', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Row />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('el-row')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('gutter', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Row gutter={20} />)
|
2020-07-31 18:20:03 +08:00
|
|
|
const rowElm = wrapper.element as HTMLElement
|
|
|
|
expect(rowElm.style.marginLeft).toEqual('-10px')
|
|
|
|
expect(rowElm.style.marginRight).toEqual('-10px')
|
|
|
|
})
|
|
|
|
test('justify', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Row justify="end" />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('is-justify-end')
|
|
|
|
})
|
|
|
|
test('align', () => {
|
2022-06-01 13:08:19 +08:00
|
|
|
const wrapper = mount(() => <Row align="bottom" />)
|
2020-07-31 18:20:03 +08:00
|
|
|
expect(wrapper.classes()).toContain('is-align-bottom')
|
|
|
|
})
|
|
|
|
})
|