forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
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
24 changed files
with
723 additions
and
220 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
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
79 changes: 79 additions & 0 deletions
79
plugins/bulk-import/src/components/BulkImportSidebarItem.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,79 @@ | ||
import React from 'react'; | ||
|
||
import { SidebarItem } from '@backstage/core-components'; | ||
import { usePermission } from '@backstage/plugin-permission-react'; | ||
|
||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { BulkImportSidebarItem } from './BulkImportSidebarItem'; | ||
|
||
jest.mock('@backstage/plugin-permission-react', () => ({ | ||
usePermission: jest.fn(), | ||
})); | ||
|
||
const mockUsePermission = usePermission as jest.MockedFunction< | ||
typeof usePermission | ||
>; | ||
|
||
const configMock = { | ||
getOptionalBoolean: jest.fn(() => true), | ||
}; | ||
|
||
jest.mock('@backstage/core-plugin-api', () => ({ | ||
...jest.requireActual('@backstage/core-plugin-api'), | ||
useApi: jest.fn(() => { | ||
return configMock; | ||
}), | ||
})); | ||
|
||
jest.mock('@backstage/core-components', () => ({ | ||
SidebarItem: jest | ||
.fn() | ||
.mockImplementation(() => ( | ||
<div data-testid="mockSidebarItem">Bulk import</div> | ||
)), | ||
})); | ||
|
||
const mockedSidebarItem = SidebarItem as jest.MockedFunction< | ||
typeof SidebarItem | ||
>; | ||
|
||
const mockBulkImportApiRef = jest.fn(); | ||
|
||
describe('Administration component', () => { | ||
beforeEach(() => { | ||
mockBulkImportApiRef.mockClear(); | ||
mockedSidebarItem.mockClear(); | ||
}); | ||
|
||
it('renders Bulk import sidebar item if user is authorized', async () => { | ||
mockUsePermission.mockReturnValue({ loading: false, allowed: true }); | ||
render(<BulkImportSidebarItem />); | ||
expect(mockedSidebarItem).toHaveBeenCalled(); | ||
expect(screen.queryByText('Bulk import')).toBeInTheDocument(); | ||
}); | ||
|
||
it('does not render Bulk import sidebar item if user is not authorized', async () => { | ||
mockUsePermission.mockReturnValue({ loading: false, allowed: false }); | ||
|
||
render(<BulkImportSidebarItem />); | ||
expect(screen.queryByText('Bulk import')).toBeNull(); | ||
}); | ||
|
||
it('does not render Bulk import sidebar item if user loading state is true', async () => { | ||
mockUsePermission.mockReturnValue({ loading: true, allowed: false }); | ||
|
||
render(<BulkImportSidebarItem />); | ||
expect(mockedSidebarItem).not.toHaveBeenCalled(); | ||
expect(screen.queryByText('Bulk import')).toBeNull(); | ||
}); | ||
|
||
it('renders the Bulk import sidebar item if RBAC is disabled in the configuration', async () => { | ||
mockUsePermission.mockReturnValue({ loading: true, allowed: true }); | ||
configMock.getOptionalBoolean.mockReturnValueOnce(false); | ||
|
||
render(<BulkImportSidebarItem />); | ||
expect(mockedSidebarItem).toHaveBeenCalled(); | ||
expect(screen.queryByText('Bulk import')).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
|
||
const GitAltIcon: React.FC<React.HTMLProps<SVGElement>> = ({ | ||
style, | ||
}): React.ReactElement => { | ||
return ( | ||
<svg | ||
height="1em" | ||
width="1em" | ||
version="1.1" | ||
viewBox="0 0 448 512" | ||
style={style} | ||
> | ||
<path | ||
d="M439.55 236.05L244 40.45a28.87 28.87 0 0 0-40.81 0l-40.66 40.63 51.52 51.52c27.06-9.14 52.68 16.77 43.39 43.68l49.66 49.66c34.23-11.8 61.18 31 35.47 56.69-26.49 26.49-70.21-2.87-56-37.34L240.22 199v121.85c25.3 12.54 22.26 41.85 9.08 55a34.34 34.34 0 0 1-48.55 0c-17.57-17.6-11.07-46.91 11.25-56v-123c-20.8-8.51-24.6-30.74-18.64-45L142.57 101 8.45 235.14a28.86 28.86 0 0 0 0 40.81l195.61 195.6a28.86 28.86 0 0 0 40.8 0l194.69-194.69a28.86 28.86 0 0 0 0-40.81z" | ||
fill="#aaabac" | ||
/> | ||
</svg> | ||
); | ||
}; | ||
|
||
export default GitAltIcon; |
Oops, something went wrong.