Skip to content

Commit

Permalink
fix(rbac): add data-testid, names and aria-label to RBAC UI components (
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 authored Feb 19, 2024
1 parent 658ad25 commit cabc76d
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 19 deletions.
1 change: 1 addition & 0 deletions plugins/rbac/src/components/CreateRole/AddMembersForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export const AddMembersForm = ({
renderInput={params => (
<TextField
{...params}
name="add-users-and-groups"
variant="outlined"
label="Users and groups"
placeholder="Search by user name or group name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const MembersDropdownOption = ({
style={{
fontWeight: part.highlight ? 400 : 700,
}}
data-testid={option.label}
>
{part.text}
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,12 @@ export const PermissionPoliciesForm = ({
}}
/>
))}
<Button className={classes.addButton} size="small" onClick={onRowAdd}>
<Button
className={classes.addButton}
size="small"
onClick={onRowAdd}
name="add-permission-policy"
>
<AddIcon />
Add
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const PermissionPoliciesFormRow = ({
onClick={() => onRemove()}
disabled={rowCount === 1}
>
<RemoveIcon />
<RemoveIcon id={`${rowName}-remove`} />
</IconButton>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const PoliciesCheckboxGroup = ({
control={
<Checkbox
checked={p.effect === 'allow'}
name={`${rowName}.policies[${index}].policy`}
name={`${rowName}.policies[${index}].policy-${p.policy}`}
onChange={e => onChangePolicy(e.target.checked, index)}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/RolesList/DeleteRoleDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ const DeleteRoleDialog = ({
specified in this role.
<br />
<TextField
data-testid="delete-role"
style={{ marginTop: '24px' }}
required
data-testid="delete-name"
variant="outlined"
label="Role name"
defaultValue={deleteRoleValue}
Expand Down
24 changes: 14 additions & 10 deletions plugins/rbac/src/components/RolesList/RolesList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ describe('RolesList', () => {
createRoleAllowed: false,
createRoleLoading: false,
});
const { getAllByTestId, getByText } = await renderInTestApp(<RolesList />);
expect(getAllByTestId('delete-role')).not.toBeNull();
const { getByTestId, getByText } = await renderInTestApp(<RolesList />);
expect(getByTestId('delete-role-role:default/guests')).not.toBeNull();
expect(getByText('Actions')).not.toBeNull();
});

Expand All @@ -134,7 +134,7 @@ describe('RolesList', () => {
},
},
{
...useRolesMockData[0],
...useRolesMockData[1],
actionsPermissionResults: {
delete: { allowed: false, loading: true },
edit: { allowed: true, loading: false },
Expand All @@ -149,9 +149,11 @@ describe('RolesList', () => {
createRoleAllowed: false,
createRoleLoading: false,
});
const { getAllByTestId } = await renderInTestApp(<RolesList />);
expect(getAllByTestId('disable-delete-role')).not.toBeNull();
expect(getAllByTestId('update-role')).not.toBeNull();
const { getByTestId } = await renderInTestApp(<RolesList />);
expect(
getByTestId('disable-delete-role-role:default/guests'),
).not.toBeNull();
expect(getByTestId('update-role-role:default/guests')).not.toBeNull();
});

it('should show disabled edit icon if user is not authorized to update roles', async () => {
Expand All @@ -170,7 +172,7 @@ describe('RolesList', () => {
},
},
{
...useRolesMockData[0],
...useRolesMockData[1],
actionsPermissionResults: {
delete: { allowed: true, loading: true },
edit: { allowed: false, loading: false },
Expand All @@ -185,9 +187,11 @@ describe('RolesList', () => {
createRoleAllowed: true,
createRoleLoading: false,
});
const { getAllByTestId } = await renderInTestApp(<RolesList />);
expect(getAllByTestId('disable-update-role')).not.toBeNull();
expect(getAllByTestId('delete-role')).not.toBeNull();
const { getByTestId } = await renderInTestApp(<RolesList />);
expect(
getByTestId('disable-update-role-role:default/guests'),
).not.toBeNull();
expect(getByTestId('delete-role-role:default/rbac_admin')).not.toBeNull();
});

it('should disable create button if user is not authorized to create roles', async () => {
Expand Down
8 changes: 4 additions & 4 deletions plugins/rbac/src/components/RolesList/RolesListColumns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const columns: TableColumn<RolesData>[] = [
<EditRole
dataTestId={
!props.actionsPermissionResults.edit.allowed
? 'disable-update-role'
: 'update-role'
? `disable-update-role-${props.name}`
: `update-role-${props.name}`
}
roleName={props.name}
disable={!props.actionsPermissionResults.edit.allowed}
Expand All @@ -66,8 +66,8 @@ export const columns: TableColumn<RolesData>[] = [
<DeleteRole
dataTestId={
!props.actionsPermissionResults.delete.allowed
? 'disable-delete-role'
: 'delete-role'
? `disable-delete-role-${props.name}`
: `delete-role-${props.name}`
}
roleName={props.name}
disable={!props.actionsPermissionResults.delete.allowed}
Expand Down
2 changes: 1 addition & 1 deletion plugins/rbac/src/components/SnackbarAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const SnackbarAlert = ({
return (
<Snackbar
open={toastMessage !== ''}
autoHideDuration={6000}
autoHideDuration={10000}
anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
style={{ top: '100px', left: '0px', justifyContent: 'center' }}
onClose={onAlertClose}
Expand Down

0 comments on commit cabc76d

Please sign in to comment.