notification.spec.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import Vue from 'vue';
  2. import { triggerEvent } from '../util';
  3. import Notification from 'packages/notification';
  4. describe('Notification', () => {
  5. afterEach(() => {
  6. const el = document.querySelector('.el-notification');
  7. if (!el) return;
  8. if (el.parentNode) {
  9. el.parentNode.removeChild(el);
  10. }
  11. if (el.__vue__) {
  12. el.__vue__.$destroy();
  13. }
  14. });
  15. it('automatically close', done => {
  16. Notification({
  17. message: '玻璃蜡烛',
  18. duration: 500
  19. });
  20. expect(document.querySelector('.el-notification')).to.exist;
  21. setTimeout(() => {
  22. expect(document.querySelector('.el-notification')).to.not.exist;
  23. done();
  24. }, 1000);
  25. });
  26. it('manually close', done => {
  27. Notification({
  28. message: '苍白母马'
  29. });
  30. setTimeout(() => {
  31. document.querySelector('.el-notification__closeBtn').click();
  32. setTimeout(() => {
  33. expect(document.querySelector('.el-notification')).to.not.exist;
  34. done();
  35. }, 500);
  36. }, 500);
  37. });
  38. it('create', () => {
  39. Notification({
  40. title: '狮子',
  41. message: '狮鹫',
  42. duration: 0
  43. });
  44. const group = document.querySelector('.el-notification__group');
  45. const title = group.querySelector('.el-notification__title');
  46. const message = group.querySelector('.el-notification__content p');
  47. expect(document.querySelector('.el-notification')).to.exist;
  48. expect(title.textContent).to.equal('狮子');
  49. expect(message.textContent).to.equal('狮鹫');
  50. });
  51. it('html string as message', () => {
  52. Notification({
  53. title: '狮子',
  54. message: '<strong>狮鹫</strong>',
  55. dangerouslyUseHTMLString: true,
  56. duration: 0
  57. });
  58. const message = document.querySelector('.el-notification__content strong');
  59. expect(message.textContent).to.equal('狮鹫');
  60. });
  61. it('create by vnode', () => {
  62. const fakeVM = new Vue();
  63. const h = fakeVM.$createElement;
  64. Notification({
  65. message: h('p', { style: { color: 'red' } }, '大美兴,川普王')
  66. });
  67. const group = document.querySelector('.el-notification__group');
  68. const message = group.querySelector('.el-notification__content');
  69. expect(message.innerHTML).to.equal('<p style="color: red;">大美兴,川普王</p>');
  70. });
  71. it('alias by vnode', () => {
  72. const fakeVM = new Vue();
  73. const h = fakeVM.$createElement;
  74. Notification.error(h('p', { style: { color: 'green' } }, '+1s'));
  75. const group = document.querySelector('.el-notification__group');
  76. const message = group.querySelector('.el-notification__content');
  77. expect(message.innerHTML).to.equal('<p style="color: green;">+1s</p>');
  78. });
  79. it('invoke with type', () => {
  80. Notification.success('太阳之子');
  81. expect(document.querySelector('.el-notification').__vue__.type).to.equal('success');
  82. });
  83. it('reset timer', done => {
  84. Notification({
  85. message: '芳香总管',
  86. duration: 1000
  87. });
  88. setTimeout(() => {
  89. triggerEvent(document.querySelector('.el-notification'), 'mouseenter');
  90. setTimeout(() => {
  91. triggerEvent(document.querySelector('.el-notification'), 'mouseleave');
  92. expect(document.querySelector('.el-notification')).to.exist;
  93. done();
  94. }, 700);
  95. }, 500);
  96. });
  97. it('no close button', done => {
  98. Notification({
  99. message: 'Hello',
  100. showClose: false
  101. });
  102. setTimeout(() => {
  103. expect(document.querySelector('.el-notification__closeBtn')).to.not.exist;
  104. done();
  105. }, 500);
  106. });
  107. });