element-plus/packages/components/container/__tests__/container.test.tsx

95 lines
2.5 KiB
TypeScript
Raw Normal View History

import { mount } from '@vue/test-utils'
import { describe, expect, test } from 'vitest'
import { getCssVariable } from '@element-plus/test-utils/dom'
2020-08-05 16:36:08 +08:00
import Container from '../src/container.vue'
2020-08-05 19:06:05 +08:00
import Header from '../src/header.vue'
import Main from '../src/main.vue'
import Aside from '../src/aside.vue'
import Footer from '../src/footer.vue'
const AXIOM = 'Rem is the best girl'
describe('Container.vue', () => {
test('container render test', async () => {
const wrapper = mount(() => <Container>{AXIOM}</Container>)
expect(wrapper.text()).toEqual(AXIOM)
})
2020-08-05 22:58:49 +08:00
test('vertical', () => {
const wrapper = mount(() => (
<Container>
<Header />
<Main />
</Container>
))
expect(wrapper.classes('is-vertical')).toBe(true)
2020-08-05 22:58:49 +08:00
})
test('direction', () => {
const wrapper = mount({
data: () => ({ direction: 'horizontal' }),
render() {
return (
<Container direction={this.direction}>
<Header />
<Main />
</Container>
)
2020-08-05 22:58:49 +08:00
},
})
2020-08-05 22:58:49 +08:00
expect(wrapper.vm.$el.classList.contains('is-vertical')).toBe(false)
wrapper.vm.direction = 'vertical'
wrapper.vm.$nextTick(() => {
expect(wrapper.vm.$el.classList.contains('is-vertical')).toBe(true)
})
})
})
2020-08-05 19:06:05 +08:00
describe('Header', () => {
2020-08-05 22:58:49 +08:00
test('create header', () => {
const wrapper = mount(() => <Header />)
2020-08-05 19:06:05 +08:00
expect(wrapper.classes()).toContain('el-header')
})
2020-08-05 22:58:49 +08:00
test('header height', () => {
const wrapper = mount(() => <Header height="100px" />)
2020-08-05 22:58:49 +08:00
const vm = wrapper.vm
expect(getCssVariable(vm.$el, '--el-header-height')).toEqual('100px')
2020-08-06 10:38:53 +08:00
})
2020-08-05 19:06:05 +08:00
})
describe('Aside', () => {
2020-08-05 22:58:49 +08:00
test('aside create', () => {
const wrapper = mount(() => <Aside />)
2020-08-05 19:06:05 +08:00
expect(wrapper.classes()).toContain('el-aside')
})
2020-08-05 22:58:49 +08:00
test('aside width', () => {
const wrapper = mount(() => <Aside width="200px" />)
2020-08-05 22:58:49 +08:00
const vm = wrapper.vm
expect(getCssVariable(vm.$el, '--el-aside-width')).toEqual('200px')
2020-08-06 10:38:53 +08:00
})
2020-08-05 22:58:49 +08:00
})
describe('Main', () => {
test('main create', () => {
const wrapper = mount(() => <Main />)
2020-08-05 22:58:49 +08:00
expect(wrapper.classes()).toContain('el-main')
})
2020-08-05 19:06:05 +08:00
})
describe('Footer', () => {
2020-08-05 22:58:49 +08:00
test('footer create', () => {
const wrapper = mount(() => <Footer />)
2020-08-05 19:06:05 +08:00
expect(wrapper.classes()).toContain('el-footer')
})
2020-08-05 22:58:49 +08:00
test('footer height', () => {
const wrapper = mount(() => <Footer height="100px" />)
2020-08-05 22:58:49 +08:00
const vm = wrapper.vm
expect(getCssVariable(vm.$el, '--el-footer-height')).toEqual('100px')
2020-08-06 10:38:53 +08:00
})
2020-08-05 19:06:05 +08:00
})