add data-testids to UI components that may be hard to target with automation

This commit is contained in:
Mary Hipp 2023-09-28 15:25:45 -04:00 committed by psychedelicious
parent 5174f382b9
commit 52f8c9e16f
21 changed files with 51 additions and 8 deletions

View File

@ -46,6 +46,7 @@ const IAICollapse = (props: IAIToggleCollapseProps) => {
transitionDuration: 'normal', transitionDuration: 'normal',
userSelect: 'none', userSelect: 'none',
}} }}
data-testid={`${label} collapsible`}
> >
{label} {label}
<AnimatePresence> <AnimatePresence>

View File

@ -67,6 +67,7 @@ type IAIDndImageProps = FlexProps & {
withHoverOverlay?: boolean; withHoverOverlay?: boolean;
children?: JSX.Element; children?: JSX.Element;
uploadElement?: ReactNode; uploadElement?: ReactNode;
dataTestId?: string;
}; };
const IAIDndImage = (props: IAIDndImageProps) => { const IAIDndImage = (props: IAIDndImageProps) => {
@ -94,6 +95,7 @@ const IAIDndImage = (props: IAIDndImageProps) => {
children, children,
onMouseOver, onMouseOver,
onMouseOut, onMouseOut,
dataTestId,
} = props; } = props;
const { colorMode } = useColorMode(); const { colorMode } = useColorMode();
@ -183,6 +185,7 @@ const IAIDndImage = (props: IAIDndImageProps) => {
borderRadius: 'base', borderRadius: 'base',
...imageSx, ...imageSx,
}} }}
data-testId={dataTestId}
/> />
{withMetadataOverlay && ( {withMetadataOverlay && (
<ImageMetadataOverlay imageDTO={imageDTO} /> <ImageMetadataOverlay imageDTO={imageDTO} />

View File

@ -39,6 +39,7 @@ const IAIDndImageIcon = (props: Props) => {
}, },
...styleOverrides, ...styleOverrides,
}} }}
data-testid={tooltip}
/> />
); );
}; };

View File

