mixin.vue-popup.spec.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. document.body.className = '';
  15. const modals = document.querySelectorAll('.v-modal');
  16. [].forEach.call(modals, modal => {
  17. modal &&
  18. modal.parentNode &&
  19. modal.parentNode.removeChild(modal);
  20. });
  21. });
  22. afterEach(() => {
  23. vm.close && vm.close();
  24. destroyVM(vm);
  25. const modal = document.querySelector('.v-modal');
  26. modal &&
  27. modal.parentNode &&
  28. modal.parentNode.removeChild(modal);
  29. });
  30. it('show modal', () => {
  31. vm = createTest(Popup);
  32. vm.open();
  33. expect(document.querySelector('.v-modal')).to.not.exist;
  34. vm.close();
  35. destroyVM(vm);
  36. vm = createTest(Popup, { modal: true });
  37. vm.open();
  38. expect(document.querySelector('.v-modal')).to.exist;
  39. });
  40. it('custom modal class', () => {
  41. vm = createTest(Popup, { modal: true, modalClass: 'custom-class' });
  42. vm.open();
  43. expect(document.querySelector('.v-modal').classList.contains('custom-class')).to.true;
  44. });
  45. it('lock scroll', done => {
  46. vm = createTest(Popup, { modal: true });
  47. vm.open();
  48. expect(document.body.classList.contains('el-popup-parent--hidden')).to.be.true;
  49. vm.close();
  50. destroyVM(vm);
  51. setTimeout(() => {
  52. vm = createTest(Popup, { modal: true, lockScroll: false });
  53. vm.open();
  54. expect(document.body.classList.contains('el-popup-parent--hidden')).to.be.false;
  55. done();
  56. }, 200);
  57. });
  58. it('z-index should increase', () => {
  59. vm = createTest(Popup, { modal: true });
  60. vm.open();
  61. const zIndex1 = document.querySelector('.v-modal').style.zIndex;
  62. vm.close();
  63. destroyVM(vm);
  64. vm = createTest(Popup, { modal: true });
  65. vm.open();
  66. const zIndex2 = document.querySelector('.v-modal').style.zIndex;
  67. expect(zIndex2 > zIndex1).to.true;
  68. });
  69. });