Skip to content

Commit

Permalink
Updated unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yi Cai <yicai@redhat.com>
  • Loading branch information
ciiay committed May 31, 2024
1 parent c3b1209 commit 2a31062
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins/rbac/src/components/RbacPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe('RbacPage', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand Down
34 changes: 34 additions & 0 deletions plugins/rbac/src/components/RolesList/RolesList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand All @@ -87,6 +88,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand All @@ -108,6 +110,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand Down Expand Up @@ -144,6 +147,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand Down Expand Up @@ -182,6 +186,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: true,
Expand All @@ -203,6 +208,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand All @@ -224,6 +230,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: true,
Expand All @@ -245,6 +252,7 @@ describe('RolesList', () => {
error: {
rolesError: '',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand All @@ -264,6 +272,7 @@ describe('RolesList', () => {
error: {
rolesError: 'Something went wrong',
policiesError: '',
roleConditionError: '',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
Expand All @@ -273,4 +282,29 @@ describe('RolesList', () => {
const { queryByText } = await renderInTestApp(<RolesList />);
expect(queryByText('Something went wrong')).toBeInTheDocument();
});

it('should show error message when there is an error fetching the role conditions', async () => {
RequirePermissionMock.mockImplementation(props => <>{props.children}</>);
mockUsePermission.mockReturnValue({ loading: false, allowed: true });
mockUseRoles.mockReturnValue({
loading: true,
data: [],
error: {
rolesError: '',
policiesError: '',
roleConditionError:
'Error fetching role conditions for role role:default/xyz, please try again later.',
},
retry: { roleRetry: jest.fn(), policiesRetry: jest.fn() },
createRoleAllowed: false,
createRoleLoading: false,
});

const { queryByText } = await renderInTestApp(<RolesList />);
expect(
queryByText(
'Error fetching role conditions for role role:default/xyz, please try again later.',
),
).toBeInTheDocument();
});
});

0 comments on commit 2a31062

Please sign in to comment.