-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bulk-import): bulk import ux improvements (#2124)
- Loading branch information
Showing
48 changed files
with
2,164 additions
and
1,357 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
148 changes: 148 additions & 0 deletions
148
plugins/bulk-import/src/components/AddRepositories/AddRepositoriesForm.test.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,148 @@ | ||
import React from 'react'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
|
||
import { configApiRef, identityApiRef } from '@backstage/core-plugin-api'; | ||
import { MockConfigApi, TestApiProvider } from '@backstage/test-utils'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
import { useFormikContext } from 'formik'; | ||
|
||
import { useDrawer } from '@janus-idp/shared-react'; | ||
|
||
import { bulkImportApiRef } from '../../api/BulkImportBackendClient'; | ||
import { mockGetImportJobs, mockGetRepositories } from '../../mocks/mockData'; | ||
import { ImportJobStatus, RepositorySelection } from '../../types'; | ||
import { AddRepositoriesForm } from './AddRepositoriesForm'; | ||
|
||
jest.mock('formik', () => ({ | ||
...jest.requireActual('formik'), | ||
useFormikContext: jest.fn(), | ||
})); | ||
|
||
jest.mock('./AddRepositoriesForm', () => ({ | ||
...jest.requireActual('./AddRepositoriesForm'), | ||
useStyles: jest.fn().mockReturnValue({ | ||
body: 'body', | ||
approvalTool: 'approvaltool', | ||
approvalToolTooltip: 'approvalToolTooltip', | ||
}), | ||
})); | ||
|
||
jest.mock('@janus-idp/shared-react', () => ({ | ||
...jest.requireActual('@janus-idp/shared-react'), | ||
useDrawer: jest.fn(), | ||
})); | ||
|
||
jest.mock('@material-ui/core', () => ({ | ||
...jest.requireActual('@material-ui/core'), | ||
makeStyles: () => () => { | ||
return { | ||
body: 'body', | ||
approvalTool: 'approvaltool', | ||
approvalToolTooltip: 'approvalToolTooltip', | ||
}; | ||
}, | ||
})); | ||
|
||
class MockBulkImportApi { | ||
async getImportAction( | ||
repo: string, | ||
_defaultBranch: string, | ||
): Promise<ImportJobStatus | Response> { | ||
return mockGetImportJobs.find( | ||
i => i.repository.url === repo, | ||
) as ImportJobStatus; | ||
} | ||
} | ||
|
||
const mockBulkImportApi = new MockBulkImportApi(); | ||
|
||
const mockIdentityApi = { | ||
getBackstageIdentity: jest | ||
.fn() | ||
.mockResolvedValue({ userEntityRef: 'user:default/testuser' }), | ||
}; | ||
|
||
beforeEach(() => { | ||
(useFormikContext as jest.Mock).mockReturnValue({ | ||
values: { | ||
repositoryType: RepositorySelection.Repository, | ||
}, | ||
setFieldValue: jest.fn(), | ||
}); | ||
}); | ||
|
||
describe('AddRepsositoriesForm', () => { | ||
it('should render the repositories list with the footer', async () => { | ||
(useDrawer as jest.Mock).mockImplementation(initial => ({ | ||
initial, | ||
setOpenDrawer: jest.fn(), | ||
setDrawerData: jest.fn(), | ||
})); | ||
render( | ||
<Router> | ||
<TestApiProvider | ||
apis={[ | ||
[identityApiRef, mockIdentityApi], | ||
[bulkImportApiRef, mockBulkImportApi], | ||
[ | ||
configApiRef, | ||
new MockConfigApi({ | ||
catalog: { | ||
import: { | ||
entityFilename: 'test.yaml', | ||
}, | ||
}, | ||
}), | ||
], | ||
]} | ||
> | ||
<AddRepositoriesForm error={null} /> | ||
</TestApiProvider> | ||
</Router>, | ||
); | ||
expect( | ||
screen.getByText('Selected repositories (0)', { exact: false }), | ||
).toBeInTheDocument(); | ||
expect(screen.getByTestId('add-repository-footer')).toBeInTheDocument(); | ||
|
||
expect(screen.queryByTestId('preview-pullrequest-sidebar')).toBeFalsy(); | ||
}); | ||
|
||
it('should show any load errors', async () => { | ||
(useDrawer as jest.Mock).mockReturnValue({ | ||
openDrawer: true, | ||
drawerData: mockGetRepositories.repositories[0], | ||
setOpenDrawer: jest.fn(), | ||
setDrawerData: jest.fn(), | ||
}); | ||
render( | ||
<Router> | ||
<TestApiProvider | ||
apis={[ | ||
[identityApiRef, mockIdentityApi], | ||
[bulkImportApiRef, mockBulkImportApi], | ||
[ | ||
configApiRef, | ||
new MockConfigApi({ | ||
catalog: { | ||
import: { | ||
entityFilename: 'test.yaml', | ||
}, | ||
}, | ||
}), | ||
], | ||
]} | ||
> | ||
<AddRepositoriesForm | ||
error={{ message: 'error', title: 'error occurred' }} | ||
/> | ||
</TestApiProvider> | ||
</Router>, | ||
); | ||
expect(screen.getByText('error occurred')).toBeTruthy(); | ||
expect( | ||
screen.getByText('Selected repositories (0)', { exact: false }), | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
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
Oops, something went wrong.