index.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { shallowMount } from '@vue/test-utils'
  2. import Backup from '../index.vue'
  3. jest.mock('@/utils/manager', () => {
  4. const hostlist = [
  5. { name: 'test1', id: 1 },
  6. { name: 'test2', id: 2 },
  7. { name: 'test3', id: 3 },
  8. ]
  9. function Manager () {}
  10. Manager.prototype.list = () => Promise.resolve({ data: { data: hostlist } })
  11. return { Manager }
  12. })
  13. describe('Backup switchDisabled', () => {
  14. const decorator = {
  15. backupEnable: [
  16. 'backupEnable',
  17. {
  18. valuePropName: 'checked',
  19. initialValue: false,
  20. },
  21. ],
  22. backup: [
  23. 'backup',
  24. ],
  25. }
  26. it('hostList.length decide switchDisabled false', () => {
  27. const wrapper = shallowMount(Backup, {
  28. propsData: { decorator },
  29. data () {
  30. return {
  31. backupEnable: false,
  32. }
  33. },
  34. })
  35. wrapper.vm.$nextTick(() => { // 已经模拟 manager 方法返回 hostList
  36. expect(wrapper.vm.switchDisabled).toBeFalsy()
  37. })
  38. })
  39. it('diskType=gpfs decide switchDisabled true', () => {
  40. const wrapper = shallowMount(Backup, {
  41. propsData: { decorator, diskType: 'gfs1' },
  42. })
  43. expect(wrapper.vm.switchDisabled).toBeTruthy()
  44. })
  45. })