-
Notifications
You must be signed in to change notification settings - Fork 370
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: [UIE-8139] - add new assigned entities table component part 1
- Loading branch information
1 parent
ab2a7e5
commit 1ca7141
Showing
10 changed files
with
488 additions
and
124 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
131 changes: 131 additions & 0 deletions
131
...ages/manager/src/features/IAM/Shared/AssignedEntitiesTable/AssignedEntitiesTable.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,131 @@ | ||
import { fireEvent, waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { accountResourcesFactory } from 'src/factories/accountResources'; | ||
import { userPermissionsFactory } from 'src/factories/userPermissions'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { AssignedEntitiesTable } from './AssignedEntitiesTable'; | ||
|
||
const queryMocks = vi.hoisted(() => ({ | ||
useAccountResources: vi.fn().mockReturnValue({}), | ||
useAccountUserPermissions: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('src/queries/iam/iam', async () => { | ||
const actual = await vi.importActual<any>('src/queries/iam/iam'); | ||
return { | ||
...actual, | ||
useAccountUserPermissions: queryMocks.useAccountUserPermissions, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/resources/resources', async () => { | ||
const actual = await vi.importActual<any>('src/queries/resources/resources'); | ||
return { | ||
...actual, | ||
useAccountResources: queryMocks.useAccountResources, | ||
}; | ||
}); | ||
|
||
describe('AssignedEntitiesTable', () => { | ||
it('should display no roles text if there are no roles assigned to user', async () => { | ||
queryMocks.useAccountUserPermissions.mockReturnValue({ | ||
data: {}, | ||
}); | ||
|
||
const { getByText } = renderWithTheme(<AssignedEntitiesTable />); | ||
|
||
getByText('No Entities are assigned.'); | ||
}); | ||
|
||
it('should display roles and menu when data is available', async () => { | ||
queryMocks.useAccountUserPermissions.mockReturnValue({ | ||
data: userPermissionsFactory.build(), | ||
}); | ||
|
||
queryMocks.useAccountResources.mockReturnValue({ | ||
data: accountResourcesFactory.build(), | ||
}); | ||
|
||
const { getAllByLabelText, getByText } = renderWithTheme( | ||
<AssignedEntitiesTable /> | ||
); | ||
|
||
expect(getByText('firewall-us-123')).toBeInTheDocument(); | ||
expect(getByText('Firewall')).toBeInTheDocument(); | ||
expect(getByText('update_firewall')).toBeInTheDocument(); | ||
|
||
const actionMenuButton = getAllByLabelText('action menu')[0]; | ||
expect(actionMenuButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(actionMenuButton); | ||
expect(getByText('Change Role')).toBeInTheDocument(); | ||
expect(getByText('Remove Assignment')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should display empty state when no roles match filters', async () => { | ||
queryMocks.useAccountUserPermissions.mockReturnValue({ | ||
data: userPermissionsFactory.build(), | ||
}); | ||
|
||
queryMocks.useAccountResources.mockReturnValue({ | ||
data: accountResourcesFactory.build(), | ||
}); | ||
|
||
const { getByPlaceholderText, getByText } = renderWithTheme( | ||
<AssignedEntitiesTable /> | ||
); | ||
|
||
const searchInput = getByPlaceholderText('Search'); | ||
fireEvent.change(searchInput, { target: { value: 'NonExistentRole' } }); | ||
|
||
await waitFor(() => { | ||
expect(getByText('No Entities are assigned.')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should filter roles based on search query', async () => { | ||
queryMocks.useAccountUserPermissions.mockReturnValue({ | ||
data: userPermissionsFactory.build(), | ||
}); | ||
|
||
queryMocks.useAccountResources.mockReturnValue({ | ||
data: accountResourcesFactory.build(), | ||
}); | ||
|
||
const { getByPlaceholderText, queryByText } = renderWithTheme( | ||
<AssignedEntitiesTable /> | ||
); | ||
|
||
const searchInput = getByPlaceholderText('Search'); | ||
fireEvent.change(searchInput, { | ||
target: { value: 'firewall-us-123' }, | ||
}); | ||
|
||
await waitFor(() => { | ||
expect(queryByText('firewall-us-123')).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should filter roles based on selected resource type', async () => { | ||
queryMocks.useAccountUserPermissions.mockReturnValue({ | ||
data: userPermissionsFactory.build(), | ||
}); | ||
|
||
queryMocks.useAccountResources.mockReturnValue({ | ||
data: accountResourcesFactory.build(), | ||
}); | ||
|
||
const { getByPlaceholderText, queryByText } = renderWithTheme( | ||
<AssignedEntitiesTable /> | ||
); | ||
|
||
const autocomplete = getByPlaceholderText('All Assigned Entities'); | ||
fireEvent.change(autocomplete, { target: { value: 'Firewalls' } }); | ||
|
||
await waitFor(() => { | ||
expect(queryByText('firewall-us-123')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.