layout.test.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { nextTick, ref } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, it, test } from 'vitest'
  4. import Row from '@element-plus/components/row'
  5. import Col from '../src/col.vue'
  6. describe('Col', () => {
  7. it('create', () => {
  8. const wrapper = mount(() => <Col />)
  9. expect(wrapper.classes()).toContain('el-col')
  10. })
  11. it('span', () => {
  12. const wrapper = mount(() => <Col span={12} />)
  13. expect(wrapper.classes()).toContain('el-col-12')
  14. })
  15. it('pull', () => {
  16. const wrapper = mount(() => <Col span={12} pull={3} />)
  17. expect(wrapper.classes()).toContain('el-col-pull-3')
  18. })
  19. it('push', () => {
  20. const wrapper = mount(() => <Col span={12} push={3} />)
  21. expect(wrapper.classes()).toContain('el-col-push-3')
  22. })
  23. it('gutter', () => {
  24. const wrapper = mount({
  25. setup() {
  26. return () => (
  27. <Row gutter={20}>
  28. <Col span={12} ref="col"></Col>
  29. </Row>
  30. )
  31. },
  32. })
  33. const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement
  34. expect(colElm.style.paddingLeft === '10px').toBe(true)
  35. expect(colElm.style.paddingRight === '10px').toBe(true)
  36. })
  37. it('change gutter value', async () => {
  38. const outer = ref(20)
  39. const wrapper = mount({
  40. setup() {
  41. return () => (
  42. <Row gutter={outer.value} ref="row">
  43. <Col span={12} ref="col" />
  44. </Row>
  45. )
  46. },
  47. })
  48. const rowElm = wrapper.findComponent({ ref: 'row' }).element as HTMLElement
  49. const colElm = wrapper.findComponent({ ref: 'col' }).element as HTMLElement
  50. expect(rowElm.style.marginLeft === '-10px').toBe(true)
  51. expect(rowElm.style.marginRight === '-10px').toBe(true)
  52. expect(colElm.style.paddingLeft === '10px').toBe(true)
  53. expect(colElm.style.paddingRight === '10px').toBe(true)
  54. outer.value = 40 // change gutter value
  55. await nextTick()
  56. expect(rowElm.style.marginLeft === '-20px').toBe(true)
  57. expect(rowElm.style.marginRight === '-20px').toBe(true)
  58. expect(colElm.style.paddingLeft === '20px').toBe(true)
  59. expect(colElm.style.paddingRight === '20px').toBe(true)
  60. })
  61. it('responsive', () => {
  62. const wrapper = mount({
  63. setup() {
  64. return () => (
  65. <Row gutter={20}>
  66. <Col
  67. ref="col"
  68. sm={{ span: 4, offset: 2 }}
  69. md={8}
  70. lg={{ span: 6, offset: 3 }}
  71. />
  72. </Row>
  73. )
  74. },
  75. })
  76. const colElmClass = wrapper.findComponent({ ref: 'col' }).classes()
  77. expect(colElmClass.includes('el-col-sm-4')).toBe(true)
  78. expect(colElmClass.includes('el-col-sm-4')).toBe(true)
  79. expect(colElmClass.includes('el-col-sm-offset-2')).toBe(true)
  80. expect(colElmClass.includes('el-col-lg-6')).toBe(true)
  81. expect(colElmClass.includes('el-col-lg-offset-3')).toBe(true)
  82. expect(colElmClass.includes('el-col-md-8')).toBe(true)
  83. })
  84. })
  85. describe('Row', () => {
  86. test('create', () => {
  87. const wrapper = mount(() => <Row />)
  88. expect(wrapper.classes()).toContain('el-row')
  89. })
  90. test('gutter', () => {
  91. const wrapper = mount(() => <Row gutter={20} />)
  92. const rowElm = wrapper.element as HTMLElement
  93. expect(rowElm.style.marginLeft).toEqual('-10px')
  94. expect(rowElm.style.marginRight).toEqual('-10px')
  95. })
  96. test('justify', () => {
  97. const wrapper = mount(() => <Row justify="end" />)
  98. expect(wrapper.classes()).toContain('is-justify-end')
  99. })
  100. test('align', () => {
  101. const wrapper = mount(() => <Row align="bottom" />)
  102. expect(wrapper.classes()).toContain('is-align-bottom')
  103. })
  104. })