@farm-investimentos/front-mfe-components 15.4.0 → 15.4.2

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": "@farm-investimentos/front-mfe-components",
3
- "version": "15.4.0",
3
+ "version": "15.4.2",
4
4
  "author": "farm investimentos",
5
5
  "private": false,
6
6
  "main": "./dist/front-mfe-components.common.js",
@@ -110,7 +110,7 @@ export default defineComponent({
110
110
  */
111
111
  allowedDates: {
112
112
  type: Function,
113
- default: () => {},
113
+ default: () => true,
114
114
  },
115
115
  /**
116
116
  * Required field (inside form)
@@ -73,6 +73,23 @@ describe('DatePicker component', () => {
73
73
  });
74
74
  expect(component.isDateFieldDisabled).toBe(false);
75
75
  });
76
+
77
+ it('should allow all dates', async () => {
78
+ await wrapper.setProps({
79
+ allowedDates: () => true
80
+ });
81
+ expect(component.checkIsInAllowedDates('2023-07-03')).toBe(true);
82
+ expect(component.checkIsInAllowedDates('2099-12-20')).toBe(true);
83
+ expect(component.checkIsInAllowedDates('1985-01-23')).toBe(true);
84
+ });
85
+
86
+ it('should allow only dates in year 2077', async () => {
87
+ await wrapper.setProps({
88
+ allowedDates: (value) => new Date(value).getFullYear() === 2077
89
+ });
90
+ expect(component.checkIsInAllowedDates('2077-05-03')).toBe(true);
91
+ expect(component.checkIsInAllowedDates('2023-05-03')).toBe('Data inválida');
92
+ });
76
93
  });
77
94
 
78
95
  describe('methods', () => {
@@ -152,6 +152,19 @@ export default defineComponent({
152
152
  this.menuField = false;
153
153
  this.$refs.contextmenu.inputValue = false;
154
154
  },
155
+ sortDates(dates) {
156
+ if(dates?.length !== 2) {
157
+ return dates;
158
+ }
159
+ const firstDate = new Date(dates[0]);
160
+ const secondDate = new Date(dates[1]);
161
+
162
+ if (firstDate.getTime() < secondDate.getTime()) {
163
+ return [dates[0], dates[1]];
164
+ }
165
+
166
+ return [dates[1], dates[0]];
167
+ },
155
168
  formatDatePickerHeader,
156
169
  },
157
170
  computed: {
@@ -160,6 +173,7 @@ export default defineComponent({
160
173
  return this.value;
161
174
  },
162
175
  set(val) {
176
+ val = this.sortDates(val);
163
177
  this.$emit('input', val);
164
178
  },
165
179
  },