Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/standalone/src/app/components/AppLayout/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const AppLayoutContent = () => {
isSidebarOpen={isSidebarOpen}
onSidebarToggle={onSidebarToggle}
id="page-toggle-button"
data-testid="nav-toggle"
/>
</MastheadToggle>
<MastheadBrand>
Expand Down
10 changes: 9 additions & 1 deletion libs/ui-components/src/components/DetailsPage/DetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type DetailsPageProps = {
actions?: React.ReactNode;
nav?: React.ReactNode;
banner?: React.ReactNode;
/** Optional data-testid for the title (e.g. "device-details-title") */
titleDataTestId?: string;
};

const DetailsPage = ({
Expand All @@ -53,6 +55,7 @@ const DetailsPage = ({
actions,
nav,
banner,
titleDataTestId,
}: DetailsPageProps) => {
const { t } = useTranslation();
let content = children;
Expand Down Expand Up @@ -87,7 +90,12 @@ const DetailsPage = ({
<PageSection hasBodyWrapper={false}>
<Split hasGutter>
<SplitItem isFilled>
<Title headingLevel="h1" size="3xl" role="heading">
<Title
headingLevel="h1"
size="3xl"
role="heading"
{...(titleDataTestId && { 'data-testid': titleDataTestId })}
>
{title || id}
</Title>
</SplitItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ const DeviceDetailsPage = ({ children, hideTerminal }: DeviceDetailsPageProps) =
error={error}
id={deviceId}
breadcrumbTitle={deviceAlias}
titleDataTestId="device-details-title"
title={
canEdit ? (
/* key={deviceAlias} is needed for the input field to be initialized with the alias as its value */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const DecommissionedDevicesTable = ({
isDisabled={!hasSelectedRows}
onClick={() => setIsMassDeleteModalOpen(true)}
variant="secondary"
data-testid="toolbar-delete-forever"
>
{t('Delete forever')}
</Button>
Expand All @@ -108,6 +109,7 @@ const DecommissionedDevicesTable = ({
setOnlyDecommissioned(false);
}}
ouiaId={t('Show decommissioned devices')}
data-testid="show-decommissioned-devices-switch"
/>
</ToolbarItem>
</ToolbarGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const EnrolledDeviceTableRow = ({
const columnIds = React.useMemo(() => deviceColumns.map(({ id }) => id), [deviceColumns]);

return (
<Tr>
<Tr data-testid="enrolled-device-row">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember if it's preferable to have unique data-testid
In this case, all enrolled devices rows would have the same ID and we'd need to target them by position. Is that OK?

<Td
select={{
rowIndex,
Expand All @@ -65,7 +65,12 @@ const EnrolledDeviceTableRow = ({
/>
{columnIds.includes('alias') && (
<Td dataLabel={t('Alias')}>
<ResourceLink id={deviceName} name={deviceAlias || t('Untitled')} routeLink={ROUTE.DEVICE_DETAILS} />
<ResourceLink
id={deviceName}
name={deviceAlias || t('Untitled')}
routeLink={ROUTE.DEVICE_DETAILS}
data-testid="device-name-link"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here, is it OK to share the same ID for multiple row elements?

/>
</Td>
)}
{columnIds.includes('name') && (
Expand Down Expand Up @@ -94,7 +99,7 @@ const EnrolledDeviceTableRow = ({
</Td>
)}
{!hideActions && (
<Td isActionCell>
<Td isActionCell data-testid="device-row-actions">
<ActionsColumn
items={[
...(canEdit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const EnrolledDevicesTable = ({
isDisabled={!hasSelectedRows}
onClick={() => setIsMassDecommissionModalOpen(true)}
variant="secondary"
data-testid="toolbar-decommission-devices"
>
{t('Decommission devices')}
</Button>
Expand All @@ -177,6 +178,7 @@ const EnrolledDevicesTable = ({
setOnlyDecommissioned(true);
}}
ouiaId={t('Show decommissioned devices')}
data-testid="show-decommissioned-devices-switch"
/>
</ToolbarItem>
</DeviceTableToolbar>
Expand All @@ -189,6 +191,7 @@ const EnrolledDevicesTable = ({
emptyData={devices.length === 0}
isAllSelected={isAllSelected}
onSelectAll={setAllSelected}
data-testid="enrolled-devices-table"
>
<Tbody>
{devices.map((device, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const EnrollmentRequestTableRow: React.FC<EnrollmentRequestTableRow> = ({
<Td dataLabel={t('Created')}>{timeSinceText(t, er.metadata.creationTimestamp)}</Td>
{canApprove && (
<Td dataLabel={t('Approve')}>
<Button variant="link" onClick={approveEnrollment}>
<Button variant="link" onClick={approveEnrollment} data-testid="enrollment-request-approve-button">
{t('Approve')}
</Button>
</Td>
Expand Down
2 changes: 1 addition & 1 deletion libs/ui-components/src/components/ListPage/ListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ListPage: React.FC<ListPageProps> = ({ title, headingLevel = 'h1', childre
<PageSection hasBodyWrapper={false}>
<Flex gap={{ default: 'gapMd' }} alignItems={{ default: 'alignItemsCenter' }}>
<FlexItem>
<Title headingLevel={headingLevel} size="3xl">
<Title headingLevel={headingLevel} size="3xl" data-testid="list-page-title">
{title}
</Title>
</FlexItem>
Expand Down
1 change: 1 addition & 0 deletions libs/ui-components/src/components/Table/Table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type TableProps<D> = Pick<PFTableProps, 'variant'> & {
onSelectAll?: (isSelected: boolean) => void;
isAllSelected?: boolean;
isExpandable?: boolean;
'data-testid'?: string;
singleSelect?: boolean;
};

Expand Down
26 changes: 22 additions & 4 deletions libs/ui-components/src/components/common/FlightCtlWizardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,32 @@ const FlightCtlWizardFooter = <T extends Record<string, unknown>>({
let primaryBtn: React.ReactNode;
if (isSubmitStep && !isReadOnly) {
primaryBtn = (
<Button variant="primary" onClick={submitForm} isDisabled={isSubmitting} isLoading={isSubmitting}>
<Button
variant="primary"
onClick={submitForm}
isDisabled={isSubmitting}
isLoading={isSubmitting}
data-testid="wizard-save-button"
>
{saveButtonText || t('Save')}
</Button>
);
} else if (isSubmitStep) {
// Read-only "Review" step
primaryBtn = (
<Button variant="primary" onClick={() => navigate(-1)}>
<Button variant="primary" onClick={() => navigate(-1)} data-testid="wizard-close-button">
{t('Close')}
</Button>
);
} else {
primaryBtn = (
<Button variant="primary" onClick={onMoveNext} isDisabled={!isReadOnly && !stepValid} ref={buttonRef}>
<Button
variant="primary"
onClick={onMoveNext}
isDisabled={!isReadOnly && !stepValid}
ref={buttonRef}
data-testid="wizard-next-button"
>
{t('Next')}
</Button>
);
Expand All @@ -77,6 +89,7 @@ const FlightCtlWizardFooter = <T extends Record<string, unknown>>({
variant="secondary"
onClick={goToPrevStep}
isDisabled={String(activeStep.id) === firstStepId || isSubmitting}
data-testid="wizard-back-button"
>
{t('Back')}
</Button>
Expand All @@ -85,7 +98,12 @@ const FlightCtlWizardFooter = <T extends Record<string, unknown>>({
</ActionListGroup>
<ActionListGroup>
<ActionListItem>
<Button variant="link" onClick={onCancel ?? (() => navigate(-1))} isDisabled={isSubmitting}>
<Button
variant="link"
onClick={onCancel ?? (() => navigate(-1))}
isDisabled={isSubmitting}
data-testid="wizard-cancel-button"
>
{t('Cancel')}
</Button>
</ActionListItem>
Expand Down
17 changes: 15 additions & 2 deletions libs/ui-components/src/components/common/ResourceLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ResourceDisplayLinkProps = {
name?: string;
variant?: 'shortened' | 'full';
routeLink?: RouteWithPostfix;
'data-testid'?: string;
};

export const getDisplayText = (name: string | undefined) => {
Expand All @@ -24,7 +25,13 @@ export const getDisplayText = (name: string | undefined) => {
return `${name.substring(0, 6)}...${name.substring(name.length - 7)}`;
};

const ResourceLink = ({ id, name, variant = 'shortened', routeLink }: ResourceDisplayLinkProps) => {
const ResourceLink = ({
id,
name,
variant = 'shortened',
routeLink,
'data-testid': dataTestId,
}: ResourceDisplayLinkProps) => {
const nameOrId = name || id;
const displayText = getDisplayText(nameOrId);
const showCopy = nameOrId !== displayText;
Expand All @@ -33,7 +40,13 @@ const ResourceLink = ({ id, name, variant = 'shortened', routeLink }: ResourceDi

return (
<span className={`fctl-resource-link fctl-resource-link__${variant}`}>
{routeLink ? <Link to={{ route: routeLink, postfix: id }}>{textEl}</Link> : <>{textEl}</>}
{routeLink ? (
<Link to={{ route: routeLink, postfix: id }} data-testid={dataTestId}>
{textEl}
</Link>
) : (
<span data-testid={dataTestId}>{textEl}</span>
)}
{showCopy && nameOrId && <CopyButton text={nameOrId} />}
</span>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ const ApproveDeviceForm: React.FC<ApproveDeviceFormProps> = ({ enrollmentRequest
onClick={submitForm}
isDisabled={disableSubmit || isSubmitting}
isLoading={isSubmitting}
data-testid="approve-device-form-submit"
>
{t('Approve')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const MassDecommissionDeviceModal = ({ onClose, devices, onSuccess }: MassDecomm
onClick={decommissionDevices}
isLoading={isSubmitting}
isDisabled={isSubmitting}
data-testid="modal-decommission-confirm"
>
{t('Decommission')}
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,14 @@ const MassDeleteDeviceModal: React.FC<MassDeleteDeviceModalProps> = ({ onClose,
</Stack>
</ModalBody>
<ModalFooter>
<Button key="delete" variant="danger" onClick={deleteResources} isLoading={isDeleting} isDisabled={isDeleting}>
<Button
key="delete"
variant="danger"
onClick={deleteResources}
isLoading={isDeleting}
isDisabled={isDeleting}
data-testid="modal-delete-devices-confirm"
>
{t('Delete devices')}
</Button>
<Button key="cancel" variant="link" onClick={onClose} isDisabled={isDeleting}>
Expand Down