mixin.vue-popup.spec.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import VuePopup from 'element-ui/src/utils/popup';
  2. import { createTest, destroyVM } from '../util';
  3. const Popup = Object.assign({}, VuePopup, {
  4. render(h) {
  5. return h('div');
  6. },
  7. created() {
  8. this.rendered = true;
  9. }
  10. });
  11. describe('Mixin:vue-popup', () => {
  12. let vm;
  13. before(() => {
  14. const modals = document.querySelectorAll('.v-modal');
  15. [].forEach.call(modals, modal => {
  16. modal &&
  17. modal.parentNode &&
  18. modal.parentNode.removeChild(modal);
  19. });
  20. });
  21. afterEach(() => {
  22. vm.close && vm.close();
  23. destroyVM(vm);
  24. const modal = document.querySelector('.v-modal');
  25. modal &&
  26. modal.parentNode &&
  27. modal.parentNode.removeChild(modal);
  28. });
  29. it('show modal', () => {
  30. vm = createTest(Popup);
  31. vm.open();
  32. expect(document.querySelector('.v-modal')).to.not.exist;
  33. vm.close();
  34. destroyVM(vm);
  35. vm = createTest(Popup, { modal: true });
  36. vm.open();
  37. expect(document.querySelector('.v-modal')).to.exist;
  38. });
  39. it('custom modal class', () => {
  40. vm = createTest(Popup, { modal: true, modalClass: 'custom-class' });
  41. vm.open();
  42. expect(document.querySelector('.v-modal').classList.contains('custom-class')).to.true;
  43. });
  44. it('lock scroll', done => {
  45. vm = createTest(Popup, { modal: true });
  46. vm.open();
  47. expect(document.body.style.overflow).to.equal('hidden');
  48. vm.close();
  49. destroyVM(vm);
  50. setTimeout(() => {
  51. vm = createTest(Popup, { modal: true, lockScroll: false });
  52. vm.open();
  53. expect(document.body.style.overflow).to.not.equal('hidden');
  54. done();
  55. }, 200);
  56. });
  57. it('z-index should increase', () => {
  58. vm = createTest(Popup, { modal: true });
  59. vm.open();
  60. const zIndex1 = document.querySelector('.v-modal').style.zIndex;
  61. vm.close();
  62. destroyVM(vm);
  63. vm = createTest(Popup, { modal: true });
  64. vm.open();
  65. const zIndex2 = document.querySelector('.v-modal').style.zIndex;
  66. expect(zIndex2 > zIndex1).to.true;
  67. });
  68. });