mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-21 02:50:11 +08:00
55348b30b6
* style: use prettier * style: just prettier format, no code changes * style: eslint fix object-shorthand, prefer-const * style: fix no-void * style: no-console
84 lines
2.2 KiB
TypeScript
84 lines
2.2 KiB
TypeScript
import { nextTick, h } from 'vue'
|
|
import { rAF } from '@element-plus/test-utils/tick'
|
|
import Notification, { closeAll } from '../src/notify'
|
|
|
|
import type { INotificationHandle } from '../src/notification.type'
|
|
|
|
const selector = '.el-notification'
|
|
|
|
describe('Notification on command', () => {
|
|
afterEach(() => {
|
|
closeAll()
|
|
})
|
|
|
|
test('it should get component handle', async () => {
|
|
const handle = Notification()
|
|
await rAF()
|
|
expect(document.querySelector(selector)).toBeDefined()
|
|
|
|
handle.close()
|
|
await rAF()
|
|
await nextTick()
|
|
expect(document.querySelector(selector)).toBeNull()
|
|
expect(
|
|
document.querySelector('[class^="container_notification"]')
|
|
).toBeNull()
|
|
})
|
|
|
|
test('it should be able to render vnode', async () => {
|
|
const testClassName = 'test-classname'
|
|
const { close } = Notification({
|
|
duration: 0,
|
|
message: h('div', { class: testClassName }, 'test-content'),
|
|
})
|
|
|
|
await rAF()
|
|
expect(document.querySelector(`.${testClassName}`)).toBeDefined()
|
|
close()
|
|
})
|
|
|
|
test('it should be able to close notification by manually close', async () => {
|
|
const { close } = Notification({
|
|
duration: 0,
|
|
})
|
|
await rAF()
|
|
|
|
const element = document.querySelector(selector)
|
|
expect(element).toBeDefined()
|
|
close()
|
|
await rAF()
|
|
await nextTick()
|
|
|
|
expect(document.querySelector(selector)).toBeNull()
|
|
})
|
|
|
|
test('it should close all notifications', async () => {
|
|
const notifications: INotificationHandle[] = []
|
|
const onClose = jest.fn()
|
|
for (let i = 0; i < 4; i++) {
|
|
notifications.push(
|
|
Notification({
|
|
onClose,
|
|
duration: 0,
|
|
})
|
|
)
|
|
}
|
|
// jest.runAllTicks()
|
|
await rAF()
|
|
|
|
expect(document.querySelectorAll(selector).length).toBe(4)
|
|
closeAll()
|
|
// jest.runAllTicks()
|
|
await rAF()
|
|
expect(onClose).toHaveBeenCalledTimes(notifications.length)
|
|
expect(document.querySelectorAll(selector).length).toBe(0)
|
|
})
|
|
|
|
test('it should be able to render all types notification', () => {
|
|
for (const type of ['success', 'warning', 'error', 'info'] as const) {
|
|
Notification[type]({})
|
|
expect(document.querySelector(`.el-icon-${type}`)).toBeDefined()
|
|
}
|
|
})
|
|
})
|