notification.spec.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { triggerEvent } from '../util';
  2. import Notification from 'packages/notification';
  3. describe('Notification', () => {
  4. afterEach(() => {
  5. const el = document.querySelector('.el-notification');
  6. if (!el) return;
  7. if (el.parentNode) {
  8. el.parentNode.removeChild(el);
  9. }
  10. if (el.__vue__) {
  11. el.__vue__.$destroy();
  12. }
  13. });
  14. it('automatically close', done => {
  15. Notification({
  16. message: '玻璃蜡烛',
  17. duration: 500
  18. });
  19. expect(document.querySelector('.el-notification')).to.exist;
  20. setTimeout(() => {
  21. expect(document.querySelector('.el-notification')).to.not.exist;
  22. done();
  23. }, 1000);
  24. });
  25. it('manually close', done => {
  26. Notification({
  27. message: '苍白母马'
  28. });
  29. setTimeout(() => {
  30. document.querySelector('.el-notification__closeBtn').click();
  31. setTimeout(() => {
  32. expect(document.querySelector('.el-notification')).to.not.exist;
  33. done();
  34. }, 500);
  35. }, 500);
  36. });
  37. it('create', () => {
  38. Notification({
  39. title: '狮子',
  40. message: '狮鹫',
  41. duration: 0
  42. });
  43. const group = document.querySelector('.el-notification__group');
  44. const title = group.querySelector('span');
  45. const message = group.querySelector('p');
  46. expect(document.querySelector('.el-notification')).to.exist;
  47. expect(title.textContent).to.equal('狮子');
  48. expect(message.textContent).to.equal('狮鹫');
  49. });
  50. it('invoke with type', () => {
  51. Notification.success('太阳之子');
  52. expect(document.querySelector('.el-notification').__vue__.type).to.equal('success');
  53. });
  54. it('reset timer', done => {
  55. Notification({
  56. message: '芳香总管',
  57. duration: 1000
  58. });
  59. setTimeout(() => {
  60. triggerEvent(document.querySelector('.el-notification'), 'mouseenter');
  61. setTimeout(() => {
  62. triggerEvent(document.querySelector('.el-notification'), 'mouseleave');
  63. expect(document.querySelector('.el-notification')).to.exist;
  64. done();
  65. }, 700);
  66. }, 500);
  67. });
  68. });