-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start workspace from default devfile on private repository SSH url (#…
…1286) (#1290) Remove the Devfile resolve from a privatre repositry via an SSH url is not supported warning and start workspace from the default devfile in this case.
- Loading branch information
Showing
4 changed files
with
35 additions
and
219 deletions.
There are no files selected for viewing
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
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
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 |
---|---|---|
|
@@ -13,7 +13,6 @@ | |
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
|
||
import { FACTORY_LINK_ATTR } from '@eclipse-che/common'; | ||
import { AlertVariant } from '@patternfly/react-core'; | ||
import { cleanup, screen, waitFor } from '@testing-library/react'; | ||
import userEvent, { UserEvent } from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
@@ -346,7 +345,7 @@ describe('Creating steps, fetching a devfile', () => { | |
}); | ||
}); | ||
|
||
describe('unsupported git provider error', () => { | ||
describe('unsupported git provider', () => { | ||
let emptyStore: Store; | ||
const rejectReason = 'Failed to fetch devfile'; | ||
|
||
|
@@ -355,110 +354,13 @@ describe('Creating steps, fetching a devfile', () => { | |
mockRequestFactoryResolver.mockRejectedValueOnce(rejectReason); | ||
}); | ||
|
||
test('alert title', async () => { | ||
test('should continue with the default devfile', async () => { | ||
renderComponent(emptyStore, searchParams); | ||
|
||
await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS); | ||
|
||
const expectAlertItem = expect.objectContaining({ | ||
title: 'Warning', | ||
actionCallbacks: [ | ||
expect.objectContaining({ | ||
title: 'Continue with default devfile', | ||
callback: expect.any(Function), | ||
}), | ||
expect.objectContaining({ | ||
title: 'Reload', | ||
callback: expect.any(Function), | ||
}), | ||
], | ||
}); | ||
await waitFor(() => expect(mockOnError).toHaveBeenCalledWith(expectAlertItem)); | ||
|
||
expect(mockOnNextStep).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('action "Continue with default devfile"', async () => { | ||
// this deferred object will help run the callback at the right time | ||
const deferred = getDefer(); | ||
|
||
const actionTitle = 'Continue with default devfile'; | ||
mockOnError.mockImplementationOnce((alertItem: AlertItem) => { | ||
const action = alertItem.actionCallbacks?.find(_action => | ||
_action.title.startsWith(actionTitle), | ||
); | ||
expect(action).toBeDefined(); | ||
|
||
if (action) { | ||
deferred.promise.then(action.callback); | ||
} else { | ||
throw new Error('Action not found'); | ||
} | ||
}); | ||
|
||
renderComponent(emptyStore, searchParams); | ||
await jest.runAllTimersAsync(); | ||
|
||
await waitFor(() => expect(mockOnError).toHaveBeenCalled()); | ||
expect(mockOnRestart).not.toHaveBeenCalled(); | ||
expect(mockOnNextStep).not.toHaveBeenCalled(); | ||
|
||
mockOnError.mockClear(); | ||
|
||
/* test the action */ | ||
await jest.runOnlyPendingTimersAsync(); | ||
|
||
// resolve deferred to trigger the callback | ||
deferred.resolve(); | ||
|
||
await waitFor(() => expect(mockOnNextStep).toHaveBeenCalled()); | ||
expect(mockOnRestart).not.toHaveBeenCalled(); | ||
expect(mockOnError).not.toHaveBeenCalled(); | ||
}); | ||
|
||
test('action "Reload"', async () => { | ||
// this deferred object will help run the callback at the right time | ||
const deferred = getDefer(); | ||
|
||
const actionTitle = 'Reload'; | ||
mockOnError.mockImplementationOnce(async (alertItem: AlertItem) => { | ||
const action = alertItem.actionCallbacks?.find(_action => | ||
_action.title.startsWith(actionTitle), | ||
); | ||
expect(action).toBeDefined(); | ||
|
||
if (action) { | ||
deferred.promise.then(action.callback); | ||
} else { | ||
throw new Error('Action not found'); | ||
} | ||
}); | ||
|
||
renderComponent(emptyStore, searchParams); | ||
await jest.runAllTimersAsync(); | ||
|
||
await waitFor(() => expect(mockOnError).toHaveBeenCalled()); | ||
expect(mockOnRestart).not.toHaveBeenCalled(); | ||
expect(mockOnNextStep).not.toHaveBeenCalled(); | ||
|
||
// first call resolves with error | ||
expect(mockRequestFactoryResolver).toHaveBeenCalledTimes(1); | ||
|
||
mockOnError.mockClear(); | ||
|
||
/* test the action */ | ||
|
||
await jest.runAllTimersAsync(); | ||
|
||
// resolve deferred to trigger the callback | ||
deferred.resolve(); | ||
|
||
await waitFor(() => expect(mockOnRestart).toHaveBeenCalled()); | ||
expect(mockOnNextStep).not.toHaveBeenCalled(); | ||
expect(mockOnError).not.toHaveBeenCalled(); | ||
|
||
// should request the factory resolver for the second time | ||
await waitFor(() => expect(mockRequestFactoryResolver).toHaveBeenCalledTimes(2)); | ||
await waitFor(() => expect(mockOnError).not.toHaveBeenCalled()); | ||
expect(mockOnNextStep).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
|
@@ -694,6 +596,7 @@ describe('Creating steps, fetching a devfile', () => { | |
const host = 'che-host'; | ||
const protocol = 'http://'; | ||
const factoryUrl = '[email protected]:user/repository-name.git'; | ||
const emptyStore = new MockStoreBuilder().build(); | ||
|
||
let spyWindowLocation: jest.SpyInstance; | ||
let location: Location; | ||
|
@@ -745,44 +648,32 @@ describe('Creating steps, fetching a devfile', () => { | |
expect(mockOnError).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should show warning on SSH url', async () => { | ||
const expectAlertItem = expect.objectContaining({ | ||
title: 'Warning', | ||
variant: AlertVariant.warning, | ||
children: ( | ||
<ExpandableWarning | ||
textBefore="Devfile resolve from a privatre repositry via an SSH url is not supported." | ||
errorMessage="Could not reach devfile" | ||
textAfter="Apply a Personal Access Token to fetch the devfile.yaml content." | ||
/> | ||
), | ||
actionCallbacks: [ | ||
expect.objectContaining({ | ||
title: 'Continue with default devfile', | ||
callback: expect.any(Function), | ||
}), | ||
expect.objectContaining({ | ||
title: 'Reload', | ||
callback: expect.any(Function), | ||
}), | ||
expect.objectContaining({ | ||
title: 'Open Documentation page', | ||
callback: expect.any(Function), | ||
}), | ||
], | ||
}); | ||
it('should use default devfile on private SSH url', async () => { | ||
searchParams = new URLSearchParams({ | ||
[FACTORY_URL_ATTR]: '[email protected]:user/repository.git', | ||
}); | ||
const emptyStore = new MockStoreBuilder().build(); | ||
|
||
renderComponent(emptyStore, searchParams, location); | ||
|
||
await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS); | ||
await waitFor(() => expect(mockOnNextStep).toHaveBeenCalled()); | ||
|
||
await waitFor(() => expect(mockOnNextStep).not.toHaveBeenCalled); | ||
expect(mockOpenOAuthPage).not.toHaveBeenCalled(); | ||
expect(mockOnError).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should use default devfile on bitbucket-server SSH url', async () => { | ||
searchParams = new URLSearchParams({ | ||
[FACTORY_URL_ATTR]: 'ssh://[email protected]/~user/repository.git', | ||
}); | ||
|
||
renderComponent(emptyStore, searchParams, location); | ||
|
||
await jest.advanceTimersByTimeAsync(MIN_STEP_DURATION_MS); | ||
await waitFor(() => expect(mockOnNextStep).toHaveBeenCalled); | ||
|
||
expect(mockOpenOAuthPage).not.toHaveBeenCalled(); | ||
expect(mockOnError).toHaveBeenCalledWith(expectAlertItem); | ||
expect(mockOnError).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); | ||
|
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