loading.spec.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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.classList.contains('is-fullscreen')).to.true;
  100. vm.loading = false;
  101. document.body.removeChild(mask);
  102. document.body.removeChild(vm.$el);
  103. done();
  104. });
  105. });
  106. it('lock', done => {
  107. vm = createVue({
  108. template: `
  109. <div v-loading.fullscreen.lock="loading"></div>
  110. `,
  111. data() {
  112. return {
  113. loading: true
  114. };
  115. }
  116. }, true);
  117. Vue.nextTick(() => {
  118. expect(document.body.style.overflow).to.equal('hidden');
  119. vm.loading = false;
  120. document.body.removeChild(document.querySelector('.el-loading-mask'));
  121. document.body.removeChild(vm.$el);
  122. done();
  123. });
  124. });
  125. it('text', done => {
  126. vm = createVue({
  127. template: `
  128. <div v-loading="loading" element-loading-text="拼命加载中"></div>
  129. `,
  130. data() {
  131. return {
  132. loading: true
  133. };
  134. }
  135. }, true);
  136. Vue.nextTick(() => {
  137. const mask = document.querySelector('.el-loading-mask');
  138. const text = mask.querySelector('.el-loading-text');
  139. expect(text).to.exist;
  140. expect(text.textContent).to.equal('拼命加载中');
  141. done();
  142. });
  143. });
  144. });