-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bulk-import): show bulk-import to authorized users
- Loading branch information
Showing
29 changed files
with
852 additions
and
317 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
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
57 changes: 57 additions & 0 deletions
57
plugins/bulk-import/src/components/BulkImportPage.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,57 @@ | ||
import React from 'react'; | ||
|
||
import { | ||
RequirePermission, | ||
usePermission, | ||
} from '@backstage/plugin-permission-react'; | ||
import { renderInTestApp } from '@backstage/test-utils'; | ||
|
||
import { screen } from '@testing-library/react'; | ||
|
||
import { useAddedRepositories } from '../hooks'; | ||
import { BulkImportPage } from './BulkImportPage'; | ||
|
||
jest.mock('@backstage/plugin-permission-react', () => ({ | ||
usePermission: jest.fn(), | ||
RequirePermission: jest.fn(), | ||
})); | ||
|
||
jest.mock('../hooks/useAddedRepositories', () => ({ | ||
useAddedRepositories: jest.fn(), | ||
})); | ||
|
||
const mockUsePermission = usePermission as jest.MockedFunction< | ||
typeof usePermission | ||
>; | ||
|
||
const mockUseAddedRepositories = useAddedRepositories as jest.MockedFunction< | ||
typeof useAddedRepositories | ||
>; | ||
|
||
const RequirePermissionMock = RequirePermission as jest.MockedFunction< | ||
typeof RequirePermission | ||
>; | ||
|
||
describe('BulkImport Page', () => { | ||
it('should render if user authorized to access bulk import plugin', async () => { | ||
RequirePermissionMock.mockImplementation(props => <>{props.children}</>); | ||
mockUsePermission.mockReturnValue({ loading: false, allowed: true }); | ||
mockUseAddedRepositories.mockReturnValue({ | ||
loading: true, | ||
data: [], | ||
retry: jest.fn(), | ||
error: undefined, | ||
}); | ||
await renderInTestApp(<BulkImportPage />); | ||
expect(screen.getByText('Added repositories')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should not render if user is not authorized to access the bulk import plugin', async () => { | ||
RequirePermissionMock.mockImplementation(_props => <>Not Found</>); | ||
mockUsePermission.mockReturnValue({ loading: false, allowed: false }); | ||
|
||
await renderInTestApp(<BulkImportPage />); | ||
expect(screen.getByText('Not Found')).toBeInTheDocument(); | ||
expect(screen.queryByText('Added repositories')).not.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
Oops, something went wrong.