notification.spec.js 1.8 KB

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