diff --git a/src/components/Answer/index.test.tsx b/src/components/Answer/index.test.tsx
new file mode 100644
index 0000000..3a76e8e
--- /dev/null
+++ b/src/components/Answer/index.test.tsx
@@ -0,0 +1,176 @@
+import React from 'react';
+
+import { render, screen } from '@testing-library/react';
+
+import { Question } from 'types/question';
+
+import Answer from '.';
+
+describe('Answer', () => {
+ describe('given the display type is star', () => {
+ it('renders Rating component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'star',
+ answers: [],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const star = screen.getByTestId(dataTestId);
+
+ expect(star).toBeVisible();
+ expect(star).toHaveAttribute('id', 'rating-id');
+ });
+ });
+
+ describe('given the display type is choice', () => {
+ it('renders MultiChoice component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'choice',
+ answers: [],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const multiChoice = screen.getByTestId(dataTestId);
+
+ expect(multiChoice).toBeVisible();
+ expect(multiChoice).toHaveAttribute('id', 'multi-choice-id');
+ });
+ });
+
+ describe('given the display type is nps', () => {
+ it('renders Nps component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'nps',
+ answers: [],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const nps = screen.getByTestId(dataTestId);
+
+ expect(nps).toBeVisible();
+ expect(nps).toHaveAttribute('id', 'nps-id');
+ });
+ });
+
+ describe('given the display type is textarea', () => {
+ it('renders TextArea component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'textarea',
+ answers: [
+ {
+ id: 'id',
+ resourceType: 'answer',
+ text: '',
+ },
+ ],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const textArea = screen.getByTestId(dataTestId);
+
+ expect(textArea).toBeVisible();
+ expect(textArea).toHaveAttribute('id', 'text-area-id');
+ });
+ });
+
+ describe('given the display type is textfield', () => {
+ it('renders MultiInputs component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'textfield',
+ answers: [
+ {
+ id: 'id',
+ resourceType: 'answer',
+ text: '',
+ },
+ ],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const multiInputs = screen.getByTestId(dataTestId);
+
+ expect(multiInputs).toBeVisible();
+ expect(multiInputs).toHaveAttribute('id', 'multi-inputs-id');
+ });
+ });
+
+ describe('given the display type is dropdown', () => {
+ it('renders Dropdown component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'dropdown',
+ answers: [
+ {
+ id: 'id',
+ resourceType: 'answer',
+ text: '',
+ },
+ ],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const dropdown = screen.getByTestId(dataTestId);
+
+ expect(dropdown).toBeVisible();
+ expect(dropdown).toHaveAttribute('id', 'dropdown-id');
+ });
+ });
+
+ describe('given the display type is slider', () => {
+ it('renders Dropdown component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'slider',
+ answers: [
+ {
+ id: 'id',
+ resourceType: 'answer',
+ text: '',
+ },
+ ],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const slider = screen.getByTestId(dataTestId);
+
+ expect(slider).toBeVisible();
+ expect(slider).toHaveAttribute('id', 'slider-id');
+ });
+ });
+
+ describe('given the display type is intro', () => {
+ it('renders Dropdown component', () => {
+ const question: Question = {
+ id: 'id',
+ resourceType: 'question',
+ displayType: 'intro',
+ answers: [],
+ };
+ const dataTestId = 'answer';
+ render();
+
+ const intro = screen.getByTestId(dataTestId);
+
+ expect(intro).toBeVisible();
+ });
+ });
+});
diff --git a/src/components/Answer/index.tsx b/src/components/Answer/index.tsx
new file mode 100644
index 0000000..a9ed91c
--- /dev/null
+++ b/src/components/Answer/index.tsx
@@ -0,0 +1,59 @@
+import React from 'react';
+
+import AppSlider from 'components/AppSlider';
+import Dropdown from 'components/Dropdown';
+import MultiChoice from 'components/MultiChoice';
+import MultiInputs from 'components/MultiInputs';
+import Nps from 'components/Nps';
+import Rating from 'components/Rating';
+import TextArea from 'components/TextArea';
+import { DisplayType, Question, getDisplayTypeEnum } from 'types/question';
+
+interface AnswerProps {
+ question: Question;
+ 'data-test-id'?: string;
+}
+const Answer = ({ question, ...rest }: AnswerProps): JSX.Element => {
+ const displayTypeEnum = getDisplayTypeEnum(question);
+
+ switch (displayTypeEnum) {
+ case DisplayType.Heart:
+ case DisplayType.Smiley:
+ case DisplayType.Thumbs:
+ case DisplayType.Star:
+ return (
+
+ );
+ case DisplayType.Choice:
+ return (
+
+ );
+ case DisplayType.Nps:
+ return ;
+ case DisplayType.Textarea:
+ return ;
+ case DisplayType.Textfield:
+ return ;
+ case DisplayType.Dropdown:
+ return ;
+ case DisplayType.Slider:
+ return ;
+ case DisplayType.Unknown:
+ case DisplayType.Intro:
+ case DisplayType.Outro:
+ default:
+ return
;
+ }
+};
+
+export default Answer;
diff --git a/src/components/AppSlider/index.test.tsx b/src/components/AppSlider/index.test.tsx
index 680fe17..4418350 100644
--- a/src/components/AppSlider/index.test.tsx
+++ b/src/components/AppSlider/index.test.tsx
@@ -6,7 +6,11 @@ import AppSlider, { appSliderDataTestIds } from '.';
describe('AppSlider', () => {
it('renders AppSlider component', () => {
- render();
+ const onValueChanged = () => {
+ // Do nothing
+ };
+
+ render();
const appSlider = screen.getByTestId(appSliderDataTestIds.base);
const slider = screen.getByRole('slider');
diff --git a/src/components/AppSlider/index.tsx b/src/components/AppSlider/index.tsx
index 3eb2217..b06794a 100644
--- a/src/components/AppSlider/index.tsx
+++ b/src/components/AppSlider/index.tsx
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useEffect } from 'react';
import Slider from 'rc-slider';
@@ -14,9 +14,9 @@ interface SliderProps {
}
const AppSlider = ({ min = 1, max = 100, step = 1, onValueChanged }: SliderProps): JSX.Element => {
- const handleOnChange = (value: number) => {
- onValueChanged(value);
- };
+ useEffect(() => {
+ onValueChanged(min);
+ }, [min, onValueChanged]);
return (
@@ -45,7 +45,7 @@ const AppSlider = ({ min = 1, max = 100, step = 1, onValueChanged }: SliderProps
min={min}
max={max}
step={step}
- onChange={(value) => handleOnChange(value as number)}
+ onChange={(value) => onValueChanged(value as number)}
/>
);
diff --git a/src/components/Dropdown/index.tsx b/src/components/Dropdown/index.tsx
index 3e5f167..ba5bc47 100644
--- a/src/components/Dropdown/index.tsx
+++ b/src/components/Dropdown/index.tsx
@@ -12,6 +12,7 @@ interface DropdownProps {
items: Answer[];
onValueChanged: (value: Answer) => void;
}
+
const Dropdown = ({ questionId, items, onValueChanged }: DropdownProps): JSX.Element => {
const [isOpen, setIsOpen] = useState(false);
const [selectedValue, setSelectedValue] = useState(items[0].text);
diff --git a/src/components/ElevatedButton/index.tsx b/src/components/ElevatedButton/index.tsx
index 04d1961..0212d04 100644
--- a/src/components/ElevatedButton/index.tsx
+++ b/src/components/ElevatedButton/index.tsx
@@ -12,7 +12,7 @@ const ElevatedButton = ({ children, isFullWidth, ...rest }: ElevatedButtonProps)
'bg-white text-black-chinese font-bold text-regular tracking-survey-tight rounded-[10px] focus:outline-none focus:shadow-outline h-14';
return (
-