-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#30] Fill the data into the Question page
- Loading branch information
Showing
22 changed files
with
495 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
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(<Answer question={question} data-test-id={dataTestId} />); | ||
|
||
const intro = screen.getByTestId(dataTestId); | ||
|
||
expect(intro).toBeVisible(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<Rating | ||
questionId={question.id} | ||
items={question.answers} | ||
displayType={displayTypeEnum} | ||
data-test-id={rest['data-test-id']} | ||
/> | ||
); | ||
case DisplayType.Choice: | ||
return ( | ||
<MultiChoice | ||
questionId={question.id} | ||
items={question.answers} | ||
isPickOne={question?.pick === 'one'} | ||
data-test-id={rest['data-test-id']} | ||
/> | ||
); | ||
case DisplayType.Nps: | ||
return <Nps questionId={question.id} items={question.answers} data-test-id={rest['data-test-id']} />; | ||
case DisplayType.Textarea: | ||
return <TextArea questionId={question.id} items={question.answers} data-test-id={rest['data-test-id']} />; | ||
case DisplayType.Textfield: | ||
return <MultiInputs questionId={question.id} items={question.answers} data-test-id={rest['data-test-id']} />; | ||
case DisplayType.Dropdown: | ||
return <Dropdown questionId={question.id} items={question.answers} data-test-id={rest['data-test-id']} />; | ||
case DisplayType.Slider: | ||
return <AppSlider questionId={question.id} items={question.answers} data-test-id={rest['data-test-id']} />; | ||
case DisplayType.Unknown: | ||
case DisplayType.Intro: | ||
case DisplayType.Outro: | ||
default: | ||
return <div {...rest}></div>; | ||
} | ||
}; | ||
|
||
export default Answer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.