@farm-investimentos/front-mfe-components 15.10.1 → 15.10.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/dist/front-mfe-components.common.js +99 -101
- package/dist/front-mfe-components.common.js.map +1 -1
- package/dist/front-mfe-components.css +1 -1
- package/dist/front-mfe-components.umd.js +99 -101
- package/dist/front-mfe-components.umd.js.map +1 -1
- package/dist/front-mfe-components.umd.min.js +1 -1
- package/dist/front-mfe-components.umd.min.js.map +1 -1
- package/package.json +1 -1
- package/src/components/RangeDatePicker/RangeDatePicker.stories.js +7 -7
- package/src/components/RangeDatePicker/RangeDatePicker.vue +7 -6
- package/src/components/RangeDatePicker/__tests__/RangeDatePicker.spec.js +45 -0
package/package.json
CHANGED
|
@@ -101,12 +101,12 @@ export const ValidacaoInputPadrao = () => ({
|
|
|
101
101
|
};
|
|
102
102
|
},
|
|
103
103
|
template: `<div style='max-width: 320px'>
|
|
104
|
-
<farm-label>Selecione uma data entre 01/01/
|
|
104
|
+
<farm-label>Selecione uma data entre 01/01/2025 e 31/12/2025</farm-label>
|
|
105
105
|
<RangeDatePicker
|
|
106
106
|
inputId="input-custom-id"
|
|
107
107
|
v-model="date"
|
|
108
|
-
min="
|
|
109
|
-
max="
|
|
108
|
+
min="2025-01-01"
|
|
109
|
+
max="2025-12-31"
|
|
110
110
|
validateInput
|
|
111
111
|
required
|
|
112
112
|
/>
|
|
@@ -121,15 +121,15 @@ export const ValidacaoInputCustomizada = () => ({
|
|
|
121
121
|
};
|
|
122
122
|
},
|
|
123
123
|
template: `<div style='max-width: 320px'>
|
|
124
|
-
<farm-label>Selecione uma data do primeiro semestre de
|
|
124
|
+
<farm-label>Selecione uma data do primeiro semestre de 2025</farm-label>
|
|
125
125
|
<RangeDatePicker
|
|
126
126
|
inputId="input-custom-id"
|
|
127
127
|
v-model="date"
|
|
128
|
-
min="
|
|
129
|
-
max="
|
|
128
|
+
min="2025-01-01"
|
|
129
|
+
max="2025-06-30"
|
|
130
130
|
validateInput
|
|
131
131
|
required
|
|
132
|
-
outOfRangeMessage="Por favor, selecione datas dentro do primeiro semestre de
|
|
132
|
+
outOfRangeMessage="Por favor, selecione datas dentro do primeiro semestre de 2025 ({min} até {max})"
|
|
133
133
|
/>
|
|
134
134
|
date: {{ date }}
|
|
135
135
|
</div>`,
|
|
@@ -164,15 +164,16 @@ export default defineComponent({
|
|
|
164
164
|
return true;
|
|
165
165
|
}
|
|
166
166
|
|
|
167
|
-
const [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
const [startDateStr, endDateStr] = value.split(' a ');
|
|
168
|
+
|
|
169
|
+
const startDate = new Date(convertDate(startDateStr));
|
|
170
|
+
const endDate = new Date(convertDate(endDateStr));
|
|
172
171
|
const minDate = new Date(this.min);
|
|
173
172
|
const maxDate = new Date(this.max);
|
|
174
173
|
|
|
175
|
-
|
|
174
|
+
const isValid = startDate.getTime() >= minDate.getTime() && endDate.getTime() <= maxDate.getTime();
|
|
175
|
+
|
|
176
|
+
if (!isValid) {
|
|
176
177
|
return this.outOfRangeMessage
|
|
177
178
|
.replace('{min}', dateDefaultFormatter(this.min))
|
|
178
179
|
.replace('{max}', dateDefaultFormatter(this.max));
|
|
@@ -104,4 +104,49 @@ describe('RangeDatePicker component', () => {
|
|
|
104
104
|
expect(component.fieldRange).toEqual('27/02/2023 a 28/02/2023');
|
|
105
105
|
});
|
|
106
106
|
});
|
|
107
|
+
|
|
108
|
+
describe('range validation', () => {
|
|
109
|
+
beforeEach(async () => {
|
|
110
|
+
await wrapper.setProps({
|
|
111
|
+
min: '2023-02-01',
|
|
112
|
+
max: '2023-02-28',
|
|
113
|
+
validateInput: true
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('should return true when date range is within min and max', () => {
|
|
118
|
+
const result = component.checkMinMax('15/02/2023 a 20/02/2023');
|
|
119
|
+
expect(result).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should return error message when start date is before min date', () => {
|
|
123
|
+
const result = component.checkMinMax('31/01/2023 a 15/02/2023');
|
|
124
|
+
expect(result).toBe('A data selecionada deve ser entre 01/02/2023 e 28/02/2023');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should return error message when end date is after max date', () => {
|
|
128
|
+
const result = component.checkMinMax('15/02/2023 a 01/03/2023');
|
|
129
|
+
expect(result).toBe('A data selecionada deve ser entre 01/02/2023 e 28/02/2023');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should return true when validateInput is false', async () => {
|
|
133
|
+
await wrapper.setProps({ validateInput: false });
|
|
134
|
+
const result = component.checkMinMax('31/01/2023 a 01/03/2023');
|
|
135
|
+
expect(result).toBe(true);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('should return true when value is empty', () => {
|
|
139
|
+
const result = component.checkMinMax('');
|
|
140
|
+
expect(result).toBe(true);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('should return true when min and max are not set', async () => {
|
|
144
|
+
await wrapper.setProps({
|
|
145
|
+
min: null,
|
|
146
|
+
max: null
|
|
147
|
+
});
|
|
148
|
+
const result = component.checkMinMax('15/02/2023 a 20/02/2023');
|
|
149
|
+
expect(result).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
107
152
|
});
|