container.test.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import { mount } from '@vue/test-utils'
  2. import { describe, expect, test } from 'vitest'
  3. import { getCssVariable } from '@element-plus/test-utils/dom'
  4. import Container from '../src/container.vue'
  5. import Header from '../src/header.vue'
  6. import Main from '../src/main.vue'
  7. import Aside from '../src/aside.vue'
  8. import Footer from '../src/footer.vue'
  9. const AXIOM = 'Rem is the best girl'
  10. describe('Container.vue', () => {
  11. test('container render test', async () => {
  12. const wrapper = mount(() => <Container>{AXIOM}</Container>)
  13. expect(wrapper.text()).toEqual(AXIOM)
  14. })
  15. test('vertical', () => {
  16. const wrapper = mount(() => (
  17. <Container>
  18. <Header />
  19. <Main />
  20. </Container>
  21. ))
  22. expect(wrapper.classes('is-vertical')).toBe(true)
  23. })
  24. test('direction', () => {
  25. const wrapper = mount({
  26. data: () => ({ direction: 'horizontal' }),
  27. render() {
  28. return (
  29. <Container direction={this.direction}>
  30. <Header />
  31. <Main />
  32. </Container>
  33. )
  34. },
  35. })
  36. expect(wrapper.vm.$el.classList.contains('is-vertical')).toBe(false)
  37. wrapper.vm.direction = 'vertical'
  38. wrapper.vm.$nextTick(() => {
  39. expect(wrapper.vm.$el.classList.contains('is-vertical')).toBe(true)
  40. })
  41. })
  42. })
  43. describe('Header', () => {
  44. test('create header', () => {
  45. const wrapper = mount(() => <Header />)
  46. expect(wrapper.classes()).toContain('el-header')
  47. })
  48. test('header height', () => {
  49. const wrapper = mount(() => <Header height="100px" />)
  50. const vm = wrapper.vm
  51. expect(getCssVariable(vm.$el, '--el-header-height')).toEqual('100px')
  52. })
  53. })
  54. describe('Aside', () => {
  55. test('aside create', () => {
  56. const wrapper = mount(() => <Aside />)
  57. expect(wrapper.classes()).toContain('el-aside')
  58. })
  59. test('aside width', () => {
  60. const wrapper = mount(() => <Aside width="200px" />)
  61. const vm = wrapper.vm
  62. expect(getCssVariable(vm.$el, '--el-aside-width')).toEqual('200px')
  63. })
  64. })
  65. describe('Main', () => {
  66. test('main create', () => {
  67. const wrapper = mount(() => <Main />)
  68. expect(wrapper.classes()).toContain('el-main')
  69. })
  70. })
  71. describe('Footer', () => {
  72. test('footer create', () => {
  73. const wrapper = mount(() => <Footer />)
  74. expect(wrapper.classes()).toContain('el-footer')
  75. })
  76. test('footer height', () => {
  77. const wrapper = mount(() => <Footer height="100px" />)
  78. const vm = wrapper.vm
  79. expect(getCssVariable(vm.$el, '--el-footer-height')).toEqual('100px')
  80. })
  81. })