ant-design-vue/components/notification/__tests__/placement.test.js

167 lines
4.2 KiB
JavaScript
Raw Normal View History

2019-01-12 03:33:27 +00:00
import { asyncExpect } from '@/tests/utils';
import notification from '..';
2018-06-10 08:02:12 +00:00
describe('Notification.placement', () => {
2019-01-12 03:33:27 +00:00
afterEach(() => notification.destroy());
2018-06-10 08:02:12 +00:00
2019-01-12 03:33:27 +00:00
function $$(className) {
return document.body.querySelectorAll(className);
2018-06-10 08:02:12 +00:00
}
2019-01-12 03:33:27 +00:00
function getStyle(el, prop) {
const style = window.getComputedStyle ? window.getComputedStyle(el) : el.currentStyle;
2018-06-10 08:02:12 +00:00
// If a css property's value is `auto`, it will return an empty string.
2019-01-12 03:33:27 +00:00
return prop ? style[prop] : style;
2018-06-10 08:02:12 +00:00
}
2019-01-12 03:33:27 +00:00
function open(args) {
2018-06-10 08:02:12 +00:00
notification.open({
message: 'Notification Title',
description: 'This is the content of the notification.',
...args,
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
}
2019-01-12 03:33:27 +00:00
function config(args) {
2018-06-10 08:02:12 +00:00
notification.config({
...args,
2019-01-12 03:33:27 +00:00
});
open();
2018-06-10 08:02:12 +00:00
}
it('change notification placement by `open` method', async () => {
2019-01-12 03:33:27 +00:00
const defaultTop = '24px';
const defaultBottom = '24px';
let style;
2018-06-10 08:02:12 +00:00
// topLeft
open({
placement: 'topLeft',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
style = getStyle($$('.ant-notification-topLeft')[0]);
expect(style.top).toBe(defaultTop);
expect(style.left).toBe('0px');
expect(style.bottom).toBe('');
});
2018-06-10 08:02:12 +00:00
open({
placement: 'topLeft',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect($$('.ant-notification-topLeft').length).toBe(1);
});
2018-06-10 08:02:12 +00:00
// topRight
open({
placement: 'topRight',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
style = getStyle($$('.ant-notification-topRight')[0]);
expect(style.top).toBe(defaultTop);
expect(style.right).toBe('0px');
expect(style.bottom).toBe('');
});
2018-06-10 08:02:12 +00:00
open({
placement: 'topRight',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect($$('.ant-notification-topRight').length).toBe(1);
});
2018-06-10 08:02:12 +00:00
// bottomRight
open({
placement: 'bottomRight',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
style = getStyle($$('.ant-notification-bottomRight')[0]);
expect(style.top).toBe('');
expect(style.right).toBe('0px');
expect(style.bottom).toBe(defaultBottom);
});
2018-06-10 08:02:12 +00:00
open({
placement: 'bottomRight',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect($$('.ant-notification-bottomRight').length).toBe(1);
});
2018-06-10 08:02:12 +00:00
// bottomLeft
open({
placement: 'bottomLeft',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
style = getStyle($$('.ant-notification-bottomLeft')[0]);
expect(style.top).toBe('');
expect(style.left).toBe('0px');
expect(style.bottom).toBe(defaultBottom);
});
2018-06-10 08:02:12 +00:00
open({
placement: 'bottomLeft',
2019-01-12 03:33:27 +00:00
});
2018-06-10 08:02:12 +00:00
await asyncExpect(() => {
2019-01-12 03:33:27 +00:00
expect($$('.ant-notification-bottomLeft').length).toBe(1);
});
await asyncExpect(() => {});
await asyncExpect(() => {});
});
2018-06-10 08:02:12 +00:00
it('change notification placement by `config` method', () => {
2019-01-12 03:33:27 +00:00
let style;
2018-06-10 08:02:12 +00:00
// topLeft
config({
placement: 'topLeft',
top: '50px',
bottom: '50px',
2019-01-12 03:33:27 +00:00
});
style = getStyle($$('.ant-notification-topLeft')[0]);
expect(style.top).toBe('50px');
expect(style.left).toBe('0px');
expect(style.bottom).toBe('');
2018-06-10 08:02:12 +00:00
// topRight
config({
placement: 'topRight',
top: '100px',
bottom: '50px',
2019-01-12 03:33:27 +00:00
});
style = getStyle($$('.ant-notification-topRight')[0]);
expect(style.top).toBe('100px');
expect(style.right).toBe('0px');
expect(style.bottom).toBe('');
2018-06-10 08:02:12 +00:00
// bottomRight
config({
placement: 'bottomRight',
top: '50px',
bottom: '100px',
2019-01-12 03:33:27 +00:00
});
style = getStyle($$('.ant-notification-bottomRight')[0]);
expect(style.top).toBe('');
expect(style.right).toBe('0px');
expect(style.bottom).toBe('100px');
2018-06-10 08:02:12 +00:00
// bottomLeft
config({
placement: 'bottomLeft',
top: 100,
bottom: 50,
2019-01-12 03:33:27 +00:00
});
style = getStyle($$('.ant-notification-bottomLeft')[0]);
expect(style.top).toBe('');
expect(style.left).toBe('0px');
expect(style.bottom).toBe('50px');
});
2018-06-10 08:02:12 +00:00
it('change notification mountNode by `config` method', () => {
2019-01-12 03:33:27 +00:00
const $container = document.createElement('div');
document.body.appendChild($container);
2018-06-10 08:02:12 +00:00
config({
top: '50px',
bottom: '100px',
2019-01-12 03:33:27 +00:00
getContainer() {
return $container;
2018-06-10 08:02:12 +00:00
},
2019-01-12 03:33:27 +00:00
});
expect($container.querySelector('.ant-notification')).not.toBe(null);
$container.remove();
});
});