2020-08-17 22:23:45 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { describe, expect, test } from 'vitest'
|
2022-02-11 11:03:15 +08:00
|
|
|
import { TypeComponentsMap } from '@element-plus/utils'
|
2021-09-13 10:48:10 +08:00
|
|
|
import Alert from '../src/alert.vue'
|
2020-08-17 22:23:45 +08:00
|
|
|
|
|
|
|
const AXIOM = 'Rem is the best girl'
|
|
|
|
|
|
|
|
describe('Alert.vue', () => {
|
|
|
|
test('render test & class', () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => <Alert title={AXIOM} showIcon={true} />)
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(wrapper.find('.el-alert__title').text()).toEqual(AXIOM)
|
|
|
|
expect(wrapper.find('.el-alert').classes()).toContain('el-alert--info')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('type', () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Alert title={'test'} showIcon={true} type={'success'} />
|
|
|
|
))
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(wrapper.find('.el-alert').classes()).toContain('el-alert--success')
|
2021-10-27 23:17:13 +08:00
|
|
|
expect(wrapper.find('.el-alert__icon').classes()).toContain('el-icon')
|
|
|
|
expect(wrapper.findComponent(TypeComponentsMap.success).exists()).toBe(true)
|
2020-08-17 22:23:45 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('description', () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<Alert title={'Dorne'} showIcon={true} description={AXIOM} />
|
|
|
|
))
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(wrapper.find('.el-alert__description').text()).toEqual(AXIOM)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('theme', () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => <Alert title={'test'} effect={'dark'} />)
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(wrapper.find('.el-alert').classes()).toContain('is-dark')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('title slot', () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => <Alert title={AXIOM} />)
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(wrapper.find('.el-alert__title').text()).toEqual(AXIOM)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('close', async () => {
|
2022-05-30 09:38:12 +08:00
|
|
|
const wrapper = mount(() => <Alert closeText={'close'} />)
|
2022-02-11 23:37:50 +08:00
|
|
|
const closeBtn = wrapper.find('.el-alert__close-btn')
|
2020-08-17 22:23:45 +08:00
|
|
|
expect(closeBtn.exists()).toBe(true)
|
|
|
|
|
|
|
|
await closeBtn.trigger('click')
|
|
|
|
expect(wrapper.emitted()).toBeDefined()
|
|
|
|
})
|
|
|
|
})
|