123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { nextTick, ref } from 'vue'
- import { mount } from '@vue/test-utils'
- import { describe, expect, it, test } from 'vitest'
- import Row from '@element-plus/components/row'
- import Col from '../src/col.vue'
- describe('Col', () => {
- it('create', () => {
- const wrapper = mount(() => <Col />)
- expect(wrapper.classes()).toContain('el-col')
- })
- it('span', () => {
- const wrapper = mount(() => <Col span={12} />)
- expect(wrapper.classes()).toContain('el-col-12')
- })
- it('pull', () => {
- const wrapper = mount(() => <Col span={12} pull={3} />)
- expect(wrapper.classes()).toContain('el-col-pull-3')
- })
- it('push', () => {
- const wrapper = mount(() => <Col span={12} push={3} />)
- expect(wrapper.classes()).toContain('el-col-push-3')
- })
- it('gutter', () => {
- const wrapper = mount({
- setup() {
- return () => (
- <Row gutter={20}>
- <Col span={12} ref="col"></Col>
- </Row>
- )
- },
- })
- const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement
- expect(colElm.style.paddingLeft === '10px').toBe(true)
- expect(colElm.style.paddingRight === '10px').toBe(true)
- })
- it('change gutter value', async () => {
- const outer = ref(20)
- const wrapper = mount({
- setup() {
- return () => (
- <Row gutter={outer.value} ref="row">
- <Col span={12} ref="col" />
- </Row>
- )
- },
- })
- 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)
- })
- it('responsive', () => {
- const wrapper = mount({
- setup() {
- return () => (
- <Row gutter={20}>
- <Col
- ref="col"
- sm={{ span: 4, offset: 2 }}
- md={8}
- lg={{ span: 6, offset: 3 }}
- />
- </Row>
- )
- },
- })
- 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', () => {
- const wrapper = mount(() => <Row />)
- expect(wrapper.classes()).toContain('el-row')
- })
- test('gutter', () => {
- const wrapper = mount(() => <Row gutter={20} />)
- const rowElm = wrapper.element as HTMLElement
- expect(rowElm.style.marginLeft).toEqual('-10px')
- expect(rowElm.style.marginRight).toEqual('-10px')
- })
- test('justify', () => {
- const wrapper = mount(() => <Row justify="end" />)
- expect(wrapper.classes()).toContain('is-justify-end')
- })
- test('align', () => {
- const wrapper = mount(() => <Row align="bottom" />)
- expect(wrapper.classes()).toContain('is-align-bottom')
- })
- })
|