loading.spec.js 3.4 KB

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