Skip to content

Commit

Permalink
add data-cy
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciej Szewczyk committed Nov 13, 2024
1 parent 5caf793 commit bbdab5c
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 19 deletions.
16 changes: 14 additions & 2 deletions src/frontend/src/components/core/ButtonTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,37 @@ interface ButtonTooltipProps {
title?: string;
disabled?: boolean;
[key: string]: any;
dataCy?: string;
}

export const ButtonTooltip: FC<ButtonTooltipProps> = ({
children,
onClick = () => null,
title = 'Permission denied',
disabled,
dataCy,
...otherProps
}) => {
return disabled ? (
<Tooltip title={title}>
<span>
<Button disabled={disabled} onClick={onClick} {...otherProps}>
<Button
disabled={disabled}
onClick={onClick}
data-cy={dataCy}
{...otherProps}
>
{children}
</Button>
</span>
</Tooltip>
) : (
<Button disabled={disabled} onClick={onClick} {...otherProps}>
<Button
disabled={disabled}
onClick={onClick}
data-cy={dataCy}
{...otherProps}
>
{children}
</Button>
);
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/targeting/CreateTPMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const CreateTPMenu = (): ReactElement => {
)}
component={Link}
to={`/${baseUrl}/target-population/create`}
data-cy="button-target-population-create-new"
dataCy="button-new-tp-disabled"
disabled={!isActiveProgram}
>
{t('Create New')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export const CreateTargetPopulationHeader = ({
>
<>
<Box m={2}>
<Button component={Link} to={`/${baseUrl}/target-population`}>
<Button
data-cy="button-cancel"
component={Link}
to={`/${baseUrl}/target-population`}
>
{t('Cancel')}
</Button>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ export const EditTargetPopulation = ({
onSubmit={handleSubmit}
>
{({ values, submitForm, errors, setFieldValue }) => (
<Form>
<Form data-cy="edit-target-population-form">
<AutoSubmitFormOnEnter />
<EditTargetPopulationHeader
handleSubmit={submitForm}
values={values}
loading={loading}
baseUrl={baseUrl}
targetPopulation={targetPopulation}
data-cy="edit-target-population-header"
/>
<PaperContainer>
<PaperContainer data-cy="paper-container">
<Box pt={3} pb={3}>
<Typography variant="h6">{t('Targeting Criteria')}</Typography>
</Box>
Expand All @@ -142,6 +143,7 @@ export const EditTargetPopulation = ({
required
// @ts-ignore
error={errors.programCycleId?.value}
data-cy="program-cycle-autocomplete"
/>
</Grid>
</Grid>
Expand All @@ -155,7 +157,6 @@ export const EditTargetPopulation = ({
required
component={FormikTextField}
variant="outlined"
data-cy="input-name"
disabled={targetPopulation.status === 'LOCKED'}
/>
</Grid>
Expand All @@ -173,17 +174,22 @@ export const EditTargetPopulation = ({
screenBeneficiary={screenBeneficiary}
isStandardDctType={isStandardDctType}
isSocialDctType={isSocialDctType}
data-cy="add-filter-targeting-criteria-display"
/>
)}
/>
</PaperContainer>
<Exclusions initialOpen={Boolean(values.excludedIds)} />
<Exclusions
initialOpen={Boolean(values.excludedIds)}
data-cy="exclusions"
/>
<Box
pt={3}
pb={3}
display="flex"
flexDirection="column"
alignItems="center"
data-cy="save-message-box"
>
<Typography style={{ color: '#b1b1b5' }} variant="h6">
{t('Save to see the list of households')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const PduDataBox = styled(Box)`
margin: ${({ theme }) => theme.spacing(3)};
`;

const CriteriaField = ({ field, choicesDict }): ReactElement => {
const CriteriaField = ({ field, choicesDict, dataCy }): ReactElement => {
const extractChoiceLabel = (choiceField, argument) => {
let choices = choicesDict?.[choiceField.fieldName];
if (!choices) {
Expand Down Expand Up @@ -205,7 +205,7 @@ const CriteriaField = ({ field, choicesDict }): ReactElement => {

return (
<>
{fieldElement}
<div data-cy={dataCy}>{fieldElement}</div>
{field.fieldAttribute?.type === 'PDU' &&
(field.pduData || field.fieldAttribute.pduData) && (
<PduDataBox data-cy="round-number-round-name-display">
Expand Down Expand Up @@ -338,17 +338,22 @@ export function Criteria({
choicesDict={allDataFieldsChoicesDict}
key={index}
field={each}
dataCy={`criteria-field-${index}`}
/>
))}
{individualsFiltersBlocks.map(
(item, index) =>
item.individualBlockFilters.length > 0 && (
<CriteriaSetBox key={index}>
<CriteriaSetBox
key={index}
data-cy={`individuals-criteria-set-box-${index}`}
>
{item.individualBlockFilters.map((filter, filterIndex) => (
<CriteriaField
choicesDict={allDataFieldsChoicesDict}
key={filterIndex}
field={filter}
dataCy={`individuals-criteria-field-${filterIndex}`}
/>
))}
</CriteriaSetBox>
Expand All @@ -357,12 +362,16 @@ export function Criteria({
{collectorsFiltersBlocks.map(
(item, index) =>
item.collectorBlockFilters.length > 0 && (
<CriteriaSetBox key={index}>
<CriteriaSetBox
key={index}
data-cy={`collectors-criteria-set-box-${index}`}
>
{item.collectorBlockFilters.map((filter, filterIndex) => (
<CriteriaField
choicesDict={allCollectorFieldsChoicesDict}
key={filterIndex}
field={filter}
dataCy={`collectors-criteria-field-${filterIndex}`}
/>
))}
</CriteriaSetBox>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ export const TargetingCriteriaCollectorFilterBlocks = ({
blockIndex + 1 < values.collectorsFiltersBlocks.length;

return (
<div>
<div data-cy="collectors-filters-block">
<FieldArray
name={`collectorsFiltersBlocks[${blockIndex}].collectorBlockFilters`}
render={(arrayHelpers) => (
<div>
<GrayFiltersBlock>
<GrayFiltersBlock data-cy="gray-filters-block">
{values.collectorsFiltersBlocks[
blockIndex
].collectorBlockFilters.map((each, index) => {
Expand All @@ -101,7 +101,7 @@ export const TargetingCriteriaCollectorFilterBlocks = ({
.collectorBlockFilters.length;
return (
<Fragment key={blockIndex + index.toString()}>
<FilterWrapper>
<FilterWrapper data-cy="filter-wrapper">
<TargetingCriteriaCollectorBlockFilter
blockIndex={blockIndex}
index={index}
Expand All @@ -124,11 +124,12 @@ export const TargetingCriteriaCollectorFilterBlocks = ({
}
arrayHelpers.remove(index);
}}
data-cy="collector-block-filter"
/>
</FilterWrapper>
{shouldShowDivider && (
<Divider>
<DividerLabel>+</DividerLabel>
<Divider data-cy="divider">
<DividerLabel data-cy="divider-label">+</DividerLabel>
</Divider>
)}
</Fragment>
Expand All @@ -149,6 +150,7 @@ export const TargetingCriteriaCollectorFilterBlocks = ({
top: 18,
backgroundColor: '#fff',
}}
data-cy="add-next-rule-button"
>
{t('Add Next Rule')}
</Button>
Expand All @@ -158,8 +160,10 @@ export const TargetingCriteriaCollectorFilterBlocks = ({
)}
/>
{shouldShowAndDivider && (
<AndDivider>
<AndDividerLabel>{t('And')}</AndDividerLabel>
<AndDivider data-cy="and-divider">
<AndDividerLabel data-cy="and-divider-label">
{t('And')}
</AndDividerLabel>
</AndDivider>
)}
</div>
Expand Down

0 comments on commit bbdab5c

Please sign in to comment.