From ea53323ec68da75beb5b5c152da909f9d967b9f1 Mon Sep 17 00:00:00 2001 From: guille Date: Tue, 5 Mar 2024 12:46:22 -0300 Subject: [PATCH 1/3] refactor(currency): change default props --- src/components/Currency/Currency.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/Currency/Currency.js b/src/components/Currency/Currency.js index e219d45..3b3dd9c 100644 --- a/src/components/Currency/Currency.js +++ b/src/components/Currency/Currency.js @@ -14,6 +14,7 @@ function Currency({form, field, label, ...props}) { return ( Date: Tue, 5 Mar 2024 13:30:47 -0300 Subject: [PATCH 2/3] refactor(currency): change default placeholder --- src/utils/__tests__/getQuestionProps.test.js | 4 ++-- src/utils/getQuestionProps.js | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/__tests__/getQuestionProps.test.js b/src/utils/__tests__/getQuestionProps.test.js index 3658e2d..95287af 100644 --- a/src/utils/__tests__/getQuestionProps.test.js +++ b/src/utils/__tests__/getQuestionProps.test.js @@ -379,7 +379,7 @@ describe('getQuestionProps', () => { props: { label: {text: 'question 1', number: '1', introduction: undefined}, name: 'S1.0.S1P1.answer', - placeholder: undefined, + placeholder: 'Ingrese Valor', type: 'number', disabled: true, warnings: {}, @@ -414,7 +414,7 @@ describe('getQuestionProps', () => { props: { label: {text: 'question 1', number: '1', introduction: undefined}, name: 'S1.0.S1P1.answer', - placeholder: undefined, + placeholder: 'Ingrese Valor', type: 'text', disabled: true, warnings: {}, diff --git a/src/utils/getQuestionProps.js b/src/utils/getQuestionProps.js index 5141a38..f99372f 100644 --- a/src/utils/getQuestionProps.js +++ b/src/utils/getQuestionProps.js @@ -3,6 +3,8 @@ import questionTypes from '@/constants/questionTypes'; import getNavigation from './getNavigation'; +const isNumericOrCurrency = type => [questionTypes.NUMERIC_FIELD, questionTypes.CURRENCY].includes(type); + const getQuestionProps = ({sectionIndex, section, question, values, disabled, warnings, initialValues, sections}) => { const { number, @@ -29,7 +31,7 @@ const getQuestionProps = ({sectionIndex, section, question, values, disabled, wa case questionTypes.CURRENCY: props = { label: {text: label, number, introduction}, - placeholder, + placeholder: !placeholder && isNumericOrCurrency(type) ? 'Ingrese Valor' : placeholder, name: questionName, type: [questionTypes.TEXT_FIELD, questionTypes.CURRENCY].includes(type) ? 'text' : 'number', disabled: isDisabled, From 763b8c933a8cdb32604b0a4df2404834ac4d5621 Mon Sep 17 00:00:00 2001 From: guille Date: Tue, 5 Mar 2024 16:05:35 -0300 Subject: [PATCH 3/3] refactor(currency): change default placeholder --- src/utils/__tests__/getQuestionProps.test.js | 75 +++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/src/utils/__tests__/getQuestionProps.test.js b/src/utils/__tests__/getQuestionProps.test.js index 95287af..e58fe0c 100644 --- a/src/utils/__tests__/getQuestionProps.test.js +++ b/src/utils/__tests__/getQuestionProps.test.js @@ -360,7 +360,7 @@ describe('getQuestionProps', () => { }); }); - describe('when `question.type` is number', () => { + describe('when `question.type` is number and placeholder value is empty', () => { beforeEach(() => { question = { type: 2, @@ -395,7 +395,42 @@ describe('getQuestionProps', () => { }); }); - describe('when `question.type` is currency', () => { + describe('when `question.type` is number and placeholder value is not empty', () => { + beforeEach(() => { + question = { + type: 2, + name: 'S1P1', + label: 'question 1', + placeholder: 'Lorem Ipsum', + number: '1', + multiple: false, + subQuestions: [] + }; + }); + + it('should return props', () => { + expect( + getQuestionProps({sectionIndex, section, question, values, disabled, warnings, initialValues, sections}) + ).toEqual({ + props: { + label: {text: 'question 1', number: '1', introduction: undefined}, + name: 'S1.0.S1P1.answer', + placeholder: 'Lorem Ipsum', + type: 'number', + disabled: true, + warnings: {}, + isMultiple: false, + show: true, + subQuestions: [], + values: {answer: {value: ''}, id: 1} + }, + questionName: 'S1.0.S1P1.answer', + questionType: 2, + jump: {valid: true} + }); + }); + }); + describe('when `question.type` is currency and placeholder value is empty', () => { beforeEach(() => { question = { type: 8, @@ -430,6 +465,42 @@ describe('getQuestionProps', () => { }); }); + describe('when `question.type` is currency and placeholder value is not empty', () => { + beforeEach(() => { + question = { + type: 8, + name: 'S1P1', + label: 'question 1', + placeholder: 'Lorem Ipsum', + number: '1', + multiple: false, + subQuestions: [] + }; + }); + + it('should return props', () => { + expect( + getQuestionProps({sectionIndex, section, question, values, disabled, warnings, initialValues, sections}) + ).toEqual({ + props: { + label: {text: 'question 1', number: '1', introduction: undefined}, + name: 'S1.0.S1P1.answer', + placeholder: 'Lorem Ipsum', + type: 'text', + disabled: true, + warnings: {}, + isMultiple: false, + show: true, + subQuestions: [], + values: {answer: {value: ''}, id: 1} + }, + questionName: 'S1.0.S1P1.answer', + questionType: 8, + jump: {valid: true} + }); + }); + }); + describe('when `question.type` is dropdown', () => { beforeEach(() => { question = {