-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed the ability to save answer of question when type is Open Answer #3148
base: develop
Are you sure you want to change the base?
Fixed the ability to save answer of question when type is Open Answer #3148
Conversation
amoutens
commented
Jan 28, 2025
•
edited
Loading
edited
- Fixed ability to save Open Answer answers
- Provided opportunity to add more than one answer for Open Answer
- Added styles for edit open answer question
- Added error handling on blur when we input empty new value
- Provided functional and styles for checking right answer when Open Answer
src/containers/my-quizzes/create-or-edit-quiz-question/CreateOrEditQuizQuestion.tsx
Outdated
Show resolved
Hide resolved
src/containers/my-quizzes/create-or-edit-quiz-question/CreateOrEditQuizQuestion.tsx
Outdated
Show resolved
Hide resolved
src/containers/my-quizzes/create-or-edit-quiz-question/CreateOrEditQuizQuestion.tsx
Outdated
Show resolved
Hide resolved
title: 'Question title', | ||
text: 'Question text', | ||
answers: [ | ||
{id: 0, text: 'Answer 1', isCorrect: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format this line, please
tests/unit/containers/my-quizzes/CreateOrEditQuizQuestion.spec.jsx
Outdated
Show resolved
Hide resolved
@@ -150,12 +161,14 @@ const CreateOrEditQuizQuestion: FC<CreateOrEditQuizQuestionProps> = ({ | |||
useEffect(() => { | |||
!question && onOpenCreateQuestionModal() | |||
// eslint-disable-next-line react-hooks/exhaustive-deps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try to not use eslint disablers in our project
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it isn't mine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but If you're working on the pr you should fix all of the issues coming with it. In my opinion at least...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to do my best
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just add useCallback
to the onOpenCreateQuestionModal
function declaration. This will stabilize the reference for that function, and useEffect
will run only if question
or onOpenCreateQuestionModal
are changed.
@@ -37,6 +37,7 @@ export interface UpdateQuestionParams { | |||
|
|||
export interface QuestionFormAnswer extends Answer { | |||
id: number | |||
isEditing?: boolean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why isEditing optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because isEditing only exists on openAnswer question type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay then perhaps should we make 2 different types? up 2 u tho
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks, I'll take a look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to leave as it was because creating 2 different types brings a lot of types mismatches
Quality Gate failedFailed conditions |
] | ||
handleNonInputValueChange('answers', addAnswer) | ||
} | ||
if (isEmptyAnswer) return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add braces here, please
const onOpenCreateQuestionModalRef = useRef(onOpenCreateQuestionModal) | ||
|
||
useEffect(() => { | ||
!question && onOpenCreateQuestionModal() | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, []) | ||
!question && onOpenCreateQuestionModalRef.current() | ||
}, [question]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very strange usage of useRef
Check, please, how it workds without useRef
, but with onOpenCreateQuestionModal
inside dependency array
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Format this file, please
fireEvent.click(addNewOneButton) | ||
|
||
expect(handleNonInputValueChange).toHaveBeenCalledWith("answers", [ | ||
{ id: 0, text: "", isCorrect: true, isEditing: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ id: 0, text: "", isCorrect: true, isEditing: true }, | |
{ id: 0, text: '', isCorrect: true, isEditing: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to format this file with prettier
@@ -116,6 +129,37 @@ describe('CreateOrEditQuizQuestion component without question', () => { | |||
expect(snackbar).toBeInTheDocument() | |||
expect(createQuestionSpy).toHaveBeenCalled() | |||
}) | |||
it('should call onCreateQuestion with openAnswer data', async () => { | |||
mockAxiosClient | |||
.onPost(`${URLs.resources.questions.post}`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.onPost(`${URLs.resources.questions.post}`) | |
.onPost(URLs.resources.questions.post) |
@@ -38,4 +38,24 @@ describe('Quiz Question tests', () => { | |||
const element = screen.getByText('0/1') | |||
expect(element).toBeInTheDocument() | |||
}) | |||
it('Should render correctness icon if shouldShowAnswersCorrectness is true', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('Should render correctness icon if shouldShowAnswersCorrectness is true', () => { | |
it('should render correctness icon if shouldShowAnswersCorrectness is true', () => { |
const icon = screen.getAllByTestId('CheckIcon')[0] | ||
expect(icon).toBeInTheDocument() | ||
}) | ||
it('Should render open answer input field', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('Should render open answer input field', () => { | |
it('should render open answer input field', () => { |