2020-08-05 16:27:51 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
|
|
|
import { getCssVariable } from '@element-plus/test-utils/dom'
|
2021-08-24 13:36:48 +08:00
|
|
|
|
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'
|
2020-08-05 16:27:51 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Container.vue', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
test('container render test', async () => {
|
|
|
|
const wrapper = mount(() => <Container>{AXIOM}</Container>)
|
2020-08-05 16:27:51 +08:00
|
|
|
expect(wrapper.text()).toEqual(AXIOM)
|
|
|
|
})
|
2020-08-05 22:58:49 +08:00
|
|
|
|
|
|
|
test('vertical', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Container>
|
|
|
|
<Header />
|
|
|
|
<Main />
|
|
|
|
</Container>
|
|
|
|
))
|
2020-08-06 19:25:13 +08:00
|
|
|
expect(wrapper.classes('is-vertical')).toBe(true)
|
2020-08-05 22:58:49 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('direction', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
data: () => ({ direction: 'horizontal' }),
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Container direction={this.direction}>
|
|
|
|
<Header />
|
|
|
|
<Main />
|
|
|
|
</Container>
|
|
|
|
)
|
2020-08-05 22:58:49 +08:00
|
|
|
},
|
2022-07-12 19:26:58 +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 16:27:51 +08:00
|
|
|
})
|
2020-08-05 19:06:05 +08:00
|
|
|
|
|
|
|
describe('Header', () => {
|
2020-08-05 22:58:49 +08:00
|
|
|
test('create header', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
const wrapper = mount(() => <Header height="100px" />)
|
2020-08-05 22:58:49 +08:00
|
|
|
const vm = wrapper.vm
|
2021-07-14 22:00:15 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
const wrapper = mount(() => <Aside width="200px" />)
|
2020-08-05 22:58:49 +08:00
|
|
|
const vm = wrapper.vm
|
2021-07-14 22:00:15 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
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', () => {
|
2022-07-12 19:26:58 +08:00
|
|
|
const wrapper = mount(() => <Footer height="100px" />)
|
2020-08-05 22:58:49 +08:00
|
|
|
const vm = wrapper.vm
|
2021-07-14 22:00:15 +08:00
|
|
|
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
|
|
|
})
|