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 ( { }); }); - describe('when `question.type` is number', () => { + describe('when `question.type` is number and placeholder value is empty', () => { beforeEach(() => { question = { type: 2, @@ -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: {}, @@ -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, @@ -414,7 +449,43 @@ 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: {}, + 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 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: {}, 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,