-
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
10 changed files
with
269 additions
and
85 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
79 changes: 79 additions & 0 deletions
79
plugins/bulk-import/src/components/BulkImportIcon.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 { BulkImportIcon } from './BulkImportIcon'; | ||
|
||
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(<BulkImportIcon />); | ||
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(<BulkImportIcon />); | ||
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(<BulkImportIcon />); | ||
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(<BulkImportIcon />); | ||
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
Oops, something went wrong.