-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
103 additions
and
0 deletions.
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
...ges/pipelines/global/modelCustomization/startRunModal/__tests__/useContinueState.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import { testHook } from '~/__tests__/unit/testUtils/hooks'; | ||
import { useIlabPipeline } from '~/concepts/pipelines/content/modelCustomizationForm/useIlabPipeline'; | ||
import { usePipelinesAPI } from '~/concepts/pipelines/context'; | ||
import { useContinueState } from '~/pages/pipelines/global/modelCustomization/startRunModal/useContinueState'; | ||
|
||
jest.mock('~/concepts/pipelines/context'); | ||
jest.mock('~/concepts/pipelines/content/modelCustomizationForm/useIlabPipeline'); | ||
|
||
describe('useContinueState', () => { | ||
const mockUsePipelinesAPI = usePipelinesAPI as jest.Mock; | ||
const mockUseIlabPipeline = useIlabPipeline as jest.Mock; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('is loading and cannot continue because the pipeline server is initializing', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ pipelinesServer: { initializing: true } }); | ||
mockUseIlabPipeline.mockReturnValue([null, false, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ canContinue: false, isLoading: true }); | ||
}); | ||
|
||
it('is loading and cannot continue because the ilab pipeline is not loaded', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ pipelinesServer: { initializing: false } }); | ||
mockUseIlabPipeline.mockReturnValue([null, false, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ canContinue: false, isLoading: true }); | ||
}); | ||
|
||
it('cannot continue because the pipeline server is not accessible', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ | ||
pipelinesServer: { | ||
initializing: false, | ||
installed: false, | ||
compatible: false, | ||
timedOut: false, | ||
}, | ||
}); | ||
mockUseIlabPipeline.mockReturnValue([null, true, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ | ||
canContinue: false, | ||
isLoading: false, | ||
unmetCondition: 'pipelineServerAccessible', | ||
}); | ||
}); | ||
|
||
it('cannot continue because the pipeline server is not online', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ | ||
pipelinesServer: { initializing: false, installed: true, compatible: true, timedOut: true }, | ||
}); | ||
mockUseIlabPipeline.mockReturnValue([null, true, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ | ||
canContinue: false, | ||
isLoading: false, | ||
unmetCondition: 'pipelineServerOnline', | ||
}); | ||
}); | ||
|
||
it('cannot continue because the pipeline server is not configured properly', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ | ||
pipelinesServer: { initializing: false, installed: true, compatible: false, timedOut: false }, | ||
}); | ||
mockUseIlabPipeline.mockReturnValue([null, false, new Error('Load error')]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ | ||
canContinue: false, | ||
isLoading: false, | ||
unmetCondition: 'pipelineServerConfigured', | ||
}); | ||
}); | ||
|
||
it('cannot continue because the ilab pipeline is not installed properly', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ | ||
pipelinesServer: { initializing: false, installed: true, compatible: true, timedOut: false }, | ||
}); | ||
mockUseIlabPipeline.mockReturnValue([null, true, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ | ||
canContinue: false, | ||
isLoading: false, | ||
unmetCondition: 'ilabPipelineInstalled', | ||
}); | ||
}); | ||
|
||
it('can continue because all conditions are met', () => { | ||
mockUsePipelinesAPI.mockReturnValue({ | ||
pipelinesServer: { initializing: false, installed: true, compatible: true, timedOut: false }, | ||
}); | ||
mockUseIlabPipeline.mockReturnValue([{}, true, null]); | ||
|
||
const renderResult = testHook(useContinueState)(); | ||
expect(renderResult.result.current).toEqual({ canContinue: true, isLoading: false }); | ||
}); | ||
}); |