Skip to content

Commit

Permalink
Adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lunars97 committed Jan 12, 2025

Verified

This commit was signed with the committer’s verified signature.
renovate-bot Mend Renovate
1 parent 9cef14f commit 6d6e949
Showing 3 changed files with 71 additions and 12 deletions.
74 changes: 68 additions & 6 deletions native/src/components/__tests__/FeedbackContainer.spec.tsx
Original file line number Diff line number Diff line change
@@ -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(
<NavigationContainer>
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} />
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} noResults={noResults} />
</NavigationContainer>,
)
const positiveRatingButton = getByText('useful')
@@ -70,7 +71,7 @@ describe('FeedbackContainer', () => {
const contactMail = '[email protected]'
const { getByText, findByText, getAllByDisplayValue } = render(
<NavigationContainer>
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} />
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} noResults={noResults} />
</NavigationContainer>,
)
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(
<NavigationContainer>
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} />
<FeedbackContainer routeType={CATEGORIES_ROUTE} language={language} cityCode={city} noResults={noResults} />
</NavigationContainer>,
)
const positiveRatingButton = getByText('useful')
@@ -120,7 +121,13 @@ describe('FeedbackContainer', () => {
const query = 'Zeugnis'
const { findByText, getByText } = render(
<NavigationContainer>
<FeedbackContainer routeType={SEARCH_ROUTE} language={language} cityCode={city} query={query} />
<FeedbackContainer
routeType={SEARCH_ROUTE}
language={language}
cityCode={city}
query={query}
noResults={noResults}
/>
</NavigationContainer>,
)
const button = getByText('send')
@@ -145,7 +152,13 @@ describe('FeedbackContainer', () => {
const fullSearchTerm = 'Zeugnisübergabe'
const { findByText, getByDisplayValue, getByText } = render(
<NavigationContainer>
<FeedbackContainer routeType={SEARCH_ROUTE} language={language} cityCode={city} query={query} />
<FeedbackContainer
routeType={SEARCH_ROUTE}
language={language}
cityCode={city}
query={query}
noResults={noResults}
/>
</NavigationContainer>,
)
const input = getByDisplayValue(query)
@@ -170,12 +183,61 @@ describe('FeedbackContainer', () => {
it('should disable send button if query term is removed', async () => {
const { findByText, getByDisplayValue } = render(
<NavigationContainer>
<FeedbackContainer routeType={SEARCH_ROUTE} language={language} cityCode={city} query='query' />
<FeedbackContainer
routeType={SEARCH_ROUTE}
language={language}
cityCode={city}
query='query'
noResults={noResults}
/>
</NavigationContainer>,
)
expect(await findByText('send')).not.toBeDisabled()
const input = getByDisplayValue('query')
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(
<NavigationContainer>
<FeedbackContainer
routeType={SEARCH_ROUTE}
language={language}
cityCode={city}
query={query}
noResults={noResults}
/>
</NavigationContainer>,
)
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,
},
},
})
})
})
2 changes: 1 addition & 1 deletion native/src/routes/FeedbackModalContainer.tsx
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ type FeedbackModalContainerProps = {
}

const FeedbackModalContainer = ({ route }: FeedbackModalContainerProps): ReactElement => (
<FeedbackContainer {...route.params} />
<FeedbackContainer {...route.params} noResults={false} />
)

export default FeedbackModalContainer
7 changes: 2 additions & 5 deletions web/src/components/FeedbackContainer.tsx
Original file line number Diff line number Diff line change
@@ -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')

0 comments on commit 6d6e949

Please sign in to comment.