|
|
|
@ -16,6 +16,11 @@ jest.mock('@grafana/runtime', () => ({ |
|
|
|
|
})), |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
const mockNavigate = jest.fn(); |
|
|
|
|
jest.mock('react-router-dom-v5-compat', () => ({ |
|
|
|
|
useNavigate: () => mockNavigate, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
jest.mock('app/api/clients/provisioning/v0alpha1', () => ({ |
|
|
|
|
useDeleteRepositoryFilesWithPathMutation: jest.fn(), |
|
|
|
|
provisioningAPI: { |
|
|
|
@ -140,6 +145,7 @@ function setup( |
|
|
|
|
...renderResult, |
|
|
|
|
onDismiss, |
|
|
|
|
mockDeleteRepoFile, |
|
|
|
|
mockNavigate, |
|
|
|
|
clickDeleteButton, |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
@ -147,6 +153,7 @@ function setup( |
|
|
|
|
describe('DeleteProvisionedFolderForm', () => { |
|
|
|
|
beforeEach(() => { |
|
|
|
|
jest.clearAllMocks(); |
|
|
|
|
mockNavigate.mockClear(); |
|
|
|
|
jest.spyOn(console, 'error').mockImplementation(() => {}); |
|
|
|
|
// Mock window.location.href
|
|
|
|
|
Object.defineProperty(window, 'location', { |
|
|
|
@ -272,13 +279,21 @@ describe('DeleteProvisionedFolderForm', () => { |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('should handle branch workflow success without navigation', async () => { |
|
|
|
|
it('should handle branch workflow success with navigation', async () => { |
|
|
|
|
const branchFormData = { ...mockFormData, workflow: 'branch' } as unknown as typeof mockFormData; |
|
|
|
|
const successState = { isLoading: false, isSuccess: true, isError: false, error: null }; |
|
|
|
|
setup({}, { ...defaultHookData, initialValues: branchFormData }, successState); |
|
|
|
|
const successState = { |
|
|
|
|
isLoading: false, |
|
|
|
|
isSuccess: true, |
|
|
|
|
isError: false, |
|
|
|
|
error: null, |
|
|
|
|
data: { urls: { newPullRequestURL: 'https://github.com/test/repo/pull/new' } }, |
|
|
|
|
}; |
|
|
|
|
const { mockNavigate } = setup({}, { ...defaultHookData, initialValues: branchFormData }, successState); |
|
|
|
|
|
|
|
|
|
await waitFor(() => { |
|
|
|
|
expect(window.location.href).toBe(''); |
|
|
|
|
expect(mockNavigate).toHaveBeenCalledWith( |
|
|
|
|
'/dashboards?new_pull_request_url=https://github.com/test/repo/pull/new' |
|
|
|
|
); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|