@transferwise/components 0.0.0-experimental-fa3aa98 → 0.0.0-experimental-f4a328f
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/build/Calendar/Calendar.js +16 -94
- package/build/Calendar/Calendar.js.map +1 -1
- package/build/Calendar/Calendar.messages.js +0 -12
- package/build/Calendar/Calendar.messages.js.map +1 -1
- package/build/Calendar/Calendar.messages.mjs +0 -12
- package/build/Calendar/Calendar.messages.mjs.map +1 -1
- package/build/Calendar/Calendar.mjs +17 -95
- package/build/Calendar/Calendar.mjs.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.js +1 -5
- package/build/Calendar/DateHeader/DateHeader.js.map +1 -1
- package/build/Calendar/DateHeader/DateHeader.mjs +1 -5
- package/build/Calendar/DateHeader/DateHeader.mjs.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.js +0 -14
- package/build/Calendar/DayCalendar/DayCalendar.js.map +1 -1
- package/build/Calendar/DayCalendar/DayCalendar.mjs +0 -14
- package/build/Calendar/DayCalendar/DayCalendar.mjs.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js +19 -53
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.js.map +1 -1
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs +19 -53
- package/build/Calendar/DayCalendar/Table/DayCalendarTable.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.js +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.js.map +1 -1
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs +0 -6
- package/build/Calendar/MonthCalendar/MonthCalendar.mjs.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.js.map +1 -1
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs +3 -8
- package/build/Calendar/MonthCalendar/Table/MonthCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.js.map +1 -1
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs +3 -8
- package/build/Calendar/YearCalendar/Table/YearCalendarTable.mjs.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.js +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.js.map +1 -1
- package/build/Calendar/YearCalendar/YearCalendar.mjs +0 -7
- package/build/Calendar/YearCalendar/YearCalendar.mjs.map +1 -1
- package/build/Calendar/{TableLink → tableLink}/TableLink.js +11 -26
- package/build/Calendar/tableLink/TableLink.js.map +1 -0
- package/build/Calendar/{TableLink → tableLink}/TableLink.mjs +11 -26
- package/build/Calendar/tableLink/TableLink.mjs.map +1 -0
- package/build/DateLookup/DateLookup.js +9 -20
- package/build/DateLookup/DateLookup.js.map +1 -1
- package/build/DateLookup/DateLookup.mjs +9 -20
- package/build/DateLookup/DateLookup.mjs.map +1 -1
- package/build/Markup/Markup.js +137 -0
- package/build/Markup/Markup.js.map +1 -0
- package/build/Markup/Markup.mjs +132 -0
- package/build/Markup/Markup.mjs.map +1 -0
- package/build/Markup/constants.js +36 -0
- package/build/Markup/constants.js.map +1 -0
- package/build/Markup/constants.mjs +29 -0
- package/build/Markup/constants.mjs.map +1 -0
- package/build/Markup/utils/parseMarkup.js +236 -0
- package/build/Markup/utils/parseMarkup.js.map +1 -0
- package/build/Markup/utils/parseMarkup.mjs +231 -0
- package/build/Markup/utils/parseMarkup.mjs.map +1 -0
- package/build/Markup/utils/sanitise.js +114 -0
- package/build/Markup/utils/sanitise.js.map +1 -0
- package/build/Markup/utils/sanitise.mjs +111 -0
- package/build/Markup/utils/sanitise.mjs.map +1 -0
- package/build/i18n/en.json +0 -4
- package/build/i18n/en.json.js +0 -4
- package/build/i18n/en.json.js.map +1 -1
- package/build/i18n/en.json.mjs +0 -4
- package/build/i18n/en.json.mjs.map +1 -1
- package/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/build/index.mjs +2 -1
- package/build/index.mjs.map +1 -1
- package/build/main.css +78 -123
- package/build/styles/Calendar/Calendar.css +37 -112
- package/build/styles/Markup/Markup.css +28 -0
- package/build/styles/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
- package/build/styles/main.css +78 -123
- package/build/types/Body/Body.d.ts +2 -2
- package/build/types/Calendar/Calendar.d.ts +3 -16
- package/build/types/Calendar/Calendar.d.ts.map +1 -1
- package/build/types/Calendar/Calendar.messages.d.ts +0 -20
- package/build/types/Calendar/Calendar.messages.d.ts.map +1 -1
- package/build/types/Calendar/DateHeader/DateHeader.d.ts +0 -2
- package/build/types/Calendar/DateHeader/DateHeader.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts +1 -5
- package/build/types/Calendar/DayCalendar/DayCalendar.d.ts.map +1 -1
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts +0 -4
- package/build/types/Calendar/DayCalendar/Table/DayCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts +0 -1
- package/build/types/Calendar/MonthCalendar/MonthCalendar.d.ts.map +1 -1
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts +1 -2
- package/build/types/Calendar/MonthCalendar/Table/MonthCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts +1 -2
- package/build/types/Calendar/YearCalendar/Table/YearCalendarTable.d.ts.map +1 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts +0 -1
- package/build/types/Calendar/YearCalendar/YearCalendar.d.ts.map +1 -1
- package/build/types/Calendar/index.d.ts +0 -1
- package/build/types/Calendar/index.d.ts.map +1 -1
- package/build/types/Calendar/{TableLink → tableLink}/TableLink.d.ts +1 -3
- package/build/types/Calendar/tableLink/TableLink.d.ts.map +1 -0
- package/build/types/Calendar/tableLink/index.d.ts.map +1 -0
- package/build/types/DateLookup/DateLookup.d.ts +5 -24
- package/build/types/DateLookup/DateLookup.d.ts.map +1 -1
- package/build/types/DateLookup/index.d.ts +0 -1
- package/build/types/DateLookup/index.d.ts.map +1 -1
- package/build/types/IconButton/IconButton.d.ts +1 -1
- package/build/types/Markup/Markup.d.ts +18 -0
- package/build/types/Markup/Markup.d.ts.map +1 -0
- package/build/types/Markup/Markup.types.d.ts +77 -0
- package/build/types/Markup/Markup.types.d.ts.map +1 -0
- package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts +12 -0
- package/build/types/Markup/_stories/Vulnerability/Vulnerability.d.ts.map +1 -0
- package/build/types/Markup/constants.d.ts +20 -0
- package/build/types/Markup/constants.d.ts.map +1 -0
- package/build/types/Markup/index.d.ts +3 -0
- package/build/types/Markup/index.d.ts.map +1 -0
- package/build/types/Markup/utils/parseMarkup.d.ts +8 -0
- package/build/types/Markup/utils/parseMarkup.d.ts.map +1 -0
- package/build/types/Markup/utils/sanitise.d.ts +4 -0
- package/build/types/Markup/utils/sanitise.d.ts.map +1 -0
- package/build/types/Title/Title.d.ts +2 -2
- package/build/types/Upload/Steps/UploadImageStep/UploadImageStep.d.ts +1 -1
- package/build/types/UploadInput/UploadItem/UploadItemLink.d.ts +1 -1
- package/build/types/common/DateUtils/index.d.ts +0 -2
- package/build/types/common/DateUtils/index.d.ts.map +1 -1
- package/build/types/index.d.ts +4 -3
- package/build/types/index.d.ts.map +1 -1
- package/build/types/test-utils/index.d.ts +0 -8
- package/build/types/test-utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/Calendar/Calendar.css +37 -112
- package/src/Calendar/Calendar.less +35 -5
- package/src/Calendar/Calendar.messages.ts +0 -21
- package/src/Calendar/Calendar.test.tsx +27 -288
- package/src/Calendar/Calendar.tsx +19 -136
- package/src/Calendar/DateHeader/DateHeader.tsx +0 -6
- package/src/Calendar/DayCalendar/DayCalendar.tsx +1 -33
- package/src/Calendar/DayCalendar/Table/DayCalendarTable.tsx +28 -62
- package/src/Calendar/MonthCalendar/MonthCalendar.tsx +0 -8
- package/src/Calendar/MonthCalendar/Table/MonthCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/Table/YearCalendarTable.tsx +3 -15
- package/src/Calendar/YearCalendar/YearCalendar.tsx +0 -9
- package/src/Calendar/_stories/Calendar.story.tsx +4 -138
- package/src/Calendar/index.ts +0 -7
- package/src/Calendar/{TableLink → tableLink}/TableLink.tsx +14 -29
- package/src/DateLookup/DateLookup.test.tsx +37 -34
- package/src/DateLookup/DateLookup.tsx +13 -37
- package/src/DateLookup/_stories/DateLookup.story.tsx +2 -124
- package/src/DateLookup/index.ts +0 -6
- package/src/Markup/Markup.css +28 -0
- package/src/Markup/Markup.injection.test.tsx +163 -0
- package/src/Markup/Markup.less +29 -0
- package/src/Markup/Markup.test.tsx +463 -0
- package/src/Markup/Markup.tsx +169 -0
- package/src/Markup/Markup.types.ts +62 -0
- package/src/Markup/_stories/Markup.docs.mdx +75 -0
- package/src/Markup/_stories/Markup.security.docs.mdx +343 -0
- package/src/Markup/_stories/Markup.story.tsx +266 -0
- package/src/Markup/_stories/Vulnerability/Vulnerability.css +69 -0
- package/src/Markup/_stories/Vulnerability/Vulnerability.tsx +30 -0
- package/src/Markup/constants.ts +41 -0
- package/src/Markup/index.ts +2 -0
- package/src/Markup/utils/parseMarkup.test.ts +706 -0
- package/src/Markup/utils/parseMarkup.ts +234 -0
- package/src/Markup/utils/sanitise.test.ts +497 -0
- package/src/Markup/utils/sanitise.ts +133 -0
- package/src/common/DateUtils/index.ts +0 -2
- package/src/i18n/en.json +0 -4
- package/src/index.ts +4 -3
- package/src/main.css +78 -123
- package/src/main.less +1 -0
- package/build/Calendar/TableLink/TableLink.js.map +0 -1
- package/build/Calendar/TableLink/TableLink.mjs.map +0 -1
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js +0 -33
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.js.map +0 -1
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs +0 -31
- package/build/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.mjs.map +0 -1
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js +0 -40
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.js.map +0 -1
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs +0 -38
- package/build/common/DateUtils/isDateDisabled/isDateDisabled.mjs.map +0 -1
- package/build/styles/Calendar/TableLink/TableLink.css +0 -115
- package/build/types/Calendar/Calendar.types.d.ts +0 -32
- package/build/types/Calendar/Calendar.types.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/TableLink.d.ts.map +0 -1
- package/build/types/Calendar/TableLink/index.d.ts.map +0 -1
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts +0 -3
- package/build/types/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.d.ts.map +0 -1
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts +0 -3
- package/build/types/common/DateUtils/isDateDisabled/isDateDisabled.d.ts.map +0 -1
- package/src/Calendar/Calendar.disabledDates.test.tsx +0 -518
- package/src/Calendar/Calendar.types.ts +0 -35
- package/src/Calendar/TableLink/TableLink.css +0 -115
- package/src/Calendar/TableLink/TableLink.less +0 -68
- package/src/Calendar/_stories/Calendar.accessibility.docs.mdx +0 -118
- package/src/Calendar/_stories/Calendar.test.story.tsx +0 -74
- package/src/DateLookup/DateLookup.disabledDates.test.tsx +0 -293
- package/src/DateLookup/_stories/DateLookup.accessibility.docs.mdx +0 -108
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.test.ts +0 -98
- package/src/common/DateUtils/hasDisabledDatesInMonth/hasDisabledDatesInMonth.ts +0 -45
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.test.ts +0 -169
- package/src/common/DateUtils/isDateDisabled/isDateDisabled.ts +0 -59
- /package/build/types/Calendar/{TableLink → tableLink}/index.d.ts +0 -0
- /package/src/Calendar/{TableLink → tableLink}/index.ts +0 -0
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth';
|
|
2
|
-
import type { DisabledRules } from '../../../Calendar/Calendar.types';
|
|
3
|
-
|
|
4
|
-
describe('hasDisabledDatesInMonth', () => {
|
|
5
|
-
describe('weekdays', () => {
|
|
6
|
-
it('returns true when weekday rules exist (every month has all weekdays)', () => {
|
|
7
|
-
const rules: DisabledRules = { weekdays: ['sat', 'sun'], reason: 'Closed' };
|
|
8
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
it('returns true for any month when weekday rules exist', () => {
|
|
12
|
-
const rules: DisabledRules = { weekdays: ['mon'], reason: 'Closed' };
|
|
13
|
-
expect(hasDisabledDatesInMonth(0, 2024, rules)).toBe(true);
|
|
14
|
-
expect(hasDisabledDatesInMonth(11, 2024, rules)).toBe(true);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it('returns false when weekdays array is empty', () => {
|
|
18
|
-
const rules: DisabledRules = { weekdays: [], reason: 'None' };
|
|
19
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false);
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('specific dates', () => {
|
|
24
|
-
const rules: DisabledRules = {
|
|
25
|
-
dates: [new Date(2024, 6, 11), new Date(2024, 6, 25), new Date(2025, 0, 1)],
|
|
26
|
-
reason: 'Bank holidays',
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
it('returns true when month contains a disabled date', () => {
|
|
30
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('returns false when month has no disabled dates', () => {
|
|
34
|
-
expect(hasDisabledDatesInMonth(5, 2024, rules)).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('returns true for another year with disabled date', () => {
|
|
38
|
-
expect(hasDisabledDatesInMonth(0, 2025, rules)).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
describe('ranges', () => {
|
|
43
|
-
const rules: DisabledRules = {
|
|
44
|
-
ranges: [{ start: new Date(2024, 2, 29), end: new Date(2024, 3, 3) }],
|
|
45
|
-
reason: 'Maintenance',
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
it('returns true when range starts in the month', () => {
|
|
49
|
-
expect(hasDisabledDatesInMonth(2, 2024, rules)).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('returns true when range ends in the month', () => {
|
|
53
|
-
expect(hasDisabledDatesInMonth(3, 2024, rules)).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('returns true when range spans the entire month', () => {
|
|
57
|
-
const spanRules: DisabledRules = {
|
|
58
|
-
ranges: [{ start: new Date(2024, 0, 1), end: new Date(2024, 11, 31) }],
|
|
59
|
-
reason: 'Year-long',
|
|
60
|
-
};
|
|
61
|
-
expect(hasDisabledDatesInMonth(6, 2024, spanRules)).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('returns false when range does not overlap the month', () => {
|
|
65
|
-
expect(hasDisabledDatesInMonth(4, 2024, rules)).toBe(false);
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
describe('min/max constraints', () => {
|
|
70
|
-
it('returns false when all disabled dates in month are outside min/max', () => {
|
|
71
|
-
const rules: DisabledRules = {
|
|
72
|
-
dates: [new Date(2024, 6, 1), new Date(2024, 6, 2)],
|
|
73
|
-
reason: 'Early',
|
|
74
|
-
};
|
|
75
|
-
const min = new Date(2024, 6, 10);
|
|
76
|
-
const max = new Date(2024, 6, 31);
|
|
77
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('returns true when weekdays exist regardless of min/max', () => {
|
|
81
|
-
const rules: DisabledRules = { weekdays: ['sat'], reason: 'Closed' };
|
|
82
|
-
const min = new Date(2024, 6, 10);
|
|
83
|
-
const max = new Date(2024, 6, 20);
|
|
84
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(true);
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
describe('no rules', () => {
|
|
89
|
-
it('returns false when disabledRules is undefined', () => {
|
|
90
|
-
expect(hasDisabledDatesInMonth(6, 2024, undefined)).toBe(false);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('returns false when only reason is provided', () => {
|
|
94
|
-
const rules: DisabledRules = { reason: 'Reason only' };
|
|
95
|
-
expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { DisabledRules } from '../../../Calendar/Calendar.types';
|
|
2
|
-
|
|
3
|
-
export function hasDisabledDatesInMonth(
|
|
4
|
-
month: number,
|
|
5
|
-
year: number,
|
|
6
|
-
disabledRules?: DisabledRules,
|
|
7
|
-
min?: Date | null,
|
|
8
|
-
max?: Date | null,
|
|
9
|
-
): boolean {
|
|
10
|
-
if (!disabledRules) return false;
|
|
11
|
-
|
|
12
|
-
if (disabledRules.weekdays?.length) {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const monthStart = new Date(year, month, 1);
|
|
17
|
-
const monthEnd = new Date(year, month + 1, 0);
|
|
18
|
-
|
|
19
|
-
if (disabledRules.dates?.length) {
|
|
20
|
-
const hasDateInMonth = disabledRules.dates.some((date) => {
|
|
21
|
-
if (date.getFullYear() !== year || date.getMonth() !== month) return false;
|
|
22
|
-
if (min && date < min) return false;
|
|
23
|
-
if (max && date > max) return false;
|
|
24
|
-
return true;
|
|
25
|
-
});
|
|
26
|
-
if (hasDateInMonth) return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (disabledRules.ranges?.length) {
|
|
30
|
-
const hasOverlap = disabledRules.ranges.some((range) => {
|
|
31
|
-
const rangeStart = new Date(
|
|
32
|
-
range.start.getFullYear(),
|
|
33
|
-
range.start.getMonth(),
|
|
34
|
-
range.start.getDate(),
|
|
35
|
-
);
|
|
36
|
-
const rangeEnd = new Date(range.end.getFullYear(), range.end.getMonth(), range.end.getDate());
|
|
37
|
-
if (max && rangeStart > max) return false;
|
|
38
|
-
if (min && rangeEnd < min) return false;
|
|
39
|
-
return rangeStart <= monthEnd && rangeEnd >= monthStart;
|
|
40
|
-
});
|
|
41
|
-
if (hasOverlap) return true;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
import { isDateDisabled } from './isDateDisabled';
|
|
2
|
-
import type { DisabledRules } from '../../../Calendar/Calendar.types';
|
|
3
|
-
|
|
4
|
-
describe('isDateDisabled', () => {
|
|
5
|
-
describe('when no rules provided', () => {
|
|
6
|
-
it('returns false when disabledRules is undefined', () => {
|
|
7
|
-
expect(isDateDisabled(new Date('2024-07-15'), undefined)).toBe(false);
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
it('returns false when disabledRules has only reason', () => {
|
|
11
|
-
const rules: DisabledRules = { reason: 'some reason' };
|
|
12
|
-
expect(isDateDisabled(new Date('2024-07-15'), rules)).toBe(false);
|
|
13
|
-
});
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
describe('weekdays', () => {
|
|
17
|
-
const rules: DisabledRules = {
|
|
18
|
-
weekdays: ['sat', 'sun'],
|
|
19
|
-
reason: 'Closed on weekends',
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
it('returns true for a Saturday', () => {
|
|
23
|
-
// 2024-07-13 is a Saturday
|
|
24
|
-
expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(true);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it('returns true for a Sunday', () => {
|
|
28
|
-
// 2024-07-14 is a Sunday
|
|
29
|
-
expect(isDateDisabled(new Date(2024, 6, 14), rules)).toBe(true);
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it('returns false for a Monday', () => {
|
|
33
|
-
// 2024-07-15 is a Monday
|
|
34
|
-
expect(isDateDisabled(new Date(2024, 6, 15), rules)).toBe(false);
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('returns false for a Friday', () => {
|
|
38
|
-
// 2024-07-12 is a Friday
|
|
39
|
-
expect(isDateDisabled(new Date(2024, 6, 12), rules)).toBe(false);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('handles single weekday rule', () => {
|
|
43
|
-
const singleDay: DisabledRules = { weekdays: ['wed'], reason: 'Closed' };
|
|
44
|
-
// 2024-07-17 is a Wednesday
|
|
45
|
-
expect(isDateDisabled(new Date(2024, 6, 17), singleDay)).toBe(true);
|
|
46
|
-
// 2024-07-18 is a Thursday
|
|
47
|
-
expect(isDateDisabled(new Date(2024, 6, 18), singleDay)).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
describe('specific dates', () => {
|
|
52
|
-
const rules: DisabledRules = {
|
|
53
|
-
dates: [new Date(2024, 6, 11), new Date(2025, 1, 12), new Date(2025, 4, 1)],
|
|
54
|
-
reason: 'Bank holidays',
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
it('returns true for a disabled date', () => {
|
|
58
|
-
expect(isDateDisabled(new Date(2024, 6, 11), rules)).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('returns false for a non-disabled date', () => {
|
|
62
|
-
expect(isDateDisabled(new Date(2024, 6, 12), rules)).toBe(false);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('compares date-only, ignoring time', () => {
|
|
66
|
-
const dateWithTime = new Date(2024, 6, 11, 14, 30, 0);
|
|
67
|
-
expect(isDateDisabled(dateWithTime, rules)).toBe(true);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it('handles disabled dates that have non-zero time components', () => {
|
|
71
|
-
const rulesWithTime: DisabledRules = {
|
|
72
|
-
dates: [new Date(2024, 6, 11, 23, 59, 59)],
|
|
73
|
-
reason: 'Holiday',
|
|
74
|
-
};
|
|
75
|
-
expect(isDateDisabled(new Date(2024, 6, 11), rulesWithTime)).toBe(true);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
describe('ranges', () => {
|
|
80
|
-
const rules: DisabledRules = {
|
|
81
|
-
ranges: [
|
|
82
|
-
{ start: new Date(2024, 2, 29), end: new Date(2024, 3, 3) },
|
|
83
|
-
{ start: new Date(2024, 11, 24), end: new Date(2024, 11, 26) },
|
|
84
|
-
],
|
|
85
|
-
reason: 'Scheduled maintenance',
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
it('returns true for start of range (inclusive)', () => {
|
|
89
|
-
expect(isDateDisabled(new Date(2024, 2, 29), rules)).toBe(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('returns true for end of range (inclusive)', () => {
|
|
93
|
-
expect(isDateDisabled(new Date(2024, 3, 3), rules)).toBe(true);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('returns true for date within range', () => {
|
|
97
|
-
expect(isDateDisabled(new Date(2024, 2, 31), rules)).toBe(true);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('returns false for date before range', () => {
|
|
101
|
-
expect(isDateDisabled(new Date(2024, 2, 28), rules)).toBe(false);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('returns false for date after range', () => {
|
|
105
|
-
expect(isDateDisabled(new Date(2024, 3, 4), rules)).toBe(false);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it('handles second range', () => {
|
|
109
|
-
expect(isDateDisabled(new Date(2024, 11, 25), rules)).toBe(true);
|
|
110
|
-
expect(isDateDisabled(new Date(2024, 11, 27), rules)).toBe(false);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it('correctly checks a date with non-midnight time against a range', () => {
|
|
114
|
-
const dateWithTime = new Date(2024, 2, 31, 14, 30, 0);
|
|
115
|
-
expect(isDateDisabled(dateWithTime, rules)).toBe(true);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('correctly excludes a date with non-midnight time outside a range', () => {
|
|
119
|
-
const dateWithTime = new Date(2024, 2, 28, 23, 59, 59);
|
|
120
|
-
expect(isDateDisabled(dateWithTime, rules)).toBe(false);
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe('combined rules (additive)', () => {
|
|
125
|
-
const rules: DisabledRules = {
|
|
126
|
-
weekdays: ['sat', 'sun'],
|
|
127
|
-
dates: [new Date(2024, 6, 15)], // Monday
|
|
128
|
-
ranges: [{ start: new Date(2024, 6, 22), end: new Date(2024, 6, 24) }],
|
|
129
|
-
reason: 'Multiple rules',
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
it('disables by weekday', () => {
|
|
133
|
-
// 2024-07-13 is Saturday
|
|
134
|
-
expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(true);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('disables by specific date', () => {
|
|
138
|
-
// 2024-07-15 is Monday but explicitly disabled
|
|
139
|
-
expect(isDateDisabled(new Date(2024, 6, 15), rules)).toBe(true);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it('disables by range', () => {
|
|
143
|
-
// 2024-07-23 is Tuesday but in range
|
|
144
|
-
expect(isDateDisabled(new Date(2024, 6, 23), rules)).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('allows date not matching any rule', () => {
|
|
148
|
-
// 2024-07-16 is Tuesday, not in dates or ranges
|
|
149
|
-
expect(isDateDisabled(new Date(2024, 6, 16), rules)).toBe(false);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('edge cases', () => {
|
|
154
|
-
it('handles empty weekdays array', () => {
|
|
155
|
-
const rules: DisabledRules = { weekdays: [], reason: 'Empty' };
|
|
156
|
-
expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('handles empty dates array', () => {
|
|
160
|
-
const rules: DisabledRules = { dates: [], reason: 'Empty' };
|
|
161
|
-
expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('handles empty ranges array', () => {
|
|
165
|
-
const rules: DisabledRules = { ranges: [], reason: 'Empty' };
|
|
166
|
-
expect(isDateDisabled(new Date(2024, 6, 13), rules)).toBe(false);
|
|
167
|
-
});
|
|
168
|
-
});
|
|
169
|
-
});
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type { DisabledRules, WeekDayType } from '../../../Calendar/Calendar.types';
|
|
2
|
-
|
|
3
|
-
const DAY_INDEX_TO_WEEKDAY: Record<number, WeekDayType> = {
|
|
4
|
-
0: 'sun',
|
|
5
|
-
1: 'mon',
|
|
6
|
-
2: 'tue',
|
|
7
|
-
3: 'wed',
|
|
8
|
-
4: 'thu',
|
|
9
|
-
5: 'fri',
|
|
10
|
-
6: 'sat',
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export function isDateDisabled(date: Date, disabledRules?: DisabledRules): boolean {
|
|
14
|
-
if (!disabledRules) return false;
|
|
15
|
-
|
|
16
|
-
if (disabledRules.weekdays?.length) {
|
|
17
|
-
const weekday = DAY_INDEX_TO_WEEKDAY[date.getDay()];
|
|
18
|
-
if (disabledRules.weekdays.includes(weekday)) return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (disabledRules.dates?.length) {
|
|
22
|
-
const year = date.getFullYear();
|
|
23
|
-
const month = date.getMonth();
|
|
24
|
-
const day = date.getDate();
|
|
25
|
-
if (
|
|
26
|
-
disabledRules.dates.some(
|
|
27
|
-
(disabledDate) =>
|
|
28
|
-
disabledDate.getFullYear() === year &&
|
|
29
|
-
disabledDate.getMonth() === month &&
|
|
30
|
-
disabledDate.getDate() === day,
|
|
31
|
-
)
|
|
32
|
-
) {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (disabledRules.ranges?.length) {
|
|
38
|
-
const dateStart = date.getTime();
|
|
39
|
-
if (
|
|
40
|
-
disabledRules.ranges.some((range) => {
|
|
41
|
-
const rangeStart = new Date(
|
|
42
|
-
range.start.getFullYear(),
|
|
43
|
-
range.start.getMonth(),
|
|
44
|
-
range.start.getDate(),
|
|
45
|
-
).getTime();
|
|
46
|
-
const rangeEnd = new Date(
|
|
47
|
-
range.end.getFullYear(),
|
|
48
|
-
range.end.getMonth(),
|
|
49
|
-
range.end.getDate(),
|
|
50
|
-
).getTime();
|
|
51
|
-
return dateStart >= rangeStart && dateStart <= rangeEnd;
|
|
52
|
-
})
|
|
53
|
-
) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
File without changes
|
|
File without changes
|