F #5422: Add flags data-cy (#1656)

(cherry picked from commit 26b15d5d09)
This commit is contained in:
Jorge Miguel Lobo Escalona authored and Tino Vazquez committed 2021-12-09 18:41:05 +01:00
1 parent 937598f3f1
commit ce0bccf1f2
31 files changed
+69 -53

No files matched your search

@@ -44,6 +44,7 @@ import { T } from 'client/constants'
* @property {object} [cancelButtonProps] - Cancel button properties
* @property {boolean} [fixedWidth] - Fix minimum with to dialog
* @property {boolean} [fixedHeight] - Fix minimum height to dialog
* @property {object} [dataCy] - identifier for cypress tests
* @property {JSXElementConstructor} [children] - Fix minimum height
*/
@@ -65,6 +66,7 @@ const DialogConfirmation = memo(
fixedWidth,
fixedHeight,
children,
dataCy,
}) => {
const isMobile = useMediaQuery((theme) => theme.breakpoints.only('xs'))
@@ -85,6 +87,7 @@ const DialogConfirmation = memo(
TransitionProps={{
onEntering: handleEntering,
}}
{...(dataCy && { 'data-cy': dataCy })}
>
<DialogTitle
sx={{
@@ -149,6 +152,7 @@ export const DialogPropTypes = {
acceptButtonProps: PropTypes.object,
handleCancel: PropTypes.func,
cancelButtonProps: PropTypes.object,
dataCy: PropTypes.string,
handleEntering: PropTypes.func,
fixedWidth: PropTypes.bool,
fixedHeight: PropTypes.bool,
@@ -49,7 +49,6 @@ const DialogForm = ({
children,
}) => {
const classes = useStyles()
const { className, ...contentProps } = dialogProps.contentProps ?? {}
dialogProps.contentProps = {
@@ -110,7 +110,7 @@ const FormWithSchema = ({
return { ...field, [key]: finalValue }
}, {})
const dataCy = `${cy}-${name}`
const dataCy = `${cy}-${name}`.replaceAll('.', '-')
const inputName = addIdToName(name)
const isHidden = htmlType === INPUT_TYPES.HIDDEN
@@ -26,11 +26,7 @@ import { T } from 'client/constants'
export const STEP_ID = 'advanced'
const Content = ({ hypervisor }) => (
<FormWithSchema
cy="attach-disk-advanced"
id={STEP_ID}
fields={FIELDS(hypervisor)}
/>
<FormWithSchema cy="attach-disk" id={STEP_ID} fields={FIELDS(hypervisor)} />
)
const AdvancedOptions = ({ hypervisor } = {}) => ({
@@ -44,6 +44,7 @@ const Content = ({ data, setFormData }) => {
onlyGlobalSelectedRows
initialState={{ selectedRowIds: { [ID]: true } }}
onSelectedRowsChange={handleSelectedRows}
searchProps={{ 'data-cy': 'search-images' }}
/>
)
}
@@ -26,11 +26,7 @@ import { T } from 'client/constants'
export const STEP_ID = 'advanced'
const Content = ({ hypervisor }) => (
<FormWithSchema
cy="attach-disk-advanced"
fields={FIELDS(hypervisor)}
id={STEP_ID}
/>
<FormWithSchema cy="attach-disk" fields={FIELDS(hypervisor)} id={STEP_ID} />
)
const AdvancedOptions = ({ hypervisor } = {}) => ({
@@ -26,11 +26,7 @@ import { T } from 'client/constants'
export const STEP_ID = 'configuration'
const Content = ({ hypervisor }) => (
<FormWithSchema
cy="attach-disk-configuration"
fields={FIELDS(hypervisor)}
id={STEP_ID}
/>
<FormWithSchema cy="attach-disk" fields={FIELDS(hypervisor)} id={STEP_ID} />
)
const BasicConfiguration = ({ hypervisor } = {}) => ({
@@ -60,7 +60,7 @@ const Booting = ({ hypervisor, ...props }) => {
<FormWithSchema
key={id}
id={EXTRA_ID}
cy={`${EXTRA_ID}.${id}`}
cy={`${EXTRA_ID}-${id}`}
{...section}
/>
))}
@@ -51,13 +51,13 @@ const ConfigurationSection = () => {
sx={{ gridTemplateColumns: { sm: '1fr', md: '1fr 1fr' } }}
>
<FormWithSchema
cy={`${EXTRA_ID}.context-configuration-others`}
cy={`${EXTRA_ID}-context-configuration-others`}
fields={OTHER_FIELDS}
id={EXTRA_ID}
/>
<div>
<FormWithSchema
cy={`${EXTRA_ID}.context-ssh-public-key`}
cy={`${EXTRA_ID}-context-ssh-public-key`}
fields={[SSH_PUBLIC_KEY]}
id={EXTRA_ID}
/>
@@ -71,7 +71,7 @@ const ConfigurationSection = () => {
</Stack>
</div>
<FormWithSchema
cy={`${EXTRA_ID}.context-script`}
cy={`${EXTRA_ID}-context-script`}
fields={SCRIPT_FIELDS}
id={EXTRA_ID}
rootProps={{ sx: { width: '100%', gridColumn: '1 / -1' } }}
@@ -31,7 +31,7 @@ export const SECTION_ID = 'CONTEXT'
*/
const FilesSection = ({ hypervisor }) => (
<FormWithSchema
cy={`${EXTRA_ID}.context-files`}
cy={`${EXTRA_ID}-context-files`}
legend={T.Files}
fields={() => FILES_FIELDS(hypervisor)}
id={EXTRA_ID}
@@ -157,7 +157,7 @@ const UserInputsSection = () => {
onSubmit={methods.handleSubmit(onSubmit)}
>
<FormWithSchema
cy={`${EXTRA_ID}.context-user-input`}
cy={`${EXTRA_ID}-context-user-input`}
fields={USER_INPUT_FIELDS}
rootProps={{ sx: { m: 0 } }}
/>
@@ -42,7 +42,7 @@ const InputOutput = ({ hypervisor }) => {
sx={{ gridTemplateColumns: { sm: '1fr', md: '1fr 1fr' } }}
>
<FormWithSchema
cy={`${EXTRA_ID}.io-graphics`}
cy={`${EXTRA_ID}-io-graphics`}
fields={GRAPHICS_FIELDS(hypervisor)}
legend={T.Graphics}
id={EXTRA_ID}
@@ -68,7 +68,7 @@ const InputsSection = ({ fields }) => {
onSubmit={methods.handleSubmit(onSubmit)}
>
<FormWithSchema
cy={`${EXTRA_ID}.io-inputs`}
cy={`${EXTRA_ID}-io-inputs`}
fields={fields}
rootProps={{ sx: { m: 0 } }}
/>
@@ -79,7 +79,7 @@ const PciDevicesSection = ({ fields }) => {
onSubmit={methods.handleSubmit(onSubmit)}
>
<FormWithSchema
cy={`${EXTRA_ID}.io-pci-devices`}
cy={`${EXTRA_ID}-io-pci-devices`}
fields={fields}
rootProps={{ sx: { m: 0 } }}
/>
@@ -80,7 +80,7 @@ const Networking = () => {
}}
options={[
{
dialogProps: { title: T.AttachNic },
dialogProps: { title: T.AttachNic, dataCy: 'modal-attach-nic' },
form: () => AttachNicForm({ nics }),
onSubmit: (nic) => append(mapNameFunction(nic, nics.length)),
},
@@ -109,7 +109,7 @@ const Networking = () => {
))}
</Stack>
<FormWithSchema
cy={`${EXTRA_ID}.network-options`}
cy={`${EXTRA_ID}-network-options`}
fields={FIELDS}
legend={T.NetworkDefaults}
legendTooltip={T.NetworkDefaultsConcept}
@@ -31,12 +31,12 @@ export const TAB_ID = 'NUMA'
const Numa = ({ hypervisor }) => (
<>
<FormWithSchema
cy={`${EXTRA_ID}.vcpu`}
cy={`${EXTRA_ID}-vcpu`}
fields={[VCPU_FIELD]}
id={GENERAL_ID}
/>
<FormWithSchema
cy={`${EXTRA_ID}.numa`}
cy={`${EXTRA_ID}-numa`}
fields={NUMA_FIELDS(hypervisor)}
id={EXTRA_ID}
/>
@@ -40,7 +40,7 @@ const Placement = () => (
<FormWithSchema
key={id}
id={EXTRA_ID}
cy={`${EXTRA_ID}.${id}`}
cy={`${EXTRA_ID}-${id}`}
{...section}
/>
))}
@@ -58,7 +58,10 @@ const ScheduleAction = () => {
{
cy: 'add-sched-action-punctual',
name: 'Punctual action',
dialogProps: { title: T.ScheduledAction },
dialogProps: {
title: T.ScheduledAction,
dataCy: 'modal-sched-actions',
},
form: () => PunctualForm(),
onSubmit: (action) =>
append(mapNameFunction(action, scheduleActions.length)),
@@ -66,7 +69,10 @@ const ScheduleAction = () => {
{
cy: 'add-sched-action-relative',
name: 'Relative action',
dialogProps: { title: T.ScheduledAction },
dialogProps: {
title: T.ScheduledAction,
dataCy: 'modal-sched-actions',
},
form: () => RelativeForm(),
onSubmit: (action) =>
append(mapNameFunction(action, scheduleActions.length)),
@@ -80,16 +80,16 @@ const Storage = ({ hypervisor }) => {
}}
options={[
{
cy: 'attach-image-disk',
cy: 'attach-image',
name: T.Image,
dialogProps: { title: T.AttachImage },
dialogProps: { title: T.AttachImage, dataCy: 'modal-attach-image' },
form: () => ImageSteps({ hypervisor }),
onSubmit: (image) => append(mapNameFunction(image, disks.length)),
},
{
cy: 'attach-volatile-disk',
cy: 'attach-volatile',
name: T.Volatile,
dialogProps: { title: T.AttachVolatile },
dialogProps: { title: T.AttachVolatile, dataCy: 'modal-attach-volatile' },
form: () => VolatileSteps({ hypervisor }),
onSubmit: (image) => append(mapNameFunction(image, disks.length)),
},
@@ -117,7 +117,7 @@ const Storage = ({ hypervisor }) => {
))}
</Stack>
<FormWithSchema
cy={`${EXTRA_ID}.storage-options`}
cy={`${EXTRA_ID}-storage-options`}
fields={FIELDS}
legend={T.StorageOptions}
id={EXTRA_ID}
@@ -49,7 +49,7 @@ const Content = ({ isUpdate }) => {
return (
<div className={classes.root}>
<FormWithSchema
cy={`${STEP_ID}.hypervisor`}
cy={`${STEP_ID}-hypervisor`}
fields={[HYPERVISOR_FIELD]}
legend={T.Hypervisor}
id={STEP_ID}
@@ -59,7 +59,7 @@ const Content = ({ isUpdate }) => {
key={id}
id={STEP_ID}
className={classes[id]}
cy={`${STEP_ID}.${id}`}
cy={`${STEP_ID}-${id}`}
{...section}
/>
))}
@@ -60,8 +60,9 @@ const SidebarCollapseItem = ({ label = '', routes = [], icon: Icon }) => {
</ListItemIcon>
)}
<ListItemText
data-cy={label}
data-cy={label.toLocaleLowerCase()}
primary={label}
{...expanded && {className: "open"}}
primaryTypographyProps={{ variant: 'body1' }}
/>
{expanded ? <CollapseIcon /> : <ExpandMoreIcon />}
@@ -100,7 +100,7 @@ const StatusChip = memo(
component="span"
className={classes.text}
onClick={callAll(onClick, clipboard && handleCopy)}
data-cy={dataCy}
{...(dataCy && { 'data-cy': dataCy })}
{...props}
>
{text}
@@ -63,10 +63,11 @@ const useStyles = makeStyles(({ spacing, palette, shape, breakpoints }) => ({
*
* @param {object} props - Props
* @param {string} props.className - Class to wrapper root
* @param {object} props.searchProps - Props for search input
* @param {UseGlobalFiltersInstanceProps} props.useTableProps - Table props
* @returns {JSXElementConstructor} Component JSX
*/
const GlobalFilter = ({ useTableProps, className }) => {
const GlobalFilter = ({ useTableProps, className, searchProps }) => {
const classes = useStyles()
const { setGlobalFilter, state } = useTableProps
@@ -100,7 +101,7 @@ const GlobalFilter = ({ useTableProps, className }) => {
root: classes.inputRoot,
input: classes.inputInput,
}}
inputProps={{ 'aria-label': 'search' }}
inputProps={{ 'aria-label': 'search', ...(searchProps ?? {}) }}
/>
</div>
)
@@ -109,6 +110,7 @@ const GlobalFilter = ({ useTableProps, className }) => {
GlobalFilter.propTypes = {
className: PropTypes.string,
useTableProps: PropTypes.object.isRequired,
searchProps: PropTypes.object,
}
export default GlobalFilter
@@ -50,10 +50,11 @@ const useToolbarStyles = makeStyles({
/**
* @param {object} props - Props
* @param {boolean} props.onlyGlobalSearch - Show only the global search
* @param {object} props.searchProps - Props for search input
* @param {UseTableInstanceProps} props.useTableProps - Table props
* @returns {JSXElementConstructor} Returns table toolbar
*/
const Filters = ({ onlyGlobalSearch, useTableProps }) => {
const Filters = ({ onlyGlobalSearch, useTableProps, searchProps }) => {
const classes = useToolbarStyles()
const isMobile = useMediaQuery((theme) => theme.breakpoints.down('md'))
@@ -77,6 +78,7 @@ const Filters = ({ onlyGlobalSearch, useTableProps }) => {
<GlobalFilter
className={classes.rootNoFilters}
useTableProps={useTableProps}
searchProps={searchProps}
/>
)
}
@@ -104,6 +106,7 @@ const Filters = ({ onlyGlobalSearch, useTableProps }) => {
Filters.propTypes = {
onlyGlobalSearch: PropTypes.bool,
useTableProps: PropTypes.object,
searchProps: PropTypes.object,
}
Filters.defaultProps = {
@@ -60,6 +60,7 @@ const EnhancedTable = ({
singleSelect = false,
classes = {},
rootProps = {},
searchProps = {},
}) => {
const styles = EnhancedTableStyles()
@@ -183,6 +184,7 @@ const EnhancedTable = ({
<Filters
onlyGlobalSearch={onlyGlobalSearch}
useTableProps={useTableProps}
searchProps={searchProps}
/>
)}
@@ -245,6 +247,9 @@ export const EnhancedTableProps = {
rootProps: PropTypes.shape({
'data-cy': PropTypes.string,
}),
searchProps: PropTypes.shape({
'data-cy': PropTypes.string,
}),
isLoading: PropTypes.bool,
onlyGlobalSearch: PropTypes.bool,
onlyGlobalSelectedRows: PropTypes.bool,
@@ -52,13 +52,15 @@ const Row = ({ original, value, ...props }) => {
const timeAgo = `registered ${time.toRelative()}`
return (
<div {...props}>
<div {...props} data-cy={`image-${ID}`}>
<div>
<StatusCircle color={stateColor} tooltip={stateName} />
</div>
<div className={classes.main}>
<div className={classes.title}>
<Typography component="span">{NAME}</Typography>
<Typography component="span" data-cy="name">
{NAME}
</Typography>
{LOCK && <Lock />}
<span className={classes.labels}>
{labels.map((label) => (
@@ -42,7 +42,7 @@ const Row = ({ original, value, ...props }) => {
VirtualNetworkModel.getLeasesInfo(original)
return (
<div {...props}>
<div {...props} data-cy={`network-${ID}`}>
<div className={classes.main}>
<div className={classes.title}>
<Typography component="span">{NAME}</Typography>
@@ -98,7 +98,11 @@ const StorageItem = ({ disk, actions = [] }) => {
</Typography>
<span className={classes.labels}>
{labels.map(({ label, dataCy }) => (
<StatusChip key={label} text={label} dataCy={dataCy} />
<StatusChip
key={label}
text={label}
{...(dataCy && { dataCy: dataCy })}
/>
))}
</span>
</div>
@@ -65,14 +65,14 @@ const VmStorageTab = ({ tabProps: { actions } = {} }) => {
}}
options={[
{
cy: 'attach-image-disk',
cy: 'attach-image',
name: T.Image,
dialogProps: { title: T.AttachImage },
form: () => ImageSteps({ hypervisor }),
onSubmit: handleAttachDisk,
},
{
cy: 'attach-volatile-disk',
cy: 'attach-volatile',
name: T.Volatile,
dialogProps: { title: T.AttachVolatile },
form: () => VolatileSteps({ hypervisor }),
@@ -80,6 +80,7 @@ const VmTabs = memo(({ id }) => {
return (
TabContent && {
name: camelName,
id: tabName,
renderContent: (props) => TabContent({ ...props, tabProps }),
}
)
@@ -73,14 +73,14 @@ const Tabs = ({
}}
{...tabsProps}
>
{tabs.map(({ value, name, label, error, icon: Icon }, idx) => (
{tabs.map(({ id, value, name, label, error, icon: Icon }, idx) => (
<MTab
key={`tab-${name}`}
id={`tab-${name}`}
icon={error ? <WarningIcon /> : Icon && <Icon />}
value={value ?? idx}
label={label ?? name}
data-cy={`tab-${name}`}
data-cy={`tab-${id}`}
/>
))}
</MTabs>