@ -30,6 +30,7 @@ const IAIIconButton = forwardRef((props: IAIIconButtonProps, forwardedRef) => {
ref={forwardedRef} ref={forwardedRef}
role={role} role={role}
colorScheme={isChecked ? 'accent' : 'base'} colorScheme={isChecked ? 'accent' : 'base'}
data-testid={tooltip}
{...rest} {...rest}
/> />
</Tooltip> </Tooltip>

View File

@ -70,7 +70,12 @@ const IAIMantineSearchableSelect = forwardRef((props: IAISelectProps, ref) => {
return ( return (
<Tooltip label={tooltip} placement="top" hasArrow> <Tooltip label={tooltip} placement="top" hasArrow>
<FormControl ref={ref} isDisabled={disabled} position="static"> <FormControl
ref={ref}
isDisabled={disabled}
position="static"
data-testid={`select-${label || props.placeholder}`}
>
{label && <FormLabel>{label}</FormLabel>} {label && <FormLabel>{label}</FormLabel>}
<Select <Select
ref={inputRef} ref={inputRef}

View File

@ -27,6 +27,7 @@ const IAIMantineSelect = forwardRef((props: IAISelectProps, ref) => {
isRequired={required} isRequired={required}
isDisabled={disabled} isDisabled={disabled}
position="static" position="static"
data-testid={`select-${label || props.placeholder}`}
> >
<FormLabel>{label}</FormLabel> <FormLabel>{label}</FormLabel>
<Select disabled={disabled} ref={inputRef} styles={styles} {...rest} /> <Select disabled={disabled} ref={inputRef} styles={styles} {...rest} />

View File

@ -20,6 +20,7 @@ const AddBoardButton = () => {
aria-label={t('boards.addBoard')} aria-label={t('boards.addBoard')}
onClick={handleCreateBoard} onClick={handleCreateBoard}
size="sm" size="sm"
data-testid="add-board-button"
/> />
); );
}; };

View File

@ -68,17 +68,22 @@ const BoardsList = (props: Props) => {
> >
<Grid <Grid
className="list-container" className="list-container"
data-testid="boards-list"
sx={{ sx={{
gridTemplateColumns: `repeat(auto-fill, minmax(108px, 1fr));`, gridTemplateColumns: `repeat(auto-fill, minmax(108px, 1fr));`,
maxH: 346, maxH: 346,
}} }}
> >
<GridItem sx={{ p: 1.5 }}> <GridItem sx={{ p: 1.5 }} data-testid="no-board">
<NoBoardBoard isSelected={selectedBoardId === 'none'} /> <NoBoardBoard isSelected={selectedBoardId === 'none'} />
</GridItem> </GridItem>
{filteredBoards && {filteredBoards &&
filteredBoards.map((board) => ( filteredBoards.map((board, index) => (
<GridItem key={board.board_id} sx={{ p: 1.5 }}> <GridItem
key={board.board_id}
sx={{ p: 1.5 }}
data-testid={`board-${index}`}
>
<GalleryBoard <GalleryBoard
board={board} board={board}
isSelected={selectedBoardId === board.board_id} isSelected={selectedBoardId === board.board_id}

View File

@ -79,6 +79,7 @@ const BoardsSearch = () => {
value={boardSearchText} value={boardSearchText}
onKeyDown={handleKeydown} onKeyDown={handleKeydown}
onChange={handleChange} onChange={handleChange}
data-testid="board-search-input"
/> />
{boardSearchText && boardSearchText.length && ( {boardSearchText && boardSearchText.length && (
<InputRightElement> <InputRightElement>

View File

@ -149,6 +149,7 @@ const CurrentImagePreview = () => {
width={denoiseProgress.progress_image.width} width={denoiseProgress.progress_image.width}
height={denoiseProgress.progress_image.height} height={denoiseProgress.progress_image.height}
draggable={false} draggable={false}
data-testid="progress-image"
sx={{ sx={{
objectFit: 'contain', objectFit: 'contain',
maxWidth: 'full', maxWidth: 'full',
@ -171,6 +172,7 @@ const CurrentImagePreview = () => {
noContentFallback={ noContentFallback={
<IAINoContentFallback icon={FaImage} label="No image selected" /> <IAINoContentFallback icon={FaImage} label="No image selected" />
} }
dataTestId="image-preview"
/> />
)} )}
{shouldShowImageDetails && imageDTO && ( {shouldShowImageDetails && imageDTO && (

View File

@ -109,6 +109,7 @@ const ImageGalleryContent = () => {
w: 'full', w: 'full',
}} }}
leftIcon={<FaImages />} leftIcon={<FaImages />}
data-testid="images-tab"
> >
Images Images
</Tab> </Tab>
@ -121,6 +122,7 @@ const ImageGalleryContent = () => {
w: 'full', w: 'full',
}} }}
leftIcon={<FaServer />} leftIcon={<FaServer />}
data-testid="assets-tab"
> >
Assets Assets
</Tab> </Tab>

View File

@ -117,7 +117,10 @@ const GalleryImage = (props: HoverableImageProps) => {
} }
return ( return (
<Box sx={{ w: 'full', h: 'full', touchAction: 'none' }}> <Box
sx={{ w: 'full', h: 'full', touchAction: 'none' }}
data-testid={`image-${imageDTO.image_name}`}
>
<Flex <Flex
userSelect="none" userSelect="none"
sx={{ sx={{

View File

@ -3,7 +3,12 @@ import { PropsWithChildren, memo } from 'react';
type ItemContainerProps = PropsWithChildren & FlexProps; type ItemContainerProps = PropsWithChildren & FlexProps;
const ItemContainer = forwardRef((props: ItemContainerProps, ref) => ( const ItemContainer = forwardRef((props: ItemContainerProps, ref) => (
<Box className="item-container" ref={ref} p={1.5}> <Box
className="item-container"
ref={ref}
p={1.5}
data-testid="image-item-container"
>
{props.children} {props.children}
</Box> </Box>
)); ));

View File

@ -17,6 +17,7 @@ const ListContainer = forwardRef((props: ListContainerProps, ref) => {
sx={{ sx={{
gridTemplateColumns: `repeat(auto-fill, minmax(${galleryImageMinimumWidth}px, 1fr));`, gridTemplateColumns: `repeat(auto-fill, minmax(${galleryImageMinimumWidth}px, 1fr));`,
}} }}
data-testid="image-list-container"
> >
{props.children} {props.children}
</Grid> </Grid>

View File

@ -98,6 +98,7 @@ const ParamLoRASelect = () => {
item.value.toLowerCase().includes(value.toLowerCase().trim()) item.value.toLowerCase().includes(value.toLowerCase().trim())
} }
onChange={handleChange} onChange={handleChange}
data-testid="add-lora"
/> />
); );
}; };

View File

@ -107,6 +107,7 @@ const ParamControlNetCollapse = () => {
flexGrow={1} flexGrow={1}
size="sm" size="sm"
onClick={handleClickedAddControlNet} onClick={handleClickedAddControlNet}
data-testid="add controlnet"
/> />
</Flex> </Flex>
{controlNetsArray.map((c, i) => ( {controlNetsArray.map((c, i) => (

View File

@ -60,6 +60,7 @@ const InitialImage = () => {
noContentFallback={ noContentFallback={
<IAINoContentFallback label="No initial image selected" /> <IAINoContentFallback label="No initial image selected" />
} }
dataTestId="initial-image"
/> />
); );
}; };

View File

@ -77,7 +77,12 @@ const QueueCounts = memo(() => {
}, [dispatch]); }, [dispatch]);
return ( return (
<Flex justifyContent="space-between" alignItems="center" pe={1}> <Flex
justifyContent="space-between"
alignItems="center"
pe={1}
data-testid="queue-count"
>
<Spacer /> <Spacer />
<Button <Button
onClick={handleClick} onClick={handleClick}

View File

@ -72,6 +72,7 @@ const QueueItemComponent = ({ index, item, context }: InnerItemProps) => {
borderRadius="base" borderRadius="base"
justifyContent="center" justifyContent="center"
sx={sx} sx={sx}
data-testid="queue-item"
> >
<Flex <Flex
minH={9} minH={9}

View File

@ -8,7 +8,7 @@ const QueueStatus = () => {
const { data: queueStatus } = useGetQueueStatusQuery(); const { data: queueStatus } = useGetQueueStatusQuery();
const { t } = useTranslation(); const { t } = useTranslation();
return ( return (
<StatusStatGroup> <StatusStatGroup data-testid="queue-status">
<StatusStatItem <StatusStatItem
label={t('queue.in_progress')} label={t('queue.in_progress')}
value={queueStatus?.queue.in_progress ?? 0} value={queueStatus?.queue.in_progress ?? 0}

View File

@ -39,6 +39,7 @@ const QueueButton = ({
colorScheme={colorScheme} colorScheme={colorScheme}
isLoading={isLoading} isLoading={isLoading}
sx={sx} sx={sx}
data-testid={label}
/> />
); );
} }
@ -55,6 +56,7 @@ const QueueButton = ({
loadingText={loadingText ?? label} loadingText={loadingText ?? label}
flexGrow={1} flexGrow={1}
sx={sx} sx={sx}
data-testid={label}
> >
{label} {label}
</IAIButton> </IAIButton>