@griddo/ax 1.68.3 → 1.68.4
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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@griddo/ax",
|
|
3
3
|
"description": "Griddo Author Experience",
|
|
4
|
-
"version": "1.68.
|
|
4
|
+
"version": "1.68.4",
|
|
5
5
|
"authors": [
|
|
6
6
|
"Álvaro Sánchez' <alvaro.sanches@secuoyas.com>",
|
|
7
7
|
"Carlos Torres <carlos.torres@secuoyas.com>",
|
|
@@ -221,5 +221,5 @@
|
|
|
221
221
|
"publishConfig": {
|
|
222
222
|
"access": "public"
|
|
223
223
|
},
|
|
224
|
-
"gitHead": "
|
|
224
|
+
"gitHead": "09ed7a46a84915d8dbf80a4221d285374550f081"
|
|
225
225
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import "@testing-library/jest-dom";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { mock } from "jest-mock-extended";
|
|
5
|
+
import { render, screen, cleanup } from "@testing-library/react";
|
|
6
|
+
|
|
7
|
+
import DateField, { IDateFieldProps } from "@ax/components/Fields/DateField";
|
|
8
|
+
import { parseTheme } from "@griddo/core";
|
|
9
|
+
import globalTheme from "@ax/themes/theme.json";
|
|
10
|
+
|
|
11
|
+
afterEach(cleanup);
|
|
12
|
+
|
|
13
|
+
const defaultProps = mock<IDateFieldProps>();
|
|
14
|
+
|
|
15
|
+
describe("DateField component rendering", () => {
|
|
16
|
+
it("should render the component", () => {
|
|
17
|
+
defaultProps.value = "values";
|
|
18
|
+
defaultProps.mandatory = true;
|
|
19
|
+
const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: any) => void>;
|
|
20
|
+
|
|
21
|
+
render(
|
|
22
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
23
|
+
<DateField {...defaultProps} />
|
|
24
|
+
</ThemeProvider>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
expect(screen.getByTestId("dateWrapper")).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should render the component receiving a date as a number", () => {
|
|
31
|
+
defaultProps.value = 112233;
|
|
32
|
+
defaultProps.mandatory = false;
|
|
33
|
+
defaultProps.futureDate = false;
|
|
34
|
+
defaultProps.pastDate = true;
|
|
35
|
+
const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: any) => void>;
|
|
36
|
+
|
|
37
|
+
render(
|
|
38
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
39
|
+
<DateField {...defaultProps} />
|
|
40
|
+
</ThemeProvider>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
expect(screen.getByTestId("dateWrapper")).toBeTruthy();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should render the component not receiving a proper date", () => {
|
|
47
|
+
defaultProps.value = undefined;
|
|
48
|
+
defaultProps.futureDate = true;
|
|
49
|
+
defaultProps.pastDate = false;
|
|
50
|
+
defaultProps.mandatory = false;
|
|
51
|
+
const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: any) => void>;
|
|
52
|
+
|
|
53
|
+
render(
|
|
54
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
55
|
+
<DateField {...defaultProps} />
|
|
56
|
+
</ThemeProvider>
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
expect(screen.getByTestId("dateWrapper")).toBeTruthy();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it("should render the component receiving a range date", () => {
|
|
63
|
+
defaultProps.value = "01/01/2022 - 10/01/2022";
|
|
64
|
+
defaultProps.mandatory = false;
|
|
65
|
+
const onChangeMock = defaultProps.onChange as jest.MockedFunction<(value: any) => void>;
|
|
66
|
+
const handleValidationMock = defaultProps.handleValidation as jest.MockedFunction<(value: string) => void>;
|
|
67
|
+
|
|
68
|
+
render(
|
|
69
|
+
<ThemeProvider theme={parseTheme(globalTheme)}>
|
|
70
|
+
<DateField {...defaultProps} />
|
|
71
|
+
</ThemeProvider>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
expect(screen.getByTestId("dateWrapper")).toBeTruthy();
|
|
75
|
+
expect(onChangeMock).toBeCalledWith("2022/01/01 - 2022/01/10");
|
|
76
|
+
expect(handleValidationMock).toBeCalled();
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import FieldGroup from "@ax/components/Fields/FieldGroup";
|
|
3
|
-
import { ThemeProvider } from "styled-components";
|
|
4
2
|
import "@testing-library/jest-dom";
|
|
3
|
+
import { ThemeProvider } from "styled-components";
|
|
4
|
+
import { render, screen, cleanup, fireEvent } from "@testing-library/react";
|
|
5
|
+
|
|
5
6
|
import { parseTheme } from "@griddo/core";
|
|
6
7
|
import globalTheme from "@ax/themes/theme.json";
|
|
7
|
-
|
|
8
|
+
|
|
9
|
+
import FieldGroup from "@ax/components/Fields/FieldGroup";
|
|
8
10
|
|
|
9
11
|
afterEach(cleanup);
|
|
10
12
|
|
|
@@ -33,9 +33,7 @@ const DateField = (props: IDateFieldProps): JSX.Element => {
|
|
|
33
33
|
const currentDate = new Date();
|
|
34
34
|
const defaultValue = mandatory ? dateToString(currentDate, "yyyy/MM/dd") : null;
|
|
35
35
|
const stringDate = value && typeof value === "number" ? dateToString(new Date(value * 1000)) : value;
|
|
36
|
-
|
|
37
36
|
const dateValue = stringDate && (isValidDate(stringDate) || isValidDateRange(stringDate)) ? stringDate : defaultValue;
|
|
38
|
-
|
|
39
37
|
const isRange = dateValue && dateValue.split(" - ").length > 1;
|
|
40
38
|
const { isOpen, toggleModal } = useModal();
|
|
41
39
|
|
|
@@ -64,8 +62,8 @@ const DateField = (props: IDateFieldProps): JSX.Element => {
|
|
|
64
62
|
registerLocale("en", en);
|
|
65
63
|
|
|
66
64
|
const handleOnChange = (dates: any) => {
|
|
67
|
-
const start = dates
|
|
68
|
-
const end = dates
|
|
65
|
+
const start = dates[0];
|
|
66
|
+
const end = dates[1];
|
|
69
67
|
|
|
70
68
|
const equalRangeDates = areEqualDates(start, end);
|
|
71
69
|
|
|
@@ -78,6 +76,7 @@ const DateField = (props: IDateFieldProps): JSX.Element => {
|
|
|
78
76
|
|
|
79
77
|
setDates(rangeDates);
|
|
80
78
|
onChange(selectedDate);
|
|
79
|
+
|
|
81
80
|
handleValidation && handleValidation(start);
|
|
82
81
|
};
|
|
83
82
|
|
|
@@ -96,7 +95,7 @@ const DateField = (props: IDateFieldProps): JSX.Element => {
|
|
|
96
95
|
);
|
|
97
96
|
|
|
98
97
|
return (
|
|
99
|
-
<S.DatePickerWrapper>
|
|
98
|
+
<S.DatePickerWrapper data-testid="dateWrapper">
|
|
100
99
|
<DatePicker
|
|
101
100
|
locale={"en"}
|
|
102
101
|
selected={start}
|
|
@@ -118,7 +117,7 @@ const DateField = (props: IDateFieldProps): JSX.Element => {
|
|
|
118
117
|
);
|
|
119
118
|
};
|
|
120
119
|
|
|
121
|
-
interface IDateFieldProps {
|
|
120
|
+
export interface IDateFieldProps {
|
|
122
121
|
value: string | any;
|
|
123
122
|
selectsRange: boolean;
|
|
124
123
|
onChange: (value: any) => void;
|
package/src/helpers/dates.tsx
CHANGED
|
@@ -8,6 +8,7 @@ const stringToDate = (value: string): Date => {
|
|
|
8
8
|
const regEx = /^[0-9]{4}[\/][0-9]{2}[\/][0-9]{2}$/g;
|
|
9
9
|
const isInversed = regEx.test(value);
|
|
10
10
|
const formatDate = isInversed ? "yyyy/MM/dd" : "dd/MM/yyyy";
|
|
11
|
+
|
|
11
12
|
return parse(value, formatDate, new Date());
|
|
12
13
|
};
|
|
13
14
|
|
|
@@ -64,9 +65,7 @@ const getHumanLastModifiedDate = (modified: Date): string => {
|
|
|
64
65
|
const oneDay = 60 * 60 * 24 * 1000;
|
|
65
66
|
const isMoreThan24Hours = now.getTime() - date.getTime() > oneDay;
|
|
66
67
|
|
|
67
|
-
return isMoreThan24Hours
|
|
68
|
-
? format(date, "d MMM HH:mm")
|
|
69
|
-
: formatDistanceToNowStrict(date, { addSuffix: true });
|
|
68
|
+
return isMoreThan24Hours ? format(date, "d MMM HH:mm") : formatDistanceToNowStrict(date, { addSuffix: true });
|
|
70
69
|
};
|
|
71
70
|
|
|
72
71
|
const getFormattedDateWithTimezone = (date: Date, formatString: string): string => {
|