Skip to content

Commit

Permalink
fix(card fields): correctly set isValid state for month and year
Browse files Browse the repository at this point in the history
  • Loading branch information
aprendendofelipe committed Dec 19, 2024
1 parent 0b43c7d commit 107887b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/forms/src/fields/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const month = {
{ value: '11', label: '11' },
{ value: '12', label: '12' },
],
onValidChange: ({ month, updateFields }) => updateFields({ state: { isValid: !!month } }),
onValidChange: ({ month, updateFields }) => updateFields({ month: { isValid: !!month } }),
validateOnBlurAndSubmit: (month) => (month === '' ? 'Selecione.' : null),
};

Expand All @@ -53,7 +53,7 @@ export const year = {
label: 'Ano',
autoComplete: 'cc-exp-year',
options: getYears(),
onValidChange: ({ year, updateFields }) => updateFields({ state: { isValid: !!year } }),
onValidChange: ({ year, updateFields }) => updateFields({ year: { isValid: !!year } }),
validateOnBlurAndSubmit: (year) => (year === '' ? 'Selecione.' : null),
};

Expand Down
8 changes: 4 additions & 4 deletions packages/forms/src/fields/card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ describe('forms', () => {
it('should call updateFields with isValid true if month is not empty', () => {
const updateFields = vi.fn();
month.onValidChange({ month: '01', updateFields });
expect(updateFields).toHaveBeenCalledWith({ state: { isValid: true } });
expect(updateFields).toHaveBeenCalledWith({ month: { isValid: true } });
});

it('should call updateFields with isValid false if month is empty', () => {
const updateFields = vi.fn();
month.onValidChange({ month: '', updateFields });
expect(updateFields).toHaveBeenCalledWith({ state: { isValid: false } });
expect(updateFields).toHaveBeenCalledWith({ month: { isValid: false } });
});
});

Expand Down Expand Up @@ -152,13 +152,13 @@ describe('forms', () => {
it('should call updateFields with isValid true if year is not empty', () => {
const updateFields = vi.fn();
year.onValidChange({ year: '99', updateFields });
expect(updateFields).toHaveBeenCalledWith({ state: { isValid: true } });
expect(updateFields).toHaveBeenCalledWith({ year: { isValid: true } });
});

it('should call updateFields with isValid false if year is empty', () => {
const updateFields = vi.fn();
year.onValidChange({ year: '', updateFields });
expect(updateFields).toHaveBeenCalledWith({ state: { isValid: false } });
expect(updateFields).toHaveBeenCalledWith({ year: { isValid: false } });
});
});

Expand Down

0 comments on commit 107887b

Please sign in to comment.