mirror of
https://github.com/vatesfr/xen-orchestra.git
synced 2026-11-09 17:06:13 -06:00
test(web): share the running job expectation
The 7 job tests checking the "in progress" error of a running job use expectJobRunning; the V2V idle job tests check canRun alone, as the other job tests (canRun is the absence of error).
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -3,6 +3,7 @@ import type { FrontXoPlugin } from '@/modules/plugin/remote-resources/use-xo-plu
|
||||
import type { fetchPatch } from '@/shared/utils/fetch.util.ts'
|
||||
import { createPlugin } from '@/test/create-plugin.ts'
|
||||
import { t } from '@/test/i18n.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
|
||||
const { patch } = vi.hoisted(() => ({
|
||||
@@ -63,9 +64,6 @@ describe('validate', () => {
|
||||
patch.mockReturnValue(new Promise(() => {}))
|
||||
const job = mountAutoloadJob(createPlugin())
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(t('job:edit:in-progress'))
|
||||
expectJobRunning(job, t('job:edit:in-progress'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { useXoTaskUtils } from '@/shared/composables/xo-task-utils.composab
|
||||
import type { fetchPatch, fetchPost } from '@/shared/utils/fetch.util.ts'
|
||||
import { createPlugin } from '@/test/create-plugin.ts'
|
||||
import { t } from '@/test/i18n.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
import { silenceConsoleError } from '@/test/silence-console-error.ts'
|
||||
|
||||
@@ -128,9 +129,6 @@ describe('validate', () => {
|
||||
post.mockReturnValue(new Promise(() => {}))
|
||||
const job = mountChangeStateJob(plugin, loaded)
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(t(key))
|
||||
expectJobRunning(job, t(key))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { FrontXoPlugin } from '@/modules/plugin/remote-resources/use-xo-plu
|
||||
import type { fetchPut } from '@/shared/utils/fetch.util.ts'
|
||||
import { createPlugin } from '@/test/create-plugin.ts'
|
||||
import { t } from '@/test/i18n.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
|
||||
const { put } = vi.hoisted(() => ({
|
||||
@@ -72,9 +73,6 @@ describe('validate', () => {
|
||||
put.mockReturnValue(new Promise(() => {}))
|
||||
const job = mountConfigureJob(configurablePlugin)
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(t('job:edit:in-progress'))
|
||||
expectJobRunning(job, t('job:edit:in-progress'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { FrontXoPlugin } from '@/modules/plugin/remote-resources/use-xo-plu
|
||||
import type { fetchDelete } from '@/shared/utils/fetch.util.ts'
|
||||
import { createPlugin } from '@/test/create-plugin.ts'
|
||||
import { t } from '@/test/i18n.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
|
||||
const { remove } = vi.hoisted(() => ({
|
||||
@@ -79,9 +80,6 @@ describe('validate', () => {
|
||||
remove.mockReturnValue(new Promise(() => {}))
|
||||
const job = mountDeleteConfigurationJob(configuredPlugin)
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(t('job:delete:in-progress'))
|
||||
expectJobRunning(job, t('job:delete:in-progress'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { useXoTaskUtils } from '@/shared/composables/xo-task-utils.composab
|
||||
import type { fetchPost } from '@/shared/utils/fetch.util.ts'
|
||||
import { createPlugin } from '@/test/create-plugin.ts'
|
||||
import { t } from '@/test/i18n.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposable } from '@/test/mount-composable.ts'
|
||||
|
||||
const { post, monitorTask } = vi.hoisted(() => ({
|
||||
@@ -85,9 +86,6 @@ describe('validate', () => {
|
||||
post.mockReturnValue(new Promise(() => {}))
|
||||
const job = mountTestJob(testablePlugin)
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(t('job:plugin-test:in-progress'))
|
||||
expectJobRunning(job, t('job:plugin-test:in-progress'))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -3,6 +3,7 @@ import { ApiError } from '@/shared/error/api.error.ts'
|
||||
import { createV2vConnection } from '@/test/create-v2v-connection.ts'
|
||||
import { createV2vInventory } from '@/test/create-v2v-inventory.ts'
|
||||
import { hasRequested } from '@/test/fetch-requests.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposableWithI18n } from '@/test/mount-composable.ts'
|
||||
import { stubFetchResponse } from '@/test/stub-fetch-response.ts'
|
||||
import { stubV2vInvalidCredentialsResponse } from '@/test/stub-v2v-invalid-credentials-response.ts'
|
||||
@@ -40,16 +41,12 @@ describe('errorMessage', () => {
|
||||
it('reports a connection in progress', () => {
|
||||
const job = mountInventoryJob(createV2vConnection())
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(job.t('job:connect:in-progress'))
|
||||
expectJobRunning(job, job.t('job:connect:in-progress'))
|
||||
})
|
||||
|
||||
it('has no error with a connection when idle', () => {
|
||||
it('can run with a connection', () => {
|
||||
const job = mountInventoryJob(createV2vConnection())
|
||||
|
||||
expect(job.canRun).toBe(true)
|
||||
expect(job.errorMessage).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
V2V_START_TASK_ID,
|
||||
} from '@/test/create-v2v-launch.ts'
|
||||
import { hasRequested } from '@/test/fetch-requests.ts'
|
||||
import { expectJobRunning } from '@/test/job-running.ts'
|
||||
import { mountComposableWithI18n } from '@/test/mount-composable.ts'
|
||||
import type { XoV2vStartPayload } from '@vates/types'
|
||||
|
||||
@@ -41,10 +42,7 @@ describe('errorMessage', () => {
|
||||
it('reports a launch in progress', () => {
|
||||
const job = mountStartJob(POOL, PAYLOAD)
|
||||
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(job.t('job:v2v-start:in-progress'))
|
||||
expectJobRunning(job, job.t('job:v2v-start:in-progress'))
|
||||
})
|
||||
|
||||
it('reports a missing pool', () => {
|
||||
@@ -68,10 +66,9 @@ describe('errorMessage', () => {
|
||||
expect(job.errorMessage).toBe(job.t('job:v2v-start:missing-vm'))
|
||||
})
|
||||
|
||||
it('has no error with a pool and a payload of one VM when idle', () => {
|
||||
it('can run with a pool and a payload of one VM', () => {
|
||||
const job = mountStartJob(POOL, PAYLOAD)
|
||||
|
||||
expect(job.canRun).toBe(true)
|
||||
expect(job.errorMessage).toBeUndefined()
|
||||
})
|
||||
})
|
||||
|
||||
16
@xen-orchestra/web/src/test/job-running.ts
Normal file
16
@xen-orchestra/web/src/test/job-running.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
type RunnableJob = {
|
||||
run: () => Promise<unknown>
|
||||
isRunning: boolean
|
||||
errorMessage: string | undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a job whose request never settles, then expects it running and reporting `message`, its "in progress" error.
|
||||
* The test stubs the request beforehand (a pending promise), or relies on the pending `fetch` of `setup.ts`.
|
||||
*/
|
||||
export function expectJobRunning(job: RunnableJob, message: string) {
|
||||
void job.run()
|
||||
|
||||
expect(job.isRunning).toBe(true)
|
||||
expect(job.errorMessage).toBe(message)
|
||||
}
|
||||
Reference in New Issue
Block a user