| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- import { mount, createLocalVue } from '@vue/test-utils'
- import Vuex from 'vuex'
- import ImageSelect from '../ImageSelect'
- import { IMAGES_TYPE_MAP } from '@/constants/compute'
- import { Manager } from '@/utils/manager'
- import i18n from '@/locales'
- const idcStandardImageList = [
- {
- name: 'test1',
- id: 1,
- disk_format: 'qcow2',
- properties: {
- arch: 'x86_64',
- distro: 'Windows Server 2012 R2 Datacenter',
- os_type: 'Windows',
- partition_type: 'mbr',
- version: '6.3',
- },
- },
- {
- name: 'test2',
- id: 2,
- disk_format: 'qcow2',
- properties: {
- net_driver: '',
- os_distribution: 'CentOS',
- os_type: 'Linux',
- partition_type: 'mbr',
- uefi_support: 'true',
- version: '8.0.1905',
- },
- },
- {
- name: 'test31',
- id: 3,
- disk_format: 'qcow2',
- properties: {
- os_type: 'linux',
- },
- },
- ]
- const idcStandardImageParams = {
- limit: 0,
- details: true,
- status: 'active',
- is_guest_image: false,
- scope: 'system',
- 'filter.0': 'disk_format.notequals(iso)',
- is_standard: true,
- }
- const $route = {
- query: {},
- }
- let store = null
- let setFieldsValue = null
- let getFieldsValue = null
- let decorator = null
- let localVue = null
- beforeEach(() => {
- setFieldsValue = jest.fn()
- decorator = {
- os: [
- 'os',
- {
- initialValue: '',
- rules: [{ required: true, message: i18n.t('compute.text_153') }],
- },
- ],
- image: [
- 'image',
- {
- initialValue: { key: '', label: '' },
- },
- ],
- }
- store = new Vuex.Store({
- getters: {
- scope: () => 'system', // !!! 如果写成 scope: 'system' 会报错,注意
- userInfo () {
- return {
- projectId: 'test',
- }
- },
- },
- })
- localVue = createLocalVue()
- localVue.use(Vuex)
- })
- describe('OsSelect', () => {
- it('IDC standard', () => {
- getFieldsValue = jest.fn(() => {
- return {
- os: 'Windows',
- image: {
- key: '90b59d90-45af-4dad-86ff-c2a19f689834',
- label: 'windows-server-2012-R2-VL-202008',
- },
- }
- })
- const wrapper = mount(ImageSelect, {
- provide () {
- return {
- form: {
- fc: {
- setFieldsValue,
- getFieldsValue,
- },
- },
- }
- },
- propsData: {
- decorator,
- type: 'idc',
- hypervisor: 'kvm',
- cloudType: 'idc',
- imageType: IMAGES_TYPE_MAP.standard.key,
- form: {
- fc: {
- setFieldsValue,
- getFieldsValue,
- },
- },
- },
- mocks: {
- $route,
- },
- localVue,
- store,
- })
- expect(wrapper.vm.$el).toMatchSnapshot()
- // 测试公共镜像的参数
- const imagesM = Manager.mock.instances[0]
- expect(imagesM.list.mock.calls[0][0].params).toEqual(idcStandardImageParams)
- wrapper.setData({
- images: {
- list: idcStandardImageList, // 公共镜像、iso、自定义镜像 list
- cacheimagesList: [], // idc: 镜像缓存list,用于对比哪些镜像已缓存,public|private: image-list
- hostimagesList: [], // 主机镜像 list
- instanceSnapshotsList: [], // 主机快照 list
- },
- })
- // 测试组件的 osOpts 和 imageOptsMap
- wrapper.vm.getImagesInfo()
- expect(wrapper.vm.imagesInfo.osOpts).toEqual([
- { label: 'Windows', key: 'Windows' },
- { label: 'CentOS', key: 'CentOS' },
- { label: 'Linux', key: 'Linux' },
- ])
- expect(wrapper.vm.imagesInfo.imageOptsMap).toEqual({
- Windows: [
- {
- name: 'test1',
- id: 1,
- disk_format: 'qcow2',
- properties: {
- arch: 'x86_64',
- distro: 'Windows Server 2012 R2 Datacenter',
- os_type: 'Windows',
- partition_type: 'mbr',
- version: '6.3',
- },
- feData: {
- name: 'test1',
- imageType: 'Windows',
- },
- },
- ],
- CentOS: [
- {
- name: 'test2',
- id: 2,
- disk_format: 'qcow2',
- properties: {
- net_driver: '',
- os_distribution: 'CentOS',
- os_type: 'Linux',
- partition_type: 'mbr',
- uefi_support: 'true',
- version: '8.0.1905',
- },
- feData: { name: 'CentOS (test2)', imageType: 'CentOS' },
- },
- ],
- Linux: [
- {
- name: 'test31',
- id: 3,
- disk_format: 'qcow2',
- properties: { os_type: 'linux' },
- feData: { name: 'test31', imageType: 'linux' },
- },
- ],
- })
- })
- })
|