@reltio/components 1.4.1955 → 1.4.1957

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.
Files changed (67) hide show
  1. package/cjs/AttributesFiltersBuilder/AttributesFiltersBuilder.js +1 -1
  2. package/cjs/AttributesFiltersBuilder/helpers.d.ts +1 -1
  3. package/cjs/AttributesFiltersBuilder/helpers.js +25 -22
  4. package/cjs/AttributesFiltersButton/AttributesFiltersButton.js +1 -1
  5. package/cjs/AttributesFiltersButton/components/ActionButtons/styles.js +2 -2
  6. package/cjs/AttributesFiltersButton/styles.d.ts +1 -1
  7. package/cjs/AttributesFiltersButton/styles.js +10 -7
  8. package/cjs/CustomDateRangeEditor/CustomDateRangeEditor.js +1 -1
  9. package/cjs/DateIntervalSelector/DateIntervalSelector.js +1 -1
  10. package/cjs/DateRangeSelector/DateRangeSelector.d.ts +9 -0
  11. package/cjs/DateRangeSelector/DateRangeSelector.js +144 -0
  12. package/cjs/DateRangeSelector/DateRangeSelector.specs.js +294 -0
  13. package/cjs/DateRangeSelector/index.d.ts +1 -0
  14. package/cjs/DateRangeSelector/index.js +5 -0
  15. package/cjs/DateRangeSelector/styles.d.ts +1 -0
  16. package/cjs/DateRangeSelector/styles.js +30 -0
  17. package/cjs/InfoIcon/InfoIcon.d.ts +6 -0
  18. package/cjs/InfoIcon/InfoIcon.js +60 -0
  19. package/cjs/InfoIcon/index.d.ts +1 -0
  20. package/cjs/InfoIcon/index.js +5 -0
  21. package/cjs/InfoIcon/styles.d.ts +1 -0
  22. package/cjs/InfoIcon/styles.js +9 -0
  23. package/cjs/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/DateRangeSelector.js +3 -108
  24. package/cjs/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/styles.d.ts +1 -1
  25. package/cjs/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/styles.js +0 -54
  26. package/cjs/icons/Info.d.ts +3 -0
  27. package/cjs/icons/Info.js +22 -0
  28. package/cjs/icons/index.d.ts +1 -0
  29. package/cjs/icons/index.js +4 -2
  30. package/cjs/index.d.ts +2 -0
  31. package/cjs/index.js +11 -7
  32. package/esm/AttributesFiltersBuilder/AttributesFiltersBuilder.js +2 -2
  33. package/esm/AttributesFiltersBuilder/helpers.d.ts +1 -1
  34. package/esm/AttributesFiltersBuilder/helpers.js +24 -21
  35. package/esm/AttributesFiltersButton/AttributesFiltersButton.js +1 -1
  36. package/esm/AttributesFiltersButton/components/ActionButtons/styles.js +2 -2
  37. package/esm/AttributesFiltersButton/styles.d.ts +1 -1
  38. package/esm/AttributesFiltersButton/styles.js +10 -7
  39. package/esm/CustomDateRangeEditor/CustomDateRangeEditor.js +1 -1
  40. package/esm/DateIntervalSelector/DateIntervalSelector.js +1 -1
  41. package/esm/DateRangeSelector/DateRangeSelector.d.ts +9 -0
  42. package/esm/DateRangeSelector/DateRangeSelector.js +114 -0
  43. package/esm/DateRangeSelector/DateRangeSelector.specs.js +289 -0
  44. package/esm/DateRangeSelector/index.d.ts +1 -0
  45. package/esm/DateRangeSelector/index.js +1 -0
  46. package/esm/DateRangeSelector/styles.d.ts +1 -0
  47. package/esm/DateRangeSelector/styles.js +27 -0
  48. package/esm/InfoIcon/InfoIcon.d.ts +6 -0
  49. package/esm/InfoIcon/InfoIcon.js +34 -0
  50. package/esm/InfoIcon/index.d.ts +1 -0
  51. package/esm/InfoIcon/index.js +1 -0
  52. package/esm/InfoIcon/styles.d.ts +1 -0
  53. package/esm/InfoIcon/styles.js +6 -0
  54. package/esm/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/DateRangeSelector.js +3 -85
  55. package/esm/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/styles.d.ts +1 -1
  56. package/esm/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/styles.js +0 -54
  57. package/esm/icons/Info.d.ts +3 -0
  58. package/esm/icons/Info.js +17 -0
  59. package/esm/icons/index.d.ts +1 -0
  60. package/esm/icons/index.js +1 -0
  61. package/esm/index.d.ts +2 -0
  62. package/esm/index.js +2 -0
  63. package/package.json +2 -2
  64. package/cjs/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/DateRangeSelector.specs.js +0 -185
  65. package/esm/features/activity-log/ActivityFilterEditor/components/DateRangeSelector/DateRangeSelector.specs.js +0 -180
  66. /package/cjs/{features/activity-log/ActivityFilterEditor/components/DateRangeSelector → DateRangeSelector}/DateRangeSelector.specs.d.ts +0 -0
  67. /package/esm/{features/activity-log/ActivityFilterEditor/components/DateRangeSelector → DateRangeSelector}/DateRangeSelector.specs.d.ts +0 -0
@@ -1,95 +1,13 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import React, { useState } from 'react';
1
+ import React from 'react';
13
2
  import i18n from 'ui-i18n';
14
- import { pipe } from 'ramda';
15
3
  import classnames from 'classnames';
16
- import { DateRangeTypes } from '@reltio/mdm-sdk';
17
- import FormControlLabel from '@mui/material/FormControlLabel';
18
- import Radio from '@mui/material/Radio';
19
- import RadioGroup from '@mui/material/RadioGroup';
20
4
  import Typography from '@mui/material/Typography';
21
- import { DateIntervalSelector } from '../../../../../DateIntervalSelector';
22
- import { getValue } from '../../../../../helpers/events';
23
- import { CustomDateRangeEditor } from '../../../../../CustomDateRangeEditor';
24
- import { useDidUpdateEffect } from '../../../../../hooks/useDidUpdateEffect';
5
+ import { DateRangeSelector as BaseDateRangeSelector } from '../../../../../DateRangeSelector';
25
6
  import { useStyles } from '../../styles';
26
- var emptyDates = [null, null];
27
- var emptyInterval = [null, 'minutes'];
28
7
  export var DateRangeSelector = function (_a) {
29
8
  var value = _a.value, onChange = _a.onChange;
30
9
  var styles = useStyles();
31
- var getInitPeriodByType = function (type) {
32
- if ((value === null || value === void 0 ? void 0 : value.type) === type) {
33
- return value.period;
34
- }
35
- else if (type === DateRangeTypes.WITHIN || type === DateRangeTypes.AGO) {
36
- return emptyInterval;
37
- }
38
- else if (type === DateRangeTypes.BETWEEN) {
39
- return emptyDates;
40
- }
41
- };
42
- var _b = useState(getInitPeriodByType(DateRangeTypes.BETWEEN)), datesInterval = _b[0], setDatesInterval = _b[1];
43
- var _c = useState(getInitPeriodByType(DateRangeTypes.WITHIN)), withinInterval = _c[0], setWithinInterval = _c[1];
44
- var _d = useState(getInitPeriodByType(DateRangeTypes.AGO)), agoInterval = _d[0], setAgoInterval = _d[1];
45
- var getCurrentPeriodByType = function (type) {
46
- if (type === DateRangeTypes.WITHIN) {
47
- return withinInterval;
48
- }
49
- else if (type === DateRangeTypes.AGO) {
50
- return agoInterval;
51
- }
52
- else if (type === DateRangeTypes.BETWEEN) {
53
- return datesInterval;
54
- }
55
- };
56
- var changeType = function (type) {
57
- if ((value === null || value === void 0 ? void 0 : value.type) !== type) {
58
- onChange({ period: getCurrentPeriodByType(type), type: type });
59
- }
60
- };
61
- var changePeriod = function (period) {
62
- onChange(__assign(__assign({}, value), { period: period }));
63
- };
64
- useDidUpdateEffect(function () {
65
- if (value) {
66
- if (value.type === DateRangeTypes.WITHIN) {
67
- setWithinInterval(value.period);
68
- }
69
- else if (value.type === DateRangeTypes.AGO) {
70
- setAgoInterval(value.period);
71
- }
72
- else if (value.type === DateRangeTypes.BETWEEN) {
73
- setDatesInterval(value.period);
74
- }
75
- }
76
- else {
77
- setDatesInterval(emptyDates);
78
- setWithinInterval(emptyInterval);
79
- setAgoInterval(emptyInterval);
80
- }
81
- }, [value]);
82
10
  return (React.createElement("div", { className: styles.selectorWrapper, "data-reltio-id": "date-range-selector" },
83
11
  React.createElement(Typography, { className: classnames(styles.filterSubtitle, styles.labels), variant: 'subtitle1' }, i18n.text('Date')),
84
- React.createElement(RadioGroup, { value: (value === null || value === void 0 ? void 0 : value.type) || null, onChange: pipe(getValue, changeType) },
85
- React.createElement("div", { className: styles.dateOptionWithin },
86
- React.createElement(FormControlLabel, { value: DateRangeTypes.WITHIN, control: React.createElement(Radio, { color: "primary" }), label: i18n.text('Within the last'), classes: { label: classnames(styles.dateOptionLabel, styles.labels) } }),
87
- React.createElement(DateIntervalSelector, { interval: withinInterval, onChange: changePeriod, onFocus: function () { return changeType(DateRangeTypes.WITHIN); } })),
88
- React.createElement("div", { className: styles.dateOptionAgo },
89
- React.createElement(FormControlLabel, { value: DateRangeTypes.AGO, control: React.createElement(Radio, { color: "primary" }), label: i18n.text('More than'), classes: { label: classnames(styles.dateOptionLabel, styles.labels) } }),
90
- React.createElement(DateIntervalSelector, { interval: agoInterval, onChange: changePeriod, onFocus: function () { return changeType(DateRangeTypes.AGO); } }),
91
- React.createElement(Typography, { className: classnames(styles.agoLabel, styles.labels), variant: 'subtitle1' }, i18n.text('Ago'))),
92
- React.createElement("div", { className: styles.dateOption },
93
- React.createElement(FormControlLabel, { value: DateRangeTypes.BETWEEN, control: React.createElement(Radio, { color: "primary" }), label: i18n.text('Date range'), classes: { label: classnames(styles.dateOptionLabel, styles.labels) } }),
94
- React.createElement(CustomDateRangeEditor, { values: datesInterval, onChange: changePeriod, onFocus: function () { return changeType(DateRangeTypes.BETWEEN); } })))));
12
+ React.createElement(BaseDateRangeSelector, { value: value, onChange: onChange })));
95
13
  };
@@ -1 +1 @@
1
- export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"container" | "option" | "labels" | "divider" | "clearButton" | "filterSubtitle" | "agoLabel" | "dateOption" | "dateOptionAgo" | "dateOptionWithin" | "dateOptionLabel" | "dropDownInput" | "editorFields" | "selectorWrapper" | "selectorsGroup" | "selectorHint">;
1
+ export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"labels" | "filterSubtitle" | "selectorWrapper">;
@@ -1,9 +1,5 @@
1
1
  import { makeStyles } from '@mui/styles';
2
2
  export var useStyles = makeStyles({
3
- container: {
4
- width: 500,
5
- boxSizing: 'border-box'
6
- },
7
3
  labels: {
8
4
  fontSize: '14px'
9
5
  },
@@ -11,57 +7,7 @@ export var useStyles = makeStyles({
11
7
  paddingBottom: '10px',
12
8
  paddingLeft: '5px'
13
9
  },
14
- agoLabel: {
15
- minWidth: '30px',
16
- textAlign: 'end',
17
- margin: 'auto'
18
- },
19
- dateOption: {
20
- display: 'flex',
21
- marginRight: '30px'
22
- },
23
- dateOptionAgo: {
24
- display: 'flex',
25
- marginBottom: '10px'
26
- },
27
- dateOptionWithin: {
28
- display: 'flex',
29
- marginRight: '30px',
30
- marginBottom: '10px'
31
- },
32
- dateOptionLabel: {
33
- minWidth: '100px'
34
- },
35
- dropDownInput: {
36
- width: '100%',
37
- justifyContent: 'center',
38
- backgroundColor: 'rgba(0, 0, 0, 0.03)',
39
- borderTop: '4px'
40
- },
41
- editorFields: {
42
- maxHeight: 400,
43
- borderColor: 'rgba(0,0,0,0.12)'
44
- },
45
- clearButton: {
46
- marginRight: 'auto'
47
- },
48
10
  selectorWrapper: {
49
11
  marginBottom: '12px'
50
- },
51
- option: {
52
- fontSize: '14px',
53
- height: '32px'
54
- },
55
- selectorsGroup: {
56
- display: 'flex',
57
- flexDirection: 'column'
58
- },
59
- selectorHint: {
60
- fontSize: 12,
61
- lineHeight: '16px',
62
- color: 'rgba(0,0,0,0.54)'
63
- },
64
- divider: {
65
- marginBottom: 12
66
12
  }
67
13
  });
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ declare const SvgInfo: React.FC<React.SVGProps<SVGSVGElement>>;
3
+ export default SvgInfo;
@@ -0,0 +1,17 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import React from 'react';
13
+ var SvgInfo = function (props) {
14
+ return (React.createElement("svg", __assign({ width: 24, height: 24, viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", "data-reltio-id": "SvgInfo" }, props),
15
+ React.createElement("path", { d: "M11.25 16.75h1.5V11h-1.5v5.75zM12 9.289c.229 0 .42-.078.575-.233a.782.782 0 00.233-.575.782.782 0 00-.232-.576.782.782 0 00-.576-.232.782.782 0 00-.575.232.782.782 0 00-.233.576c0 .229.078.42.232.575A.782.782 0 0012 9.29zm.002 12.211a9.254 9.254 0 01-3.706-.748 9.596 9.596 0 01-3.016-2.03 9.595 9.595 0 01-2.032-3.016 9.246 9.246 0 01-.748-3.704c0-1.314.25-2.55.748-3.706a9.596 9.596 0 012.03-3.016 9.594 9.594 0 013.016-2.032 9.246 9.246 0 013.704-.748c1.314 0 2.55.25 3.706.748a9.596 9.596 0 013.017 2.03 9.594 9.594 0 012.03 3.016 9.247 9.247 0 01.749 3.704c0 1.314-.25 2.55-.748 3.706a9.596 9.596 0 01-2.03 3.017 9.595 9.595 0 01-3.016 2.03 9.247 9.247 0 01-3.704.749zM12 20c2.233 0 4.125-.775 5.675-2.325C19.225 16.125 20 14.233 20 12c0-2.233-.775-4.125-2.325-5.675C16.125 4.775 14.233 4 12 4c-2.233 0-4.125.775-5.675 2.325C4.775 7.875 4 9.767 4 12c0 2.233.775 4.125 2.325 5.675C7.875 19.225 9.767 20 12 20z", fill: "#003", fillOpacity: 0.8 })));
16
+ };
17
+ export default SvgInfo;
@@ -24,6 +24,7 @@ export { default as Filter } from './Filter';
24
24
  export { default as Hyperlink } from './Hyperlink';
25
25
  export { default as Ignored } from './Ignored';
26
26
  export { default as IgnoredOutlined } from './IgnoredOutlined';
27
+ export { default as Info } from './Info';
27
28
  export { default as LogIn } from './LogIn';
28
29
  export { default as LogOut } from './LogOut';
29
30
  export { default as Merge } from './Merge';
@@ -24,6 +24,7 @@ export { default as Filter } from './Filter';
24
24
  export { default as Hyperlink } from './Hyperlink';
25
25
  export { default as Ignored } from './Ignored';
26
26
  export { default as IgnoredOutlined } from './IgnoredOutlined';
27
+ export { default as Info } from './Info';
27
28
  export { default as LogIn } from './LogIn';
28
29
  export { default as LogOut } from './LogOut';
29
30
  export { default as Merge } from './Merge';
package/esm/index.d.ts CHANGED
@@ -37,6 +37,7 @@ export { ExpandedValueTooltip } from './ExpandedValueTooltip';
37
37
  export { FacetViewHeader } from './FacetViewHeader';
38
38
  export { FilterButton } from './FilterButton';
39
39
  export { ImageAttributesLineEditor as EditableImageAttributesLine } from './ImageAttributesLineEditor';
40
+ export { InfoIcon } from './InfoIcon';
40
41
  export { InlineAttributesPager } from './InlineAttributesPager';
41
42
  export { InlineImageAttribute } from './InlineImageAttribute';
42
43
  export { InlineNestedAttribute } from './InlineNestedAttribute';
@@ -175,6 +176,7 @@ export { ReltioMap } from './ReltioMap';
175
176
  export { RelationEditor } from './RelationEditor';
176
177
  export { GaugeChart } from './GaugeChart';
177
178
  export { UpSetChart } from './UpSetChart';
179
+ export { DateRangeSelector } from './DateRangeSelector';
178
180
  export { withTooltip } from './HOCs/withTooltip';
179
181
  export { withAsyncMount } from './HOCs/withAsyncMount';
180
182
  export { withDragHandle } from './HOCs/withDragHandle';
package/esm/index.js CHANGED
@@ -38,6 +38,7 @@ export { ExpandedValueTooltip } from './ExpandedValueTooltip';
38
38
  export { FacetViewHeader } from './FacetViewHeader';
39
39
  export { FilterButton } from './FilterButton';
40
40
  export { ImageAttributesLineEditor as EditableImageAttributesLine } from './ImageAttributesLineEditor';
41
+ export { InfoIcon } from './InfoIcon';
41
42
  export { InlineAttributesPager } from './InlineAttributesPager';
42
43
  export { InlineImageAttribute } from './InlineImageAttribute';
43
44
  export { InlineNestedAttribute } from './InlineNestedAttribute';
@@ -176,6 +177,7 @@ export { ReltioMap } from './ReltioMap';
176
177
  export { RelationEditor } from './RelationEditor';
177
178
  export { GaugeChart } from './GaugeChart';
178
179
  export { UpSetChart } from './UpSetChart';
180
+ export { DateRangeSelector } from './DateRangeSelector';
179
181
  // HOCs
180
182
  export { withTooltip } from './HOCs/withTooltip';
181
183
  export { withAsyncMount } from './HOCs/withAsyncMount';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1955",
3
+ "version": "1.4.1957",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -8,7 +8,7 @@
8
8
  "@fluentui/react-context-selector": "^9.1.26",
9
9
  "@react-google-maps/api": "2.7.0",
10
10
  "@react-sigma/core": "3.4.0",
11
- "@reltio/mdm-sdk": "^1.4.1864",
11
+ "@reltio/mdm-sdk": "^1.4.1866",
12
12
  "@upsetjs/react": "^1.11.0",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",
@@ -1,185 +0,0 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- var react_1 = __importDefault(require("react"));
18
- var enzyme_1 = require("enzyme");
19
- var test_utils_1 = require("react-dom/test-utils");
20
- var mdm_sdk_1 = require("@reltio/mdm-sdk");
21
- var FormControlLabel_1 = __importDefault(require("@mui/material/FormControlLabel"));
22
- var RadioGroup_1 = __importDefault(require("@mui/material/RadioGroup"));
23
- var Typography_1 = __importDefault(require("@mui/material/Typography"));
24
- var CustomDateRangeEditor_1 = require("../../../../../CustomDateRangeEditor");
25
- var DateIntervalSelector_1 = require("../../../../../DateIntervalSelector");
26
- var DateRangeSelector_1 = require("./DateRangeSelector");
27
- describe('DateRangeSelector tests', function () {
28
- var value = {
29
- type: mdm_sdk_1.DateRangeTypes.WITHIN,
30
- period: [4, 'month']
31
- };
32
- var defaultProps = {
33
- value: value,
34
- onChange: jest.fn()
35
- };
36
- afterEach(function () {
37
- jest.clearAllMocks();
38
- });
39
- it('should render correct default state', function () {
40
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps)));
41
- expect(wrapper.find(Typography_1.default).filterWhere(function (component) { return component.text() === 'Date'; }).length).toBe(1);
42
- var radioGroup = wrapper.find(RadioGroup_1.default);
43
- expect(radioGroup.length).toBe(1);
44
- expect(radioGroup.prop('value')).toBe(defaultProps.value.type);
45
- var withinOption = wrapper.find('.dateOptionWithin');
46
- var agoOption = wrapper.find('.dateOptionAgo');
47
- var betweenOption = wrapper.find('.dateOption');
48
- expect(withinOption.length).toBe(1);
49
- expect(withinOption.find(FormControlLabel_1.default).prop('value')).toBe(mdm_sdk_1.DateRangeTypes.WITHIN);
50
- expect(agoOption.length).toBe(1);
51
- expect(agoOption.find(FormControlLabel_1.default).prop('value')).toBe(mdm_sdk_1.DateRangeTypes.AGO);
52
- expect(betweenOption.length).toBe(1);
53
- expect(betweenOption.find(FormControlLabel_1.default).prop('value')).toBe(mdm_sdk_1.DateRangeTypes.BETWEEN);
54
- });
55
- it('should call props.onChange when type is changed to ago', function () {
56
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps)));
57
- var radioGroup = wrapper.find(RadioGroup_1.default);
58
- (0, test_utils_1.act)(function () {
59
- var _a;
60
- var changeEvent = { target: { value: mdm_sdk_1.DateRangeTypes.AGO } };
61
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, mdm_sdk_1.DateRangeTypes.AGO);
62
- });
63
- wrapper.update();
64
- var agoValue = {
65
- type: mdm_sdk_1.DateRangeTypes.AGO,
66
- period: [null, 'minutes']
67
- };
68
- expect(defaultProps.onChange).toHaveBeenCalledWith(agoValue);
69
- });
70
- it('should call props.onChange when type is changed to between', function () {
71
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps)));
72
- var radioGroup = wrapper.find(RadioGroup_1.default);
73
- (0, test_utils_1.act)(function () {
74
- var _a;
75
- var changeEvent = { target: { value: mdm_sdk_1.DateRangeTypes.BETWEEN } };
76
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, mdm_sdk_1.DateRangeTypes.BETWEEN);
77
- });
78
- wrapper.update();
79
- var betweenValue = {
80
- type: mdm_sdk_1.DateRangeTypes.BETWEEN,
81
- period: [null, null]
82
- };
83
- expect(defaultProps.onChange).toHaveBeenCalledWith(betweenValue);
84
- });
85
- it('should call props.onChange when type is changed to between', function () {
86
- var agoValue = {
87
- type: mdm_sdk_1.DateRangeTypes.AGO,
88
- period: [4, 'month']
89
- };
90
- var props = {
91
- value: agoValue,
92
- onChange: jest.fn()
93
- };
94
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, props)));
95
- var radioGroup = wrapper.find(RadioGroup_1.default);
96
- (0, test_utils_1.act)(function () {
97
- var _a;
98
- var changeEvent = { target: { value: mdm_sdk_1.DateRangeTypes.WITHIN } };
99
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, mdm_sdk_1.DateRangeTypes.WITHIN);
100
- });
101
- wrapper.update();
102
- var withinValue = {
103
- type: mdm_sdk_1.DateRangeTypes.WITHIN,
104
- period: [null, 'minutes']
105
- };
106
- expect(props.onChange).toHaveBeenCalledWith(withinValue);
107
- });
108
- it('should call props.onChange when within period is changed', function () {
109
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps)));
110
- var withinOption = wrapper.find('.dateOptionWithin');
111
- (0, test_utils_1.act)(function () {
112
- withinOption.find(DateIntervalSelector_1.DateIntervalSelector).prop('onChange')([3, 'days']);
113
- });
114
- wrapper.update();
115
- var newValue = {
116
- type: mdm_sdk_1.DateRangeTypes.WITHIN,
117
- period: [3, 'days']
118
- };
119
- expect(defaultProps.onChange).toHaveBeenCalledWith(newValue);
120
- });
121
- it('should call props.onChange when ago period is changed', function () {
122
- var agoValue = {
123
- type: mdm_sdk_1.DateRangeTypes.AGO,
124
- period: [4, 'month']
125
- };
126
- var props = {
127
- value: agoValue,
128
- onChange: jest.fn()
129
- };
130
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, props)));
131
- var agoOption = wrapper.find('.dateOptionAgo');
132
- (0, test_utils_1.act)(function () {
133
- agoOption.find(DateIntervalSelector_1.DateIntervalSelector).prop('onChange')([17, 'days']);
134
- });
135
- wrapper.update();
136
- var newValue = {
137
- type: mdm_sdk_1.DateRangeTypes.AGO,
138
- period: [17, 'days']
139
- };
140
- expect(props.onChange).toHaveBeenCalledWith(newValue);
141
- });
142
- it('should call props.onChange when between period is changed', function () {
143
- var betweenValue = {
144
- type: mdm_sdk_1.DateRangeTypes.BETWEEN,
145
- period: [new Date(123), new Date(456)]
146
- };
147
- var props = {
148
- value: betweenValue,
149
- onChange: jest.fn()
150
- };
151
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, props)));
152
- var betweenOption = wrapper.find('.dateOption');
153
- (0, test_utils_1.act)(function () {
154
- betweenOption.find(CustomDateRangeEditor_1.CustomDateRangeEditor).prop('onChange')([new Date(234), new Date(567)]);
155
- });
156
- wrapper.update();
157
- var newValue = {
158
- type: mdm_sdk_1.DateRangeTypes.BETWEEN,
159
- period: [new Date(234), new Date(567)]
160
- };
161
- expect(props.onChange).toHaveBeenCalledWith(newValue);
162
- });
163
- it('should render correctly if value is null', function () {
164
- var wrapper = (0, enzyme_1.shallow)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps, { value: null })));
165
- expect(wrapper.find(RadioGroup_1.default).prop('value')).toBe(null);
166
- expect(wrapper.find('.dateOptionWithin').find(DateIntervalSelector_1.DateIntervalSelector).prop('interval')).toEqual([
167
- null,
168
- 'minutes'
169
- ]);
170
- expect(wrapper.find('.dateOptionAgo').find(DateIntervalSelector_1.DateIntervalSelector).prop('interval')).toEqual([null, 'minutes']);
171
- expect(wrapper.find('.dateOption').find(CustomDateRangeEditor_1.CustomDateRangeEditor).prop('values')).toEqual([null, null]);
172
- });
173
- it('should apply null value from props correctly', function () {
174
- var wrapper = (0, enzyme_1.mount)(react_1.default.createElement(DateRangeSelector_1.DateRangeSelector, __assign({}, defaultProps)));
175
- wrapper.setProps({ value: null });
176
- wrapper.update();
177
- expect(wrapper.find(RadioGroup_1.default).prop('value')).toBe(null);
178
- expect(wrapper.find('.dateOptionWithin').find(DateIntervalSelector_1.DateIntervalSelector).prop('interval')).toEqual([
179
- null,
180
- 'minutes'
181
- ]);
182
- expect(wrapper.find('.dateOptionAgo').find(DateIntervalSelector_1.DateIntervalSelector).prop('interval')).toEqual([null, 'minutes']);
183
- expect(wrapper.find('.dateOption').find(CustomDateRangeEditor_1.CustomDateRangeEditor).prop('values')).toEqual([null, null]);
184
- });
185
- });
@@ -1,180 +0,0 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- import React from 'react';
13
- import { mount, shallow } from 'enzyme';
14
- import { act } from 'react-dom/test-utils';
15
- import { DateRangeTypes } from '@reltio/mdm-sdk';
16
- import FormControlLabel from '@mui/material/FormControlLabel';
17
- import RadioGroup from '@mui/material/RadioGroup';
18
- import Typography from '@mui/material/Typography';
19
- import { CustomDateRangeEditor } from '../../../../../CustomDateRangeEditor';
20
- import { DateIntervalSelector } from '../../../../../DateIntervalSelector';
21
- import { DateRangeSelector } from './DateRangeSelector';
22
- describe('DateRangeSelector tests', function () {
23
- var value = {
24
- type: DateRangeTypes.WITHIN,
25
- period: [4, 'month']
26
- };
27
- var defaultProps = {
28
- value: value,
29
- onChange: jest.fn()
30
- };
31
- afterEach(function () {
32
- jest.clearAllMocks();
33
- });
34
- it('should render correct default state', function () {
35
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, defaultProps)));
36
- expect(wrapper.find(Typography).filterWhere(function (component) { return component.text() === 'Date'; }).length).toBe(1);
37
- var radioGroup = wrapper.find(RadioGroup);
38
- expect(radioGroup.length).toBe(1);
39
- expect(radioGroup.prop('value')).toBe(defaultProps.value.type);
40
- var withinOption = wrapper.find('.dateOptionWithin');
41
- var agoOption = wrapper.find('.dateOptionAgo');
42
- var betweenOption = wrapper.find('.dateOption');
43
- expect(withinOption.length).toBe(1);
44
- expect(withinOption.find(FormControlLabel).prop('value')).toBe(DateRangeTypes.WITHIN);
45
- expect(agoOption.length).toBe(1);
46
- expect(agoOption.find(FormControlLabel).prop('value')).toBe(DateRangeTypes.AGO);
47
- expect(betweenOption.length).toBe(1);
48
- expect(betweenOption.find(FormControlLabel).prop('value')).toBe(DateRangeTypes.BETWEEN);
49
- });
50
- it('should call props.onChange when type is changed to ago', function () {
51
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, defaultProps)));
52
- var radioGroup = wrapper.find(RadioGroup);
53
- act(function () {
54
- var _a;
55
- var changeEvent = { target: { value: DateRangeTypes.AGO } };
56
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, DateRangeTypes.AGO);
57
- });
58
- wrapper.update();
59
- var agoValue = {
60
- type: DateRangeTypes.AGO,
61
- period: [null, 'minutes']
62
- };
63
- expect(defaultProps.onChange).toHaveBeenCalledWith(agoValue);
64
- });
65
- it('should call props.onChange when type is changed to between', function () {
66
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, defaultProps)));
67
- var radioGroup = wrapper.find(RadioGroup);
68
- act(function () {
69
- var _a;
70
- var changeEvent = { target: { value: DateRangeTypes.BETWEEN } };
71
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, DateRangeTypes.BETWEEN);
72
- });
73
- wrapper.update();
74
- var betweenValue = {
75
- type: DateRangeTypes.BETWEEN,
76
- period: [null, null]
77
- };
78
- expect(defaultProps.onChange).toHaveBeenCalledWith(betweenValue);
79
- });
80
- it('should call props.onChange when type is changed to between', function () {
81
- var agoValue = {
82
- type: DateRangeTypes.AGO,
83
- period: [4, 'month']
84
- };
85
- var props = {
86
- value: agoValue,
87
- onChange: jest.fn()
88
- };
89
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, props)));
90
- var radioGroup = wrapper.find(RadioGroup);
91
- act(function () {
92
- var _a;
93
- var changeEvent = { target: { value: DateRangeTypes.WITHIN } };
94
- (_a = radioGroup.prop('onChange')) === null || _a === void 0 ? void 0 : _a(changeEvent, DateRangeTypes.WITHIN);
95
- });
96
- wrapper.update();
97
- var withinValue = {
98
- type: DateRangeTypes.WITHIN,
99
- period: [null, 'minutes']
100
- };
101
- expect(props.onChange).toHaveBeenCalledWith(withinValue);
102
- });
103
- it('should call props.onChange when within period is changed', function () {
104
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, defaultProps)));
105
- var withinOption = wrapper.find('.dateOptionWithin');
106
- act(function () {
107
- withinOption.find(DateIntervalSelector).prop('onChange')([3, 'days']);
108
- });
109
- wrapper.update();
110
- var newValue = {
111
- type: DateRangeTypes.WITHIN,
112
- period: [3, 'days']
113
- };
114
- expect(defaultProps.onChange).toHaveBeenCalledWith(newValue);
115
- });
116
- it('should call props.onChange when ago period is changed', function () {
117
- var agoValue = {
118
- type: DateRangeTypes.AGO,
119
- period: [4, 'month']
120
- };
121
- var props = {
122
- value: agoValue,
123
- onChange: jest.fn()
124
- };
125
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, props)));
126
- var agoOption = wrapper.find('.dateOptionAgo');
127
- act(function () {
128
- agoOption.find(DateIntervalSelector).prop('onChange')([17, 'days']);
129
- });
130
- wrapper.update();
131
- var newValue = {
132
- type: DateRangeTypes.AGO,
133
- period: [17, 'days']
134
- };
135
- expect(props.onChange).toHaveBeenCalledWith(newValue);
136
- });
137
- it('should call props.onChange when between period is changed', function () {
138
- var betweenValue = {
139
- type: DateRangeTypes.BETWEEN,
140
- period: [new Date(123), new Date(456)]
141
- };
142
- var props = {
143
- value: betweenValue,
144
- onChange: jest.fn()
145
- };
146
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, props)));
147
- var betweenOption = wrapper.find('.dateOption');
148
- act(function () {
149
- betweenOption.find(CustomDateRangeEditor).prop('onChange')([new Date(234), new Date(567)]);
150
- });
151
- wrapper.update();
152
- var newValue = {
153
- type: DateRangeTypes.BETWEEN,
154
- period: [new Date(234), new Date(567)]
155
- };
156
- expect(props.onChange).toHaveBeenCalledWith(newValue);
157
- });
158
- it('should render correctly if value is null', function () {
159
- var wrapper = shallow(React.createElement(DateRangeSelector, __assign({}, defaultProps, { value: null })));
160
- expect(wrapper.find(RadioGroup).prop('value')).toBe(null);
161
- expect(wrapper.find('.dateOptionWithin').find(DateIntervalSelector).prop('interval')).toEqual([
162
- null,
163
- 'minutes'
164
- ]);
165
- expect(wrapper.find('.dateOptionAgo').find(DateIntervalSelector).prop('interval')).toEqual([null, 'minutes']);
166
- expect(wrapper.find('.dateOption').find(CustomDateRangeEditor).prop('values')).toEqual([null, null]);
167
- });
168
- it('should apply null value from props correctly', function () {
169
- var wrapper = mount(React.createElement(DateRangeSelector, __assign({}, defaultProps)));
170
- wrapper.setProps({ value: null });
171
- wrapper.update();
172
- expect(wrapper.find(RadioGroup).prop('value')).toBe(null);
173
- expect(wrapper.find('.dateOptionWithin').find(DateIntervalSelector).prop('interval')).toEqual([
174
- null,
175
- 'minutes'
176
- ]);
177
- expect(wrapper.find('.dateOptionAgo').find(DateIntervalSelector).prop('interval')).toEqual([null, 'minutes']);
178
- expect(wrapper.find('.dateOption').find(CustomDateRangeEditor).prop('values')).toEqual([null, null]);
179
- });
180
- });