mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-09 17:06:13 -06:00
test(web): read the V2V listed VM, empty and stored lists from the shared fixtures
This commit is contained in:
@@ -49,7 +49,7 @@ const poolStats = createPoolStats({
|
||||
const dashboard = createPoolDashboardTopFiveUsage({ cpu: [createHostCpuUsage()] }, { cpu: [createVmCpuUsage()] })
|
||||
```
|
||||
|
||||
Shared _helper_ factories live there too — `mount-composable.ts`, `mount-chart-card.ts`, `create-enhanced-data-helpers.ts`, `global-test-config.ts`, `create-test-router.ts`, `create-job-result.ts` (what a mocked `defineJob` composable returns), `create-action-item.ts` (a menu / button `LeafActionItem`), `create-plugin-actions.ts` (what a mocked `useXoPluginActions` returns), `find-rendered-values.ts`, `find-tags.ts` (the labels of the rendered tags), `find-titles.ts` (the card and section titles), `find-tooltip-content.ts` (the tooltip an element shows on hover), `get-button.ts` (by its label, or the `aria-label` of an icon button: `findButton` / `getButton` the `<button>` to click, `getUiButton` the `UiButton` whose `busy` / `disabled` props the app sets), `get-checkbox.ts` (the input of a `UiCheckbox` by its label), `drawer.ts` (submit or cancel a drawer, read its buttons), `select.ts` (open a `VtsSelect`, read or pick its options, read the selection it shows), `mount-json-schema-form.ts` (a JSON schema form, or a composable run in one of its fields), `json-schema-item-label.ts` (the labels of the items of a JSON schema list), `find-parts.ts`, `find-input-labels.ts`, `find-input-messages.ts`, `find-accented-labels.ts` (`findAccentedTags` / `findAccentedInfos`: each `UiTag` / `UiInfo` as `{ label, accent }`), `find-card-title.ts` (`findCardTitle`, the whole title; `findCardTitleLabel`, its label alone), `create-select-bindings.ts`, `find-select-stub-labels.ts`, `mount-with-select.ts`, `form-messages.ts`, `credentials-error-wiring.ts`, `stub-fetch-response.ts`, `stub-v2v-invalid-credentials-response.ts` (the 422 the V2V routes answer to rejected credentials), `silence-console-error.ts`, `create-v2v-wizard-router.ts` (and `V2V_VMS_FILTER_QUERY_KEY`, the route key of the VMs step filter), `mount-on-v2v-wizard.ts` (`mountOnV2vWizard`: stores a migration list, routes the wizard to a step, on the pool of the list unless given a query, mounts with that router and the connection of a source), `mount-v2v-vms-step.ts` (`mountV2vVmsStep`: mounts a composable on the VMs step, with a stored list and a connected source), `create-v2v-vm-row.ts` (also `getV2vVmNames` / `getV2vVmIds`, the names / ids of V2V VMs or rows, in order), `v2v-vms-fixtures.ts` (two datastores and one inventory VM per case the VMs step tells apart: on one datastore, on both, unsupported, in the list), `v2v-wizard-fixtures.ts` (the connected source, a list stored for a pool without VMs then with some, that pool and another one), `find-table-cells.ts` (see [Testing components](./testing-components.md#tables)), `query-builder-filters.ts` (`UNPARSABLE_FILTER`), `local-storage.ts`, `v2v-remembered-connections-storage.ts`, `v2v-migration-list-storage.ts`, `fill-v2v-connection-form.ts`, `choose-v2v-destination.ts` (choose the pool of the V2V destination form, or a complete destination), `seed-v2v-destination-pools.ts` (the collections a V2V destination pool offers its prefill from), `v2v-connection-provide.ts` (the V2V connection the migration page provides), `v2v-connection-reader.ts` (a component that reads the V2V connection its parent provides), `now.ts` (the fixed date of the fake timers), `group-by.ts`, `i18n.ts` and `linear-chart-stub.ts`. The shared module mocks (`mock-xo-*.ts`, `mock-delete-modal.ts`) live there as well, see [mocking.md](./mocking.md).
|
||||
Shared _helper_ factories live there too — `mount-composable.ts`, `mount-chart-card.ts`, `create-enhanced-data-helpers.ts`, `global-test-config.ts`, `create-test-router.ts`, `create-job-result.ts` (what a mocked `defineJob` composable returns), `create-action-item.ts` (a menu / button `LeafActionItem`), `create-plugin-actions.ts` (what a mocked `useXoPluginActions` returns), `find-rendered-values.ts`, `find-tags.ts` (the labels of the rendered tags), `find-titles.ts` (the card and section titles), `find-tooltip-content.ts` (the tooltip an element shows on hover), `get-button.ts` (by its label, or the `aria-label` of an icon button: `findButton` / `getButton` the `<button>` to click, `getUiButton` the `UiButton` whose `busy` / `disabled` props the app sets), `get-checkbox.ts` (the input of a `UiCheckbox` by its label), `drawer.ts` (submit or cancel a drawer, read its buttons), `select.ts` (open a `VtsSelect`, read or pick its options, read the selection it shows), `mount-json-schema-form.ts` (a JSON schema form, or a composable run in one of its fields), `json-schema-item-label.ts` (the labels of the items of a JSON schema list), `find-parts.ts`, `find-input-labels.ts`, `find-input-messages.ts`, `find-accented-labels.ts` (`findAccentedTags` / `findAccentedInfos`: each `UiTag` / `UiInfo` as `{ label, accent }`), `find-card-title.ts` (`findCardTitle`, the whole title; `findCardTitleLabel`, its label alone), `create-select-bindings.ts`, `find-select-stub-labels.ts`, `mount-with-select.ts`, `form-messages.ts`, `credentials-error-wiring.ts`, `stub-fetch-response.ts`, `stub-v2v-invalid-credentials-response.ts` (the 422 the V2V routes answer to rejected credentials), `silence-console-error.ts`, `create-v2v-wizard-router.ts` (and `V2V_VMS_FILTER_QUERY_KEY`, the route key of the VMs step filter), `mount-on-v2v-wizard.ts` (`mountOnV2vWizard`: stores a migration list, routes the wizard to a step, on the pool of the list unless given a query, mounts with that router and the connection of a source), `mount-v2v-vms-step.ts` (`mountV2vVmsStep`: mounts a composable on the VMs step, with a stored list and a connected source), `create-v2v-vm-row.ts` (also `getV2vVmNames` / `getV2vVmIds`, the names / ids of V2V VMs or rows, in order), `v2v-vms-fixtures.ts` (two datastores and one inventory VM per case the VMs step tells apart: on one datastore, on both, unsupported, in the list, and the list holding that last one), `v2v-wizard-fixtures.ts` (the connected source, a list stored for a pool without VMs then with some, that pool and another one), `find-table-cells.ts` (see [Testing components](./testing-components.md#tables)), `query-builder-filters.ts` (`UNPARSABLE_FILTER`), `local-storage.ts`, `v2v-remembered-connections-storage.ts`, `v2v-migration-list-storage.ts`, `fill-v2v-connection-form.ts`, `choose-v2v-destination.ts` (choose the pool of the V2V destination form, or a complete destination), `seed-v2v-destination-pools.ts` (the collections a V2V destination pool offers its prefill from), `v2v-connection-provide.ts` (the V2V connection the migration page provides), `v2v-connection-reader.ts` (a component that reads the V2V connection its parent provides), `now.ts` (the fixed date of the fake timers), `group-by.ts`, `i18n.ts` and `linear-chart-stub.ts`. The shared module mocks (`mock-xo-*.ts`, `mock-delete-modal.ts`) live there as well, see [mocking.md](./mocking.md).
|
||||
|
||||
Each factory returns a **fully-populated** object of the real front-end type and accepts a `Partial<T>` of overrides, spread last, so a test only states the fields relevant to its case:
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useV2vVmsStep } from '@/modules/v2v/composables/use-v2v-vms-step.compos
|
||||
import type { V2vMigrationList } from '@/modules/v2v/types/v2v-migration-list.type.ts'
|
||||
import { applyV2vPreset, V2V_VM_PRESETS } from '@/modules/v2v/utils/v2v-vm-presets.util.ts'
|
||||
import { createV2vConnection } from '@/test/create-v2v-connection.ts'
|
||||
import { createV2vMigrationList } from '@/test/create-v2v-migration-list.ts'
|
||||
import { createV2vListPair } from '@/test/create-v2v-selected-vms.ts'
|
||||
import { getV2vVmIds, getV2vVmNames } from '@/test/create-v2v-vm-row.ts'
|
||||
import { getV2vVmsQuery } from '@/test/create-v2v-wizard-router.ts'
|
||||
@@ -24,6 +23,7 @@ import {
|
||||
V2V_DATASTORE_B,
|
||||
V2V_DATASTORE_B_FILTER,
|
||||
V2V_LISTED_VM,
|
||||
V2V_LIST_WITH_LISTED_VM,
|
||||
V2V_VMS_INVENTORY,
|
||||
V2V_WEB_VM,
|
||||
} from '@/test/v2v-vms-fixtures.ts'
|
||||
@@ -59,16 +59,17 @@ vi.mock(
|
||||
)
|
||||
vi.mock(import('@core/composables/modals/use-delete-modal.ts'), () => import('@/test/mock-delete-modal.ts'))
|
||||
|
||||
const LIST = createV2vMigrationList({ vms: [{ id: V2V_LISTED_VM.id }] })
|
||||
|
||||
const DATASTORE_B_AND_NAME_FILTER = `${V2V_DATASTORE_B_FILTER} name:${V2V_LISTED_VM.name}`
|
||||
|
||||
const SOURCE_HOST = createV2vConnection().host
|
||||
|
||||
const SHOW_PANEL_LABEL = t('selected-vms-n', { n: LIST.vms.length })
|
||||
const SHOW_PANEL_LABEL = t('selected-vms-n', { n: V2V_LIST_WITH_LISTED_VM.vms.length })
|
||||
|
||||
// The children render what the step hands them, each covered by its own test: here only the wiring matters
|
||||
async function mountStep({ list = LIST, filter }: { list?: V2vMigrationList; filter?: string } = {}) {
|
||||
async function mountStep({
|
||||
list = V2V_LIST_WITH_LISTED_VM,
|
||||
filter,
|
||||
}: { list?: V2vMigrationList; filter?: string } = {}) {
|
||||
xoCollectionsMock.pools.value = [V2V_LIST_POOL]
|
||||
|
||||
const { mounted: wrapper, router } = await mountOnV2vWizard(
|
||||
@@ -86,7 +87,12 @@ async function mountStep({ list = LIST, filter }: { list?: V2vMigrationList; fil
|
||||
},
|
||||
}),
|
||||
}),
|
||||
{ step: 'vms', query: getV2vVmsQuery(LIST.poolId, filter), list, source: { inventory: V2V_VMS_INVENTORY } }
|
||||
{
|
||||
step: 'vms',
|
||||
query: getV2vVmsQuery(V2V_LIST_WITH_LISTED_VM.poolId, filter),
|
||||
list,
|
||||
source: { inventory: V2V_VMS_INVENTORY },
|
||||
}
|
||||
)
|
||||
|
||||
return { wrapper, router }
|
||||
@@ -153,8 +159,8 @@ describe('VMs', () => {
|
||||
it('offers the query builder of the VM properties', async () => {
|
||||
const { wrapper } = await mountStep()
|
||||
const { result: vmsStep } = await mountV2vVmsStep(() => useV2vVmsStep(), {
|
||||
list: LIST,
|
||||
query: getV2vVmsQuery(LIST.poolId),
|
||||
list: V2V_LIST_WITH_LISTED_VM,
|
||||
query: getV2vVmsQuery(V2V_LIST_WITH_LISTED_VM.poolId),
|
||||
})
|
||||
|
||||
expect(getQueryBuilder(wrapper).props('schema')).toEqual(vmsStep.schema)
|
||||
|
||||
@@ -12,22 +12,23 @@ import { writeLocalStorageFromAnotherTab } from '@/test/local-storage.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
import { silenceConsoleError } from '@/test/silence-console-error.ts'
|
||||
import { readV2vMigrationListStorage, seedV2vMigrationList } from '@/test/v2v-migration-list-storage.ts'
|
||||
import { V2V_EMPTY_LIST, V2V_LIST_WITH_VMS } from '@/test/v2v-wizard-fixtures.ts'
|
||||
import { nextTick, type Ref, ref } from 'vue'
|
||||
|
||||
const [FIRST_VM, SECOND_VM, THIRD_VM, FOURTH_VM] = createV2vMigrationListVms(4)
|
||||
|
||||
const STORED_LIST = createV2vMigrationList({ vms: [FIRST_VM, SECOND_VM] })
|
||||
|
||||
// Every write rebuilds the list without this field: finding it again proves nothing was written
|
||||
const UNWRITTEN_LIST = { ...STORED_LIST, unknownField: true }
|
||||
const UNWRITTEN_LIST = { ...V2V_LIST_WITH_VMS, unknownField: true }
|
||||
|
||||
const { sourceId: SOURCE_ID, poolId: POOL_ID } = STORED_LIST
|
||||
const { sourceId: SOURCE_ID, poolId: POOL_ID } = V2V_LIST_WITH_VMS
|
||||
|
||||
const NEW_DEFAULTS = createV2vDestinationDefaults({
|
||||
template: 'template-2' as V2vMigrationList['defaults']['template'],
|
||||
})
|
||||
|
||||
const STORAGE_KEY = getV2vMigrationListStorageKey(STORED_LIST)
|
||||
const NEW_DEFAULTS_LIST = createV2vMigrationList({ defaults: NEW_DEFAULTS })
|
||||
|
||||
const STORAGE_KEY = getV2vMigrationListStorageKey(V2V_LIST_WITH_VMS)
|
||||
|
||||
type MountOptions = {
|
||||
sourceId?: Ref<string | undefined>
|
||||
@@ -55,7 +56,7 @@ function readStorageAfter(storedList: V2vMigrationList, write: ListWrite, option
|
||||
// A list is only written for a known source and pool, whichever function writes it
|
||||
function itStoresNothingWithoutSourceOrPool(write: ListWrite) {
|
||||
it.each(WITHOUT_SOURCE_OR_POOL)('leaves the stored list untouched without a %s', (_, options) => {
|
||||
expect(readStorageAfter(STORED_LIST, write, options)).toEqual(STORED_LIST)
|
||||
expect(readStorageAfter(V2V_LIST_WITH_VMS, write, options)).toEqual(V2V_LIST_WITH_VMS)
|
||||
expect(localStorage.length).toBe(1)
|
||||
})
|
||||
}
|
||||
@@ -73,9 +74,9 @@ function itStoresNoVmWithoutList(write: ListWrite) {
|
||||
|
||||
describe('list', () => {
|
||||
it('is the list stored for the source and the pool', () => {
|
||||
seedV2vMigrationList(STORED_LIST)
|
||||
seedV2vMigrationList(V2V_LIST_WITH_VMS)
|
||||
|
||||
expect(mountMigrationList().list).toEqual(STORED_LIST)
|
||||
expect(mountMigrationList().list).toEqual(V2V_LIST_WITH_VMS)
|
||||
})
|
||||
|
||||
it('is undefined when no list is stored', () => {
|
||||
@@ -92,14 +93,14 @@ describe('list', () => {
|
||||
})
|
||||
|
||||
it.each(WITHOUT_SOURCE_OR_POOL)('is undefined without a %s', (_, options) => {
|
||||
seedV2vMigrationList(STORED_LIST)
|
||||
seedV2vMigrationList(V2V_LIST_WITH_VMS)
|
||||
|
||||
expect(mountMigrationList(options).list).toBeUndefined()
|
||||
})
|
||||
|
||||
it('reads the list of the newly chosen pool', async () => {
|
||||
const otherList = createV2vMigrationList({ poolId: OTHER_POOL_ID })
|
||||
seedV2vMigrationList(STORED_LIST)
|
||||
seedV2vMigrationList(V2V_LIST_WITH_VMS)
|
||||
seedV2vMigrationList(otherList)
|
||||
const poolId = ref<FrontXoPool['id'] | undefined>(POOL_ID)
|
||||
const result = mountMigrationList({ poolId })
|
||||
@@ -113,15 +114,15 @@ describe('list', () => {
|
||||
it('follows the changes made in another tab', async () => {
|
||||
const result = mountMigrationList()
|
||||
|
||||
await writeLocalStorageFromAnotherTab(STORAGE_KEY, JSON.stringify(STORED_LIST))
|
||||
await writeLocalStorageFromAnotherTab(STORAGE_KEY, JSON.stringify(V2V_LIST_WITH_VMS))
|
||||
|
||||
expect(result.list).toEqual(STORED_LIST)
|
||||
expect(result.list).toEqual(V2V_LIST_WITH_VMS)
|
||||
})
|
||||
})
|
||||
|
||||
describe('vmCount', () => {
|
||||
it('counts the VMs of the stored list', () => {
|
||||
seedV2vMigrationList(STORED_LIST)
|
||||
seedV2vMigrationList(V2V_LIST_WITH_VMS)
|
||||
|
||||
expect(mountMigrationList().vmCount).toBe(2)
|
||||
})
|
||||
@@ -133,13 +134,13 @@ describe('vmCount', () => {
|
||||
|
||||
describe('hasVms', () => {
|
||||
it('is true once the stored list holds VMs', () => {
|
||||
seedV2vMigrationList(STORED_LIST)
|
||||
seedV2vMigrationList(V2V_LIST_WITH_VMS)
|
||||
|
||||
expect(mountMigrationList().hasVms).toBe(true)
|
||||
})
|
||||
|
||||
it.each([
|
||||
['the stored list holds no VM', createV2vMigrationList()],
|
||||
['the stored list holds no VM', V2V_EMPTY_LIST],
|
||||
['no list is stored', undefined],
|
||||
])('is false when %s', (_, list) => {
|
||||
if (list !== undefined) {
|
||||
@@ -154,13 +155,13 @@ describe('saveDefaults', () => {
|
||||
it('stores a new list with the defaults and no VM', () => {
|
||||
mountMigrationList().saveDefaults(NEW_DEFAULTS)
|
||||
|
||||
expect(readV2vMigrationListStorage()).toEqual(createV2vMigrationList({ defaults: NEW_DEFAULTS }))
|
||||
expect(readV2vMigrationListStorage()).toEqual(NEW_DEFAULTS_LIST)
|
||||
})
|
||||
|
||||
it('keeps the VMs of the stored list', () => {
|
||||
const storedList = readStorageAfter(STORED_LIST, result => result.saveDefaults(NEW_DEFAULTS))
|
||||
const storedList = readStorageAfter(V2V_LIST_WITH_VMS, result => result.saveDefaults(NEW_DEFAULTS))
|
||||
|
||||
expect(storedList).toEqual({ ...STORED_LIST, defaults: NEW_DEFAULTS })
|
||||
expect(storedList).toEqual({ ...V2V_LIST_WITH_VMS, defaults: NEW_DEFAULTS })
|
||||
})
|
||||
|
||||
itStoresNothingWithoutSourceOrPool(result => result.saveDefaults(NEW_DEFAULTS))
|
||||
@@ -175,32 +176,29 @@ describe('saveDefaults', () => {
|
||||
|
||||
result.saveDefaults(NEW_DEFAULTS)
|
||||
|
||||
expect(result.list).toEqual(createV2vMigrationList({ defaults: NEW_DEFAULTS }))
|
||||
expect(result.list).toEqual(NEW_DEFAULTS_LIST)
|
||||
expect(consoleError).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
describe('addVms', () => {
|
||||
it('persists the VMs', () => {
|
||||
const storedList = readStorageAfter(createV2vMigrationList(), result => result.addVms([FIRST_VM.id, SECOND_VM.id]))
|
||||
const storedList = readStorageAfter(V2V_EMPTY_LIST, result => result.addVms([FIRST_VM.id, SECOND_VM.id]))
|
||||
|
||||
expect(storedList).toEqual(STORED_LIST)
|
||||
expect(storedList).toEqual(V2V_LIST_WITH_VMS)
|
||||
})
|
||||
|
||||
it('keeps the existing VMs first', () => {
|
||||
const storedList = readStorageAfter(STORED_LIST, result => result.addVms([FOURTH_VM.id, THIRD_VM.id]))
|
||||
const storedList = readStorageAfter(V2V_LIST_WITH_VMS, result => result.addVms([FOURTH_VM.id, THIRD_VM.id]))
|
||||
|
||||
expect(storedList).toEqual(createV2vMigrationList({ vms: [FIRST_VM, SECOND_VM, FOURTH_VM, THIRD_VM] }))
|
||||
})
|
||||
|
||||
it('skips an id already in the list', () => {
|
||||
const storedList = readStorageAfter(STORED_LIST, result => result.addVms([SECOND_VM.id, THIRD_VM.id]))
|
||||
|
||||
expect(storedList).toEqual(createV2vMigrationList({ vms: [FIRST_VM, SECOND_VM, THIRD_VM] }))
|
||||
})
|
||||
|
||||
it('skips an id duplicated in its argument', () => {
|
||||
const storedList = readStorageAfter(STORED_LIST, result => result.addVms([THIRD_VM.id, THIRD_VM.id]))
|
||||
it.each([
|
||||
['already in the list', [SECOND_VM.id, THIRD_VM.id]],
|
||||
['duplicated in its argument', [THIRD_VM.id, THIRD_VM.id]],
|
||||
])('skips an id %s', (_, vmIds) => {
|
||||
const storedList = readStorageAfter(V2V_LIST_WITH_VMS, result => result.addVms(vmIds))
|
||||
|
||||
expect(storedList).toEqual(createV2vMigrationList({ vms: [FIRST_VM, SECOND_VM, THIRD_VM] }))
|
||||
})
|
||||
@@ -214,7 +212,7 @@ describe('addVms', () => {
|
||||
|
||||
describe('removeVm', () => {
|
||||
it('deletes the VM and keeps the others', () => {
|
||||
const storedList = readStorageAfter(STORED_LIST, result => result.removeVm(FIRST_VM.id))
|
||||
const storedList = readStorageAfter(V2V_LIST_WITH_VMS, result => result.removeVm(FIRST_VM.id))
|
||||
|
||||
expect(storedList).toEqual(createV2vMigrationList({ vms: [SECOND_VM] }))
|
||||
})
|
||||
@@ -232,7 +230,7 @@ describe('clearVms', () => {
|
||||
|
||||
const storedList = readStorageAfter(listWithNewDefaults, result => result.clearVms())
|
||||
|
||||
expect(storedList).toEqual(createV2vMigrationList({ defaults: NEW_DEFAULTS }))
|
||||
expect(storedList).toEqual(NEW_DEFAULTS_LIST)
|
||||
})
|
||||
|
||||
itStoresNoVmWithoutList(result => result.clearVms())
|
||||
|
||||
@@ -55,6 +55,8 @@ const NETWORK = createNetwork({ id: LIST.defaults.network, name_label: 'VLAN 10'
|
||||
|
||||
const GONE_VM_ID = 'vm-gone' as XoV2vVm['id']
|
||||
|
||||
const GONE_VM_LIST = createV2vMigrationList({ vms: [{ id: GONE_VM_ID }] })
|
||||
|
||||
const WEB_LIST = createV2vMigrationList({ vms: [{ id: V2V_WEB_VM.id }] })
|
||||
|
||||
// The web VM is new, the DB one resumed
|
||||
@@ -109,7 +111,7 @@ describe('items', () => {
|
||||
})
|
||||
|
||||
it('names a VM gone from the inventory by its id', async () => {
|
||||
const { result } = await mountSelectedVms({ list: createV2vMigrationList({ vms: [{ id: GONE_VM_ID }] }) })
|
||||
const { result } = await mountSelectedVms({ list: GONE_VM_LIST })
|
||||
|
||||
expect(result.items.map(item => item.name)).toEqual([GONE_VM_ID])
|
||||
})
|
||||
@@ -124,7 +126,7 @@ describe('items', () => {
|
||||
})
|
||||
|
||||
it('leaves a VM gone from the inventory without a kind tag', async () => {
|
||||
const { result } = await mountSelectedVms({ list: createV2vMigrationList({ vms: [{ id: GONE_VM_ID }] }) })
|
||||
const { result } = await mountSelectedVms({ list: GONE_VM_LIST })
|
||||
|
||||
expect(result.items.map(item => item.kind)).toEqual([undefined])
|
||||
})
|
||||
|
||||
@@ -5,7 +5,6 @@ import { ONE_GB } from '@/shared/constants.ts'
|
||||
import { createV2vConnection } from '@/test/create-v2v-connection.ts'
|
||||
import { createV2vImportVm } from '@/test/create-v2v-import-vm.ts'
|
||||
import { createV2vInventory } from '@/test/create-v2v-inventory.ts'
|
||||
import { createV2vMigrationList } from '@/test/create-v2v-migration-list.ts'
|
||||
import { getV2vVmIds, getV2vVmNames } from '@/test/create-v2v-vm-row.ts'
|
||||
import { getV2vVmsQuery, V2V_VMS_FILTER_QUERY_KEY } from '@/test/create-v2v-wizard-router.ts'
|
||||
import { writeLocalStorageFromAnotherTab } from '@/test/local-storage.ts'
|
||||
@@ -18,10 +17,12 @@ import {
|
||||
V2V_DATASTORE_B_FILTER,
|
||||
V2V_DB_VM,
|
||||
V2V_LISTED_VM,
|
||||
V2V_LIST_WITH_LISTED_VM,
|
||||
V2V_RDM_VM,
|
||||
V2V_VMS_INVENTORY,
|
||||
V2V_WEB_VM,
|
||||
} from '@/test/v2v-vms-fixtures.ts'
|
||||
import { V2V_EMPTY_LIST } from '@/test/v2v-wizard-fixtures.ts'
|
||||
import type { XoV2vInventory, XoV2vVm } from '@vates/types'
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { toValue } from 'vue'
|
||||
@@ -43,19 +44,17 @@ vi.mock(
|
||||
() => import('@/test/mock-xo-collections.ts')
|
||||
)
|
||||
|
||||
const LIST = createV2vMigrationList({ vms: [{ id: V2V_LISTED_VM.id }] })
|
||||
|
||||
async function mountVmsStep({
|
||||
filter,
|
||||
inventory = V2V_VMS_INVENTORY,
|
||||
list = LIST,
|
||||
list = V2V_LIST_WITH_LISTED_VM,
|
||||
}: { filter?: string; inventory?: XoV2vInventory | null; list?: V2vMigrationList | null } = {}) {
|
||||
v2vVmRowsCollectionsMock.vms.value = [createV2vImportVm({ isWarm: true, sourceVmId: V2V_DB_VM.id })]
|
||||
|
||||
return mountV2vVmsStep(() => useV2vVmsStep(), {
|
||||
list,
|
||||
inventory,
|
||||
query: getV2vVmsQuery(LIST.poolId, filter),
|
||||
query: getV2vVmsQuery(V2V_LIST_WITH_LISTED_VM.poolId, filter),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -257,7 +256,10 @@ describe('addSelected', () => {
|
||||
|
||||
result.selection.toggle(V2V_WEB_VM.id)
|
||||
result.addSelected()
|
||||
await writeLocalStorageFromAnotherTab(getV2vMigrationListStorageKey(LIST), JSON.stringify(LIST))
|
||||
await writeLocalStorageFromAnotherTab(
|
||||
getV2vMigrationListStorageKey(V2V_LIST_WITH_LISTED_VM),
|
||||
JSON.stringify(V2V_LIST_WITH_LISTED_VM)
|
||||
)
|
||||
|
||||
expect(findPageRow(result, V2V_WEB_VM.id)).toMatchObject({ isSelectable: true, isSelected: false })
|
||||
})
|
||||
@@ -377,10 +379,10 @@ describe('selectedVmsContext', () => {
|
||||
|
||||
const { migrationList, rows, areRowsReady, poolId } = result.selectedVmsContext
|
||||
|
||||
expect(migrationList.list.value?.vms).toEqual(LIST.vms)
|
||||
expect(migrationList.list.value?.vms).toEqual(V2V_LIST_WITH_LISTED_VM.vms)
|
||||
expect(getV2vVmNames(toValue(rows))).toEqual(getV2vVmNames(V2V_VMS_INVENTORY.vms))
|
||||
expect(toValue(areRowsReady)).toBe(false)
|
||||
expect(toValue(poolId)).toBe(LIST.poolId)
|
||||
expect(toValue(poolId)).toBe(V2V_LIST_WITH_LISTED_VM.poolId)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -390,7 +392,7 @@ describe('navigation', () => {
|
||||
|
||||
await result.back()
|
||||
|
||||
expect(router.currentRoute.value.query).toMatchObject({ step: 'destination', pool: LIST.poolId })
|
||||
expect(router.currentRoute.value.query).toMatchObject({ step: 'destination', pool: V2V_LIST_WITH_LISTED_VM.poolId })
|
||||
})
|
||||
|
||||
it('goes on to the mapping, keeping the pool and the filter', async () => {
|
||||
@@ -400,7 +402,7 @@ describe('navigation', () => {
|
||||
|
||||
expect(router.currentRoute.value.query).toMatchObject({
|
||||
step: 'mapping',
|
||||
pool: LIST.poolId,
|
||||
pool: V2V_LIST_WITH_LISTED_VM.poolId,
|
||||
[V2V_VMS_FILTER_QUERY_KEY]: V2V_DATASTORE_B_FILTER,
|
||||
})
|
||||
})
|
||||
@@ -412,7 +414,7 @@ describe('navigation', () => {
|
||||
})
|
||||
|
||||
it.each([
|
||||
['an empty list', createV2vMigrationList({ vms: [] })],
|
||||
['an empty list', V2V_EMPTY_LIST],
|
||||
['no stored list', null],
|
||||
])('cannot go on with %s', async (_, list) => {
|
||||
const { result } = await mountVmsStep({ list })
|
||||
@@ -421,7 +423,7 @@ describe('navigation', () => {
|
||||
})
|
||||
|
||||
it('can go on once a VM is added', async () => {
|
||||
const { result } = await mountVmsStep({ list: createV2vMigrationList({ vms: [] }) })
|
||||
const { result } = await mountVmsStep({ list: V2V_EMPTY_LIST })
|
||||
|
||||
result.selection.toggle(V2V_WEB_VM.id)
|
||||
result.addSelected()
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ONE_GB } from '@/shared/constants.ts'
|
||||
import { createV2vDatastore, createV2vInventory, createV2vVmWithDisks } from '@/test/create-v2v-inventory.ts'
|
||||
import { createV2vMigrationList } from '@/test/create-v2v-migration-list.ts'
|
||||
import { V2V_VM_POWER_STATE, type XoV2vDatastore, type XoV2vVm } from '@vates/types'
|
||||
|
||||
export const V2V_DATASTORE_A = createV2vDatastore({ id: 'datastore-a' as XoV2vDatastore['id'], name: 'ds-a' })
|
||||
@@ -42,6 +43,8 @@ export const V2V_LISTED_VM = createV2vVmWithDisks([{ datastoreId: V2V_DATASTORE_
|
||||
datastoreIds: [V2V_DATASTORE_B.id],
|
||||
})
|
||||
|
||||
export const V2V_LIST_WITH_LISTED_VM = createV2vMigrationList({ vms: [{ id: V2V_LISTED_VM.id }] })
|
||||
|
||||
export const V2V_VMS_INVENTORY = createV2vInventory({
|
||||
datastores: [V2V_DATASTORE_A, V2V_DATASTORE_B],
|
||||
vms: [V2V_WEB_VM, V2V_DB_VM, V2V_RDM_VM, V2V_LISTED_VM],
|
||||
|
||||
Reference in New Issue
Block a user