@centreon/ui 24.4.1-MON-34298-refato-metrics-selection.4 → 24.4.1-MON-21278-Delete-a-basic-token.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.4.1-MON-34298-refato-metrics-selection.4",
3
+ "version": "24.4.1-MON-21278-Delete-a-basic-token.19",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -1,4 +1,4 @@
1
- import { DialogContentText, Typography } from '@mui/material';
1
+ import { ButtonProps, DialogContentText, Typography } from '@mui/material';
2
2
 
3
3
  import Dialog, { Props as DialogProps } from '..';
4
4
 
@@ -6,15 +6,23 @@ type Props = DialogProps & {
6
6
  children?: JSX.Element;
7
7
  labelMessage?: string | null;
8
8
  labelSecondMessage?: string | null;
9
+ restCancelButtonProps?: ButtonProps;
10
+ restConfirmButtonProps?: ButtonProps;
9
11
  };
10
12
 
11
13
  const Confirm = ({
12
14
  labelMessage,
13
15
  labelSecondMessage,
14
16
  children,
17
+ restCancelButtonProps,
18
+ restConfirmButtonProps,
15
19
  ...rest
16
20
  }: Props): JSX.Element => (
17
- <Dialog {...rest}>
21
+ <Dialog
22
+ restCancelButtonProps={restCancelButtonProps}
23
+ restConfirmButtonProps={restConfirmButtonProps}
24
+ {...rest}
25
+ >
18
26
  <DialogContentText>
19
27
  {labelMessage && <Typography>{labelMessage}</Typography>}
20
28
  {labelSecondMessage && <Typography>{labelSecondMessage}</Typography>}
@@ -9,7 +9,8 @@ import {
9
9
  DialogContent,
10
10
  DialogActions,
11
11
  DialogProps,
12
- CircularProgress
12
+ CircularProgress,
13
+ ButtonProps
13
14
  } from '@mui/material';
14
15
 
15
16
  import { DataTestAttributes } from '../@types/data-attributes';
@@ -48,6 +49,8 @@ export type Props = {
48
49
  onClose?: () => void;
49
50
  onConfirm: (event, value?) => void;
50
51
  open: boolean;
52
+ restCancelButtonProps?: ButtonProps;
53
+ restConfirmButtonProps?: ButtonProps;
51
54
  submitting?: boolean;
52
55
  } & DialogProps &
53
56
  DataTestAttributes;
@@ -70,6 +73,8 @@ const Dialog = ({
70
73
  dialogContentClassName,
71
74
  dialogActionsClassName,
72
75
  dialogConfirmButtonClassName,
76
+ restCancelButtonProps,
77
+ restConfirmButtonProps,
73
78
  ...rest
74
79
  }: Props): JSX.Element => {
75
80
  const { classes, cx } = useStyles({ contentWidth });
@@ -101,6 +106,7 @@ const Dialog = ({
101
106
  data-testid="Cancel"
102
107
  disabled={cancelDisabled}
103
108
  onClick={onCancel}
109
+ {...restCancelButtonProps}
104
110
  >
105
111
  {labelCancel}
106
112
  </Button>
@@ -113,6 +119,7 @@ const Dialog = ({
113
119
  disabled={confirmDisabled}
114
120
  endIcon={submitting && <CircularProgress size={15} />}
115
121
  onClick={onConfirm}
122
+ {...restConfirmButtonProps}
116
123
  >
117
124
  {labelConfirm}
118
125
  </Button>
@@ -7,6 +7,7 @@ import { Box, alpha, useTheme } from '@mui/material';
7
7
 
8
8
  import { useMemoComponent } from '@centreon/ui';
9
9
 
10
+ import { maxLinesDisplayedLegend } from '../common';
10
11
  import { formatMetricValue } from '../../common/timeSeries';
11
12
  import { Line, TimeValue } from '../../common/timeSeries/models';
12
13
  import { labelAvg, labelMax, labelMin } from '../translatedLabels';
@@ -23,7 +24,7 @@ import LegendContent from './LegendContent';
23
24
  interface Props {
24
25
  base: number;
25
26
  displayAnchor?: boolean;
26
- limitLegend?: false | number;
27
+ limitLegendRows?: boolean;
27
28
  lines: Array<Line>;
28
29
  renderExtraComponent?: ReactNode;
29
30
  setLinesGraph: Dispatch<SetStateAction<Array<Line> | null>>;
@@ -38,14 +39,14 @@ const MainLegend = ({
38
39
  timeSeries,
39
40
  base,
40
41
  toggable = true,
41
- limitLegend = false,
42
+ limitLegendRows = true,
42
43
  renderExtraComponent,
43
44
  displayAnchor = true,
44
45
  setLinesGraph,
45
46
  xScale,
46
47
  shouldDisplayLegendInCompactMode
47
48
  }: Props): JSX.Element => {
48
- const { classes, cx } = useStyles({ limitLegendRows: Boolean(limitLegend) });
49
+ const { classes, cx } = useStyles({ limitLegendRows });
49
50
  const theme = useTheme();
50
51
 
51
52
  const { selectMetricLine, clearHighlight, highlightLine, toggleMetricLine } =
@@ -60,8 +61,8 @@ const MainLegend = ({
60
61
 
61
62
  const sortedData = sortBy(prop('metric_id'), lines);
62
63
 
63
- const displayedLines = limitLegend
64
- ? slice(0, limitLegend, sortedData)
64
+ const displayedLines = limitLegendRows
65
+ ? slice(0, maxLinesDisplayedLegend, sortedData)
65
66
  : sortedData;
66
67
 
67
68
  const getMetricValue = ({ value, unit }: GetMetricValueProps): string =>
@@ -173,7 +174,7 @@ const MainLegend = ({
173
174
  const Legend = (props: Props): JSX.Element => {
174
175
  const {
175
176
  toggable,
176
- limitLegend,
177
+ limitLegendRows,
177
178
  timeSeries,
178
179
  lines,
179
180
  base,
@@ -190,7 +191,7 @@ const Legend = (props: Props): JSX.Element => {
190
191
  lines,
191
192
  base,
192
193
  toggable,
193
- limitLegend,
194
+ limitLegendRows,
194
195
  displayAnchor,
195
196
  shouldDisplayLegendInCompactMode
196
197
  ]
@@ -43,7 +43,6 @@ interface Props extends LineChartProps {
43
43
  graphInterval: GraphInterval;
44
44
  graphRef: MutableRefObject<HTMLDivElement | null>;
45
45
  legend?: LegendModel;
46
- limitLegend?: false | number;
47
46
  marginBottom: number;
48
47
  shapeLines?: GlobalAreaLines;
49
48
  thresholdUnit?: string;
@@ -74,8 +73,7 @@ const LineChart = ({
74
73
  curve,
75
74
  marginBottom,
76
75
  thresholds,
77
- thresholdUnit,
78
- limitLegend
76
+ thresholdUnit
79
77
  }: Props): JSX.Element => {
80
78
  const { classes } = useStyles();
81
79
 
@@ -303,7 +301,6 @@ const LineChart = ({
303
301
  <Legend
304
302
  base={baseAxis}
305
303
  displayAnchor={displayAnchor?.displayGuidingLines ?? true}
306
- limitLegend={limitLegend}
307
304
  lines={newLines}
308
305
  renderExtraComponent={legend?.renderExtraComponent}
309
306
  setLinesGraph={setLinesGraph}
@@ -28,7 +28,6 @@ interface Props extends Partial<LineChartProps> {
28
28
  data?: LineChartData;
29
29
  end: string;
30
30
  legend: LegendModel;
31
- limitLegend?: false | number;
32
31
  loading: boolean;
33
32
  marginBottom?: number;
34
33
  shapeLines?: GlobalAreaLines;
@@ -56,8 +55,7 @@ const WrapperLineChart = ({
56
55
  curve = Curve.curveLinear,
57
56
  marginBottom = 0,
58
57
  thresholds,
59
- thresholdUnit,
60
- limitLegend
58
+ thresholdUnit
61
59
  }: Props): JSX.Element | null => {
62
60
  const { adjustedData } = useLineChartData({ data, end, start });
63
61
  const lineChartRef = useRef<HTMLDivElement | null>(null);
@@ -97,7 +95,6 @@ const WrapperLineChart = ({
97
95
  header={header}
98
96
  height={height || responsiveHeight}
99
97
  legend={legend}
100
- limitLegend={limitLegend}
101
98
  loading={loading}
102
99
  marginBottom={marginBottom}
103
100
  shapeLines={shapeLines}
@@ -1,20 +1,11 @@
1
1
  import { useRef } from 'react';
2
2
 
3
- import {
4
- equals,
5
- flatten,
6
- has,
7
- includes,
8
- isEmpty,
9
- not,
10
- pipe,
11
- pluck
12
- } from 'ramda';
3
+ import { equals, has, isEmpty, pluck } from 'ramda';
13
4
  import dayjs from 'dayjs';
14
5
 
15
6
  import { LineChartData, buildListingEndpoint, useFetchQuery } from '../..';
16
7
 
17
- import { Metric, Resource, WidgetResourceType } from './models';
8
+ import { Resource, WidgetResourceType } from './models';
18
9
 
19
10
  interface CustomTimePeriod {
20
11
  end: string;
@@ -23,9 +14,7 @@ interface CustomTimePeriod {
23
14
 
24
15
  interface UseMetricsQueryProps {
25
16
  baseEndpoint: string;
26
- bypassMetricsExclusion?: boolean;
27
- includeAllResources?: boolean;
28
- metrics: Array<Metric>;
17
+ metrics: Array<string>;
29
18
  refreshCount?: number;
30
19
  refreshInterval?: number | false;
31
20
  resources?: Array<Resource>;
@@ -82,7 +71,6 @@ const areResourcesFullfilled = (value: Array<Resource>): boolean =>
82
71
  );
83
72
 
84
73
  const useGraphQuery = ({
85
- bypassMetricsExclusion,
86
74
  metrics,
87
75
  resources = [],
88
76
  baseEndpoint,
@@ -105,7 +93,7 @@ const useGraphQuery = ({
105
93
 
106
94
  const definedMetrics = metrics.filter((metric) => metric);
107
95
  const formattedDefinedMetrics = definedMetrics.map((metric) =>
108
- encodeURIComponent(metric.name)
96
+ encodeURIComponent(metric)
109
97
  );
110
98
 
111
99
  const {
@@ -157,16 +145,7 @@ const useGraphQuery = ({
157
145
  base: data.current.base,
158
146
  title: ''
159
147
  },
160
- metrics: bypassMetricsExclusion
161
- ? data.current.metrics
162
- : data.current.metrics.filter(({ metric_id }) => {
163
- return pipe(
164
- pluck('excludedMetrics'),
165
- flatten,
166
- includes(metric_id),
167
- not
168
- )(metrics);
169
- }),
148
+ metrics: data.current.metrics,
170
149
  times: data.current.times
171
150
  }
172
151
  : undefined;
@@ -13,8 +13,3 @@ export enum WidgetResourceType {
13
13
  serviceCategory = 'service-category',
14
14
  serviceGroup = 'service-group'
15
15
  }
16
-
17
- export interface Metric {
18
- excludedMetrics: Array<number>;
19
- name: string;
20
- }
@@ -1,7 +1,5 @@
1
1
  import { Meta, StoryObj } from '@storybook/react';
2
2
 
3
- import { Checkbox, Typography } from '@mui/material';
4
-
5
3
  import { CollapsibleItem } from './CollapsibleItem';
6
4
 
7
5
  const meta: Meta<typeof CollapsibleItem> = {
@@ -25,27 +23,3 @@ export const ExpandedByDefault: Story = {
25
23
  title: 'Title'
26
24
  }
27
25
  };
28
-
29
- export const customizedTitle: Story = {
30
- args: {
31
- children: 'Label',
32
- defaultExpanded: false,
33
- title: <Typography>Title</Typography>
34
- }
35
- };
36
-
37
- export const customizedTitleAndCompact: Story = {
38
- args: {
39
- children: 'Label',
40
- compact: true,
41
- defaultExpanded: false,
42
- title: (
43
- <div
44
- style={{ alignItems: 'center', display: 'flex', flexDirection: 'row' }}
45
- >
46
- <Checkbox size="small" />
47
- <Typography>Title compact</Typography>
48
- </div>
49
- )
50
- }
51
- };
@@ -1,7 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
2
 
3
- import { equals, type } from 'ramda';
4
-
5
3
  import {
6
4
  AccordionDetails,
7
5
  AccordionSummary,
@@ -12,63 +10,36 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
12
10
 
13
11
  import { useCollapsibleItemStyles } from './useCollapsibleItemStyles';
14
12
 
15
- export interface Props {
13
+ interface Props {
16
14
  children: ReactNode;
17
- compact?: boolean;
18
- dataTestId?: string;
19
15
  defaultExpanded?: boolean;
20
- title: string | JSX.Element;
16
+ title: string;
21
17
  }
22
18
 
23
19
  export const CollapsibleItem = ({
24
20
  title,
25
21
  children,
26
- defaultExpanded,
27
- compact = false,
28
- dataTestId = ''
22
+ defaultExpanded
29
23
  }: Props): JSX.Element => {
30
- const { classes, cx } = useCollapsibleItemStyles();
31
-
32
- const isStringTitle = equals(type(title), 'String');
24
+ const { classes } = useCollapsibleItemStyles();
33
25
 
34
26
  return (
35
27
  <Accordion
36
28
  disableGutters
37
29
  className={classes.accordion}
38
- data-compact={compact}
39
- data-testid={`${dataTestId}-accordion`}
40
30
  defaultExpanded={defaultExpanded}
41
31
  >
42
- <div className={classes.summaryContainer}>
43
- <div className={classes.customTitle}>{!isStringTitle && title}</div>
44
- <AccordionSummary
45
- classes={{
46
- content: cx(
47
- compact
48
- ? classes.accordionSummaryCompactContent
49
- : classes.accordionSummary
50
- ),
51
- root: cx(
52
- compact
53
- ? classes.accordionSummaryCompactRoot
54
- : classes.accordionSummaryRoot
55
- )
56
- }}
57
- data-testid={`${dataTestId}-summary`}
58
- expandIcon={<ExpandMoreIcon color="primary" />}
59
- >
60
- {isStringTitle && (
61
- <Typography color="primary" variant="h6">
62
- {title}
63
- </Typography>
64
- )}
65
- </AccordionSummary>
66
- </div>
67
- <AccordionDetails
68
- className={cx(
69
- compact ? classes.accordionDetailsCompact : classes.accordionDetails
70
- )}
32
+ <AccordionSummary
33
+ classes={{
34
+ content: classes.accordionSummary
35
+ }}
36
+ expandIcon={<ExpandMoreIcon color="primary" />}
71
37
  >
38
+ <Typography color="primary" variant="h6">
39
+ {title}
40
+ </Typography>
41
+ </AccordionSummary>
42
+ <AccordionDetails className={classes.accordionDetails}>
72
43
  {children}
73
44
  </AccordionDetails>
74
45
  </Accordion>
@@ -4,35 +4,12 @@ export const useCollapsibleItemStyles = makeStyles()((theme) => ({
4
4
  accordion: {
5
5
  backgroundColor: 'transparent',
6
6
  border: 'none',
7
- borderBottom: `1px solid ${theme.palette.divider}`,
8
- width: '100%'
7
+ borderBottom: `1px solid ${theme.palette.divider}`
9
8
  },
10
9
  accordionDetails: {
11
10
  padding: theme.spacing(0, 2, 2)
12
11
  },
13
- accordionDetailsCompact: {
14
- padding: theme.spacing(0)
15
- },
16
12
  accordionSummary: {
17
13
  margin: theme.spacing(1.5, 0)
18
- },
19
- accordionSummaryCompactContent: {
20
- margin: theme.spacing(0, 0, 0.5)
21
- },
22
- accordionSummaryCompactRoot: {
23
- minHeight: theme.spacing(1),
24
- width: '100%'
25
- },
26
- accordionSummaryRoot: {
27
- width: '100%'
28
- },
29
- customTitle: {
30
- whiteSpace: 'nowrap'
31
- },
32
- summaryContainer: {
33
- alignItems: 'center',
34
- display: 'flex',
35
- flexDirection: 'row',
36
- width: '100%'
37
14
  }
38
15
  }));
@@ -7,7 +7,7 @@ import { IconButton } from '..';
7
7
  import { useItemStyles } from './ItemComposition.styles';
8
8
 
9
9
  type Props = {
10
- children: ReactElement | Array<ReactElement>;
10
+ children: Array<ReactElement>;
11
11
  className?: string;
12
12
  deleteButtonHidden?: boolean;
13
13
  labelDelete: string;
@@ -1,13 +1,6 @@
1
1
  import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  export const useItemCompositionStyles = makeStyles()((theme) => ({
4
- buttonAndSecondaryLabel: {
5
- alignItems: 'center',
6
- display: 'flex',
7
- flexDirection: 'row',
8
- justifyContent: 'space-between',
9
- width: '100%'
10
- },
11
4
  itemCompositionContainer: {
12
5
  alignItems: 'flex-start',
13
6
  display: 'flex',
@@ -31,6 +24,6 @@ export const useItemStyles = makeStyles()((theme) => ({
31
24
  width: '100%'
32
25
  },
33
26
  visibilityHiden: {
34
- display: 'none'
27
+ visibility: 'hidden'
35
28
  }
36
29
  }));
@@ -1,20 +1,18 @@
1
1
  import { ReactElement } from 'react';
2
2
 
3
3
  import AddIcon from '@mui/icons-material/Add';
4
- import { Typography } from '@mui/material';
5
4
 
6
5
  import { Button } from '..';
7
6
 
8
7
  import { useItemCompositionStyles } from './ItemComposition.styles';
9
8
 
10
- export type Props = {
9
+ type Props = {
11
10
  IconAdd?;
12
11
  addButtonHidden?: boolean;
13
12
  addbuttonDisabled?: boolean;
14
13
  children: Array<ReactElement>;
15
14
  labelAdd: string;
16
15
  onAddItem: () => void;
17
- secondaryLabel?: string;
18
16
  };
19
17
 
20
18
  export const ItemComposition = ({
@@ -23,35 +21,27 @@ export const ItemComposition = ({
23
21
  labelAdd,
24
22
  addbuttonDisabled,
25
23
  addButtonHidden,
26
- IconAdd,
27
- secondaryLabel
24
+ IconAdd
28
25
  }: Props): JSX.Element => {
29
26
  const { classes } = useItemCompositionStyles();
30
27
 
31
28
  return (
32
29
  <div className={classes.itemCompositionContainer}>
33
30
  {children}
34
- <div className={classes.buttonAndSecondaryLabel}>
35
- {!addButtonHidden && (
36
- <Button
37
- aria-label={labelAdd}
38
- data-testid={labelAdd}
39
- disabled={addbuttonDisabled}
40
- icon={IconAdd || <AddIcon />}
41
- iconVariant="start"
42
- size="small"
43
- variant="ghost"
44
- onClick={onAddItem}
45
- >
46
- {labelAdd}
47
- </Button>
48
- )}
49
- {secondaryLabel && (
50
- <Typography sx={{ color: 'text.secondary' }}>
51
- {secondaryLabel}
52
- </Typography>
53
- )}
54
- </div>
31
+ {!addButtonHidden && (
32
+ <Button
33
+ aria-label={labelAdd}
34
+ data-testid={labelAdd}
35
+ disabled={addbuttonDisabled}
36
+ icon={IconAdd || <AddIcon />}
37
+ iconVariant="start"
38
+ size="small"
39
+ variant="ghost"
40
+ onClick={onAddItem}
41
+ >
42
+ {labelAdd}
43
+ </Button>
44
+ )}
55
45
  </div>
56
46
  );
57
47
  };
@@ -1,76 +0,0 @@
1
- import { CollapsibleItem, Props } from './CollapsibleItem';
2
-
3
- const title = 'Title';
4
-
5
- const customizedTitle = <div>Customized title</div>;
6
-
7
- const initialize = (props: Omit<Props, 'children'>): void => {
8
- cy.mount({
9
- Component: <CollapsibleItem {...props}>Content</CollapsibleItem>
10
- });
11
- };
12
-
13
- describe('CollapsibleItem', () => {
14
- it('displays the component collpased by default', () => {
15
- initialize({ title });
16
-
17
- cy.contains(title).should('be.visible');
18
- cy.contains('Content').should('not.be.visible');
19
- cy.get('div[aria-expanded="false"]').should('exist');
20
-
21
- cy.makeSnapshot();
22
- });
23
-
24
- it('displays the component expanded when the corresponding prop is set to true', () => {
25
- initialize({ defaultExpanded: true, title });
26
-
27
- cy.contains(title).should('be.visible');
28
- cy.contains('Content').should('be.visible');
29
- cy.get('div[aria-expanded="true"]').should('exist');
30
-
31
- cy.makeSnapshot();
32
- });
33
-
34
- it('displays a customized title', () => {
35
- initialize({ title: customizedTitle });
36
-
37
- cy.contains('Customized title').should('be.visible');
38
- cy.get('div[aria-expanded="false"]').should('exist');
39
-
40
- cy.makeSnapshot();
41
- });
42
-
43
- it('displays the component as compact', () => {
44
- initialize({ compact: true, title });
45
-
46
- cy.contains(title).should('be.visible');
47
- cy.get('div[aria-expanded="false"]').should('exist');
48
- cy.get('div[data-compact="true"]').should('exist');
49
-
50
- cy.makeSnapshot();
51
- });
52
-
53
- it('displays the component as compact and expanded when the icon is clicked', () => {
54
- initialize({ compact: true, title });
55
-
56
- cy.contains(title).should('be.visible');
57
- cy.get('div[aria-expanded="false"]').should('exist');
58
-
59
- cy.get('div[aria-expanded="false"]').click();
60
-
61
- cy.get('div[aria-expanded="true"]').should('exist');
62
- cy.contains('Content').should('be.visible');
63
-
64
- cy.makeSnapshot();
65
- });
66
-
67
- it('displays the component as compact and a customized title', () => {
68
- initialize({ compact: true, title: customizedTitle });
69
-
70
- cy.contains('Customized title').should('be.visible');
71
- cy.get('div[aria-expanded="false"]').should('exist');
72
- cy.get('div[data-compact="true"]').should('exist');
73
-
74
- cy.makeSnapshot();
75
- });
76
- });
@@ -1,116 +0,0 @@
1
- import { ItemComposition } from '.';
2
-
3
- interface Props {
4
- addButtonHidden?: boolean;
5
- addbuttonDisabled?: boolean;
6
- deleteButtonHidden?: boolean;
7
- secondaryLabel?: string;
8
- }
9
-
10
- const initialize = ({
11
- addButtonHidden,
12
- addbuttonDisabled,
13
- secondaryLabel,
14
- deleteButtonHidden
15
- }: Props): unknown => {
16
- const addItem = cy.stub();
17
- const deleteItem = cy.stub();
18
-
19
- cy.mount({
20
- Component: (
21
- <ItemComposition
22
- addButtonHidden={addButtonHidden}
23
- addbuttonDisabled={addbuttonDisabled}
24
- labelAdd="Add"
25
- secondaryLabel={secondaryLabel}
26
- onAddItem={addItem}
27
- >
28
- <ItemComposition.Item
29
- deleteButtonHidden={deleteButtonHidden}
30
- labelDelete="Delete"
31
- onDeleteItem={deleteItem}
32
- >
33
- <div>Item 1</div>
34
- </ItemComposition.Item>
35
- <ItemComposition.Item
36
- deleteButtonHidden={deleteButtonHidden}
37
- labelDelete="Delete"
38
- onDeleteItem={deleteItem}
39
- >
40
- <div>Item 2</div>
41
- </ItemComposition.Item>
42
- </ItemComposition>
43
- )
44
- });
45
-
46
- return {
47
- addItem,
48
- deleteItem
49
- };
50
- };
51
-
52
- describe('ItemComposition', () => {
53
- it('displays the component', () => {
54
- initialize({});
55
-
56
- cy.contains('Item 1').should('be.visible');
57
- cy.contains('Item 2').should('be.visible');
58
- cy.findAllByTestId('Delete').should('have.length', 2);
59
- cy.findByTestId('Add').should('be.enabled');
60
-
61
- cy.makeSnapshot();
62
- });
63
-
64
- it('displays the component with a secondary label', () => {
65
- initialize({ secondaryLabel: 'Secondary label' });
66
-
67
- cy.contains('Secondary label').should('be.visible');
68
-
69
- cy.makeSnapshot();
70
- });
71
-
72
- it('displays add button as hidden when the prop is set to true', () => {
73
- initialize({ addbuttonDisabled: true });
74
-
75
- cy.findByTestId('Add').should('be.disabled');
76
-
77
- cy.makeSnapshot();
78
- });
79
-
80
- it('does not display the add button as hidden when the prop is set to true', () => {
81
- initialize({ addButtonHidden: true });
82
-
83
- cy.findByTestId('Add').should('not.exist');
84
-
85
- cy.makeSnapshot();
86
- });
87
-
88
- it('does not display the delete button as hidden when the prop is set to true', () => {
89
- initialize({ deleteButtonHidden: true });
90
-
91
- cy.findByTestId('Delete').should('not.exist');
92
-
93
- cy.makeSnapshot();
94
- });
95
-
96
- it('calls the add function when the button is clicked', () => {
97
- const { addItem } = initialize({});
98
-
99
- cy.findByTestId('Add')
100
- .click()
101
- .then(() => {
102
- expect(addItem).to.have.been.calledWith();
103
- });
104
- });
105
-
106
- it('calls the delete function when the button is clicked', () => {
107
- const { deleteItem } = initialize({});
108
-
109
- cy.findAllByTestId('Delete')
110
- .eq(1)
111
- .click()
112
- .then(() => {
113
- expect(deleteItem).to.have.been.calledWith();
114
- });
115
- });
116
- });