From 6d6e949e91f06dbb5483a28acfa35c3702b850fd Mon Sep 17 00:00:00 2001 From: lunars97 Date: Sat, 11 Jan 2025 21:09:14 +0100 Subject: [PATCH] Adjust tests --- .../__tests__/FeedbackContainer.spec.tsx | 74 +++++++++++++++++-- native/src/routes/FeedbackModalContainer.tsx | 2 +- web/src/components/FeedbackContainer.tsx | 7 +- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/native/src/components/__tests__/FeedbackContainer.spec.tsx b/native/src/components/__tests__/FeedbackContainer.spec.tsx index 4e630c7e92..5176d5fd39 100644 --- a/native/src/components/__tests__/FeedbackContainer.spec.tsx +++ b/native/src/components/__tests__/FeedbackContainer.spec.tsx @@ -28,11 +28,12 @@ describe('FeedbackContainer', () => { const city = 'augsburg' const language = 'de' + const noResults = false it('should send feedback request with rating and no other inputs on submit', async () => { const { getByText, findByText } = render( - + , ) const positiveRatingButton = getByText('useful') @@ -70,7 +71,7 @@ describe('FeedbackContainer', () => { const contactMail = 'test@example.com' const { getByText, findByText, getAllByDisplayValue } = render( - + , ) const [commentField, emailField] = getAllByDisplayValue('') @@ -106,7 +107,7 @@ describe('FeedbackContainer', () => { it('should disable send feedback button if rating button is clicked twice', async () => { const { getByText, findByText } = render( - + , ) const positiveRatingButton = getByText('useful') @@ -120,7 +121,13 @@ describe('FeedbackContainer', () => { const query = 'Zeugnis' const { findByText, getByText } = render( - + , ) const button = getByText('send') @@ -145,7 +152,13 @@ describe('FeedbackContainer', () => { const fullSearchTerm = 'Zeugnisübergabe' const { findByText, getByDisplayValue, getByText } = render( - + , ) const input = getByDisplayValue(query) @@ -170,7 +183,13 @@ describe('FeedbackContainer', () => { it('should disable send button if query term is removed', async () => { const { findByText, getByDisplayValue } = render( - + , ) expect(await findByText('send')).not.toBeDisabled() @@ -178,4 +197,47 @@ describe('FeedbackContainer', () => { fireEvent.changeText(input, '') expect(await findByText('send')).toBeDisabled() }) + + it('should send negative rating on submit if there are no search results found', async () => { + const query = 'gesundheitsversicherung' + const noResults = true + const { getByText, findByText } = render( + + + , + ) + expect(getByText('send')).not.toBeDisabled() + const submitButton = getByText('send') + fireEvent.press(submitButton) + expect(await findByText('thanksMessage')).toBeDefined() + expect(mockRequest).toHaveBeenCalledTimes(1) + expect(mockRequest).toHaveBeenCalledWith({ + routeType: SEARCH_ROUTE, + isPositiveRating: false, + city, + language, + comment: '', + contactMail: '', + query, + searchTerm: query, + slug: undefined, + }) + expect(sendTrackingSignal).toHaveBeenCalledTimes(1) + expect(sendTrackingSignal).toHaveBeenCalledWith({ + signal: { + name: SEND_FEEDBACK_SIGNAL_NAME, + feedback: { + positive: false, + numCharacters: 0, + contactMail: false, + }, + }, + }) + }) }) diff --git a/native/src/routes/FeedbackModalContainer.tsx b/native/src/routes/FeedbackModalContainer.tsx index 63139cf154..0594a19310 100644 --- a/native/src/routes/FeedbackModalContainer.tsx +++ b/native/src/routes/FeedbackModalContainer.tsx @@ -11,7 +11,7 @@ type FeedbackModalContainerProps = { } const FeedbackModalContainer = ({ route }: FeedbackModalContainerProps): ReactElement => ( - + ) export default FeedbackModalContainer diff --git a/web/src/components/FeedbackContainer.tsx b/web/src/components/FeedbackContainer.tsx index 731b5ebe7c..95128fa15c 100644 --- a/web/src/components/FeedbackContainer.tsx +++ b/web/src/components/FeedbackContainer.tsx @@ -40,10 +40,7 @@ export const FeedbackContainer = ({ useEffect(() => { setSearchTerm(query) - if (noResults === true) { - isPositiveRating = false - } - }, [query, noResults]) + }, [query]) const handleSubmit = () => { setSendingStatus('sending') @@ -59,7 +56,7 @@ export const FeedbackContainer = ({ query, slug, searchTerm, - isPositiveRating, + isPositiveRating: noResults === true ? false : isPositiveRating, }) setSendingStatus('successful')