loading.spec.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { createVue } from '../util';
  2. import Vue from 'vue';
  3. describe('Loading', () => {
  4. it('create', done => {
  5. const vm = createVue({
  6. template: `
  7. <div v-loading="loading"></div>
  8. `,
  9. data() {
  10. return {
  11. loading: true
  12. };
  13. }
  14. });
  15. Vue.nextTick(() => {
  16. const mask = vm.$el.querySelector('.el-loading-mask');
  17. expect(mask).to.exist;
  18. vm.loading = false;
  19. setTimeout(() => {
  20. expect(mask.style.display).to.equal('none');
  21. done();
  22. }, 100);
  23. });
  24. });
  25. it('unbind', done => {
  26. const vm1 = createVue({
  27. template: `
  28. <div v-if="show" v-loading="loading"></div>
  29. `,
  30. data() {
  31. return {
  32. show: true,
  33. loading: true
  34. };
  35. }
  36. });
  37. const vm2 = createVue({
  38. template: `
  39. <div v-if="show" v-loading.body="loading"></div>
  40. `,
  41. data() {
  42. return {
  43. show: true,
  44. loading: true
  45. };
  46. }
  47. });
  48. Vue.nextTick(() => {
  49. vm1.loading = false;
  50. vm2.loading = false;
  51. Vue.nextTick(() => {
  52. vm1.show = false;
  53. vm2.show = false;
  54. Vue.nextTick(() => {
  55. expect(document.querySelector('.el-loading-mask')).to.not.exist;
  56. done();
  57. });
  58. });
  59. });
  60. });
  61. it('body', done => {
  62. const vm = createVue({
  63. template: `
  64. <div v-loading.body="loading"></div>
  65. `,
  66. data() {
  67. return {
  68. loading: true
  69. };
  70. }
  71. }, true);
  72. Vue.nextTick(() => {
  73. const mask = document.querySelector('.el-loading-mask');
  74. expect(mask.parentNode === document.body).to.true;
  75. vm.loading = false;
  76. document.body.removeChild(mask);
  77. document.body.removeChild(vm.$el);
  78. done();
  79. });
  80. });
  81. it('fullscreen', done => {
  82. const vm = createVue({
  83. template: `
  84. <div v-loading.fullscreen="loading"></div>
  85. `,
  86. data() {
  87. return {
  88. loading: true
  89. };
  90. }
  91. }, true);
  92. Vue.nextTick(() => {
  93. const mask = document.querySelector('.el-loading-mask');
  94. expect(mask.parentNode === document.body).to.true;
  95. expect(mask.style.left).to.equal('0px');
  96. expect(mask.style.right).to.equal('0px');
  97. expect(mask.style.position).to.equal('fixed');
  98. vm.loading = false;
  99. document.body.removeChild(mask);
  100. document.body.removeChild(vm.$el);
  101. done();
  102. });
  103. });
  104. it('lock', done => {
  105. const vm = createVue({
  106. template: `
  107. <div v-loading.fullscreen.lock="loading"></div>
  108. `,
  109. data() {
  110. return {
  111. loading: true
  112. };
  113. }
  114. }, true);
  115. Vue.nextTick(() => {
  116. expect(document.body.style.overflow).to.equal('hidden');
  117. vm.loading = false;
  118. document.body.removeChild(document.querySelector('.el-loading-mask'));
  119. document.body.removeChild(vm.$el);
  120. done();
  121. });
  122. });
  123. });