Skip to content

Commit

Permalink
feat: add cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
CodyWMitchell committed Oct 30, 2024
1 parent 54fded0 commit 1955935
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
8 changes: 8 additions & 0 deletions cypress/e2e/users-and-user-groups.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,12 @@ describe('Users and User Groups page', () => {
cy.get('[data-ouia-component-id="iam-users-table-add-user-button"]').click();
cy.get('[data-ouia-component-id="add-user-group-modal"]').should('be.visible');
});

it('can view user details when a user is clicked', () => {
cy.get('[data-ouia-component-id="iam-users-table-table-tr-0"]').click();
cy.get('[data-ouia-component-id="user-details-drawer"]').should('be.visible');
cy.get('[data-ouia-component-id="user-details-drawer"]').contains(mockUsers.data[0].first_name).should('exist');
cy.get('[data-ouia-component-id="user-details-drawer"]').contains(mockUsers.data[0].last_name).should('exist');
cy.get('[data-ouia-component-id="user-details-drawer"]').contains(mockUsers.data[0].email).should('exist');
});
});
38 changes: 25 additions & 13 deletions src/smart-components/access-management/UserDetailsDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,12 @@ import { fetchRoles } from '../../redux/actions/role-actions';
import { useIntl } from 'react-intl';
import messages from '../../Messages';

interface UserDetailsProps {
focusedUser?: User;
onClose: () => void;
interface UserGroupsViewProps {
userId: string;
ouiaId: string;
}

const UserGroupsView: React.FunctionComponent<{ userId: string }> = ({ userId }) => {
const ouiaId = 'user-groups-view';
const UserGroupsView: React.FunctionComponent<UserGroupsViewProps> = ({ userId, ouiaId }) => {
const dispatch = useDispatch();
const intl = useIntl();
const columns: string[] = [intl.formatMessage(messages.userGroup), intl.formatMessage(messages.users)];
Expand Down Expand Up @@ -69,8 +68,12 @@ const UserGroupsView: React.FunctionComponent<{ userId: string }> = ({ userId })
);
};

const UserRolesView: React.FunctionComponent<{ userId: string }> = ({ userId }) => {
const ouiaId = 'user-roles-view';
interface UserRolesViewProps {
userId: string;
ouiaId: string;
}

const UserRolesView: React.FunctionComponent<UserRolesViewProps> = ({ userId, ouiaId }) => {
const dispatch = useDispatch();
const intl = useIntl();
// const columns: string[] = ['Roles', 'User group', 'Workspace'];
Expand Down Expand Up @@ -111,7 +114,13 @@ const UserRolesView: React.FunctionComponent<{ userId: string }> = ({ userId })
);
};

export const UserDetailsDrawerContent: React.FunctionComponent<UserDetailsProps> = ({ focusedUser, onClose }) => {
interface UserDetailsProps {
focusedUser?: User;
onClose: () => void;
ouiaId: string;
}

export const UserDetailsDrawerContent: React.FunctionComponent<UserDetailsProps> = ({ focusedUser, onClose, ouiaId }) => {
const [activeTabKey, setActiveTabKey] = React.useState<string | number>(0);
const intl = useIntl();

Expand All @@ -128,7 +137,7 @@ export const UserDetailsDrawerContent: React.FunctionComponent<UserDetailsProps>
</DrawerHead>
<Tabs isFilled activeKey={activeTabKey} onSelect={(_, tabIndex) => setActiveTabKey(tabIndex)}>
<Tab eventKey={0} title={intl.formatMessage(messages.userGroups)}>
{focusedUser && <UserGroupsView userId={focusedUser.username} />}
{focusedUser && <UserGroupsView ouiaId={`${ouiaId}-user-groups-view`} userId={focusedUser.username} />}
</Tab>
<Tab
eventKey={1}
Expand All @@ -148,7 +157,7 @@ export const UserDetailsDrawerContent: React.FunctionComponent<UserDetailsProps>
</TabTitleText>
}
>
{focusedUser && <UserRolesView userId={focusedUser.username} />}
{focusedUser && <UserRolesView userId={focusedUser.username} ouiaId={`${ouiaId}-assigned-users-view`} />}
</Tab>
</Tabs>
</DrawerPanelContent>
Expand All @@ -160,15 +169,18 @@ interface DetailDrawerProps {
focusedUser?: User;
onClose: () => void;
children: React.ReactNode;
ouiaId?: string;
ouiaId: string;
}

export const UserDetailsDrawer: React.FunctionComponent<DetailDrawerProps> = ({ isOpen, focusedUser, onClose, children, ouiaId }) => {
const drawerRef = React.useRef<HTMLDivElement>(null);

return (
<Drawer isExpanded={isOpen} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id={ouiaId ? `${ouiaId}-detail-drawer` : undefined}>
<DrawerContent panelContent={<UserDetailsDrawerContent focusedUser={focusedUser} onClose={onClose} />} ref={drawerRef}>
<Drawer isExpanded={isOpen} onExpand={() => drawerRef.current?.focus()} data-ouia-component-id={ouiaId}>
<DrawerContent
panelContent={<UserDetailsDrawerContent ouiaId={`${ouiaId}-panel-content`} focusedUser={focusedUser} onClose={onClose} />}
ref={drawerRef}
>
<DrawerContentBody hasPadding>{children}</DrawerContentBody>
</DrawerContent>
</Drawer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ const UsersAndUserGroups: React.FunctionComponent = () => {
</PageSection>
<PageSection padding={{ default: 'noPadding' }}>
{activeTabKey === 0 && (
<UserDetailsDrawer isOpen={!!focusedUser} focusedUser={focusedUser} onClose={() => setFocusedUser(undefined)}>
<UserDetailsDrawer ouiaId="user-details-drawer" isOpen={!!focusedUser} focusedUser={focusedUser} onClose={() => setFocusedUser(undefined)}>
<TabContent eventKey={0} id="usersTab" ref={usersRef} aria-label="Users tab">
<UsersTable
onAddUserClick={handleOpenAddUserModal}
Expand Down

0 comments on commit 1955935

Please sign in to comment.