Skip to content

Commit

Permalink
Merge pull request #309 from digitalfabrik/LUN-351-separeted-words-wrong
Browse files Browse the repository at this point in the history
LUN-351: Write Exercise incorrect answer validation
  • Loading branch information
steffenkleinle authored Jun 7, 2022
2 parents b2b2c8a + 58cfdbb commit 6a394dd
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
6 changes: 6 additions & 0 deletions release-notes/unreleased/LUN-351-separated-words-wrong.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
issue_key: LUN-280
show_in_stores: true
platforms:
- android
- ios
de: Richtige Antworten für getrennte Wörter werden nun korrekt ausgewertet.
2 changes: 1 addition & 1 deletion src/routes/write-exercise/components/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Feedback = ({ documentWithResult, submission, needsToBeRepeated }: Feedbac
return (
<Background source={background} testID='background-image'>
<Icon width={28} height={28} />
<StyledText numberOfLines={3} ellipsizeMode='tail' testID='feedback-write-exercise'>
<StyledText numberOfLines={3} ellipsizeMode='tail'>
{message}
</StyledText>
</Background>
Expand Down
9 changes: 5 additions & 4 deletions src/routes/write-exercise/components/InteractionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,15 @@ const InteractionSection = (props: InteractionSectionProps): ReactElement => {
}

const checkEntry = async (): Promise<void> => {
const splitInput = input.trim().split(' ')
if (splitInput.length < 2) {
const trimmed = input.trim()
const indexOfFirstSpace = trimmed.indexOf(' ')
if (indexOfFirstSpace < 0) {
setIsArticleMissing(true)
return
}

const article = capitalizeFirstLetter(splitInput[0])
const word = splitInput[1]
const article = capitalizeFirstLetter(trimmed.substring(0, indexOfFirstSpace))
const word = trimmed.substring(indexOfFirstSpace + 1)

setSubmittedInput(input)
updateAndStoreResult(validateAnswer(article, word))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import { DocumentResult } from '../../../../navigation/NavigationTypes'
import render from '../../../../testing/render'
import InteractionSection from '../InteractionSection'

jest.mock('react-native-tts', () => ({
getInitStatus: jest.fn(async () => 'success'),
addListener: jest.fn(async () => ({ remove: jest.fn() }))
}))

jest.mock('react-native-sound-player', () => ({
addEventListener: jest.fn(() => ({ remove: jest.fn() }))
}))
Expand Down Expand Up @@ -38,6 +43,15 @@ describe('InteractionSection', () => {
word: 'Spachtel'
}

const dividedDocument = {
alternatives: [],
article: ARTICLES[1],
audio: 'https://example.com/my-audio',
id: 0,
document_image: [],
word: 'kontaktlose Spannungsprüfer'
}

const renderInteractionSection = (documentWithResult: DocumentResult, isAnswerSubmitted: boolean): RenderAPI =>
render(
<InteractionSection
Expand Down Expand Up @@ -72,4 +86,84 @@ describe('InteractionSection', () => {
fireEvent.press(button)
await waitFor(() => expect(getByTestId('popover').props.isVisible).toBeTruthy())
})

it('should show incorrect if word is not correct', async () => {
const { rerender, getByText, getByPlaceholderText } = renderInteractionSection(
{ document, result: null, numberOfTries: 0 },
false
)
const inputField = getByPlaceholderText(labels.exercises.write.insertAnswer)
fireEvent.changeText(inputField, 'Die WrongAnswer')
fireEvent.press(getByText(labels.exercises.write.checkInput))

const documentWithResult: DocumentResult = { document, result: 'incorrect', numberOfTries: 1 }
expect(storeResult).toHaveBeenCalledWith(documentWithResult)

rerender(<InteractionSection documentWithResult={documentWithResult} isAnswerSubmitted storeResult={storeResult} />)
expect(getByText(labels.exercises.write.feedback.wrong, { exact: false })).toBeTruthy()
})

it('should show similar if word is similar', async () => {
const { rerender, getByText, getByPlaceholderText } = renderInteractionSection(
{ document, result: null, numberOfTries: 0 },
false
)
const inputField = getByPlaceholderText(labels.exercises.write.insertAnswer)
fireEvent.changeText(inputField, 'Die Wachtel')
fireEvent.press(getByText(labels.exercises.write.checkInput))

const documentWithResult: DocumentResult = { document, result: 'similar', numberOfTries: 1 }
expect(storeResult).toHaveBeenCalledWith(documentWithResult)

rerender(<InteractionSection documentWithResult={documentWithResult} isAnswerSubmitted storeResult={storeResult} />)
expect(getByText(labels.exercises.write.feedback.almostCorrect2, { exact: false })).toBeTruthy()
})

it('should show similar if word is correct and article similar', async () => {
const { rerender, getByText, getByPlaceholderText } = renderInteractionSection(
{ document, result: null, numberOfTries: 0 },
false
)
const inputField = getByPlaceholderText(labels.exercises.write.insertAnswer)
fireEvent.changeText(inputField, 'Das Spachtel')
fireEvent.press(getByText(labels.exercises.write.checkInput))

const documentWithResult: DocumentResult = { document, result: 'similar', numberOfTries: 1 }
expect(storeResult).toHaveBeenCalledWith(documentWithResult)

rerender(<InteractionSection documentWithResult={documentWithResult} isAnswerSubmitted storeResult={storeResult} />)
expect(getByText(labels.exercises.write.feedback.almostCorrect2, { exact: false })).toBeTruthy()
})

it('should show correct', async () => {
const { rerender, getByText, getByPlaceholderText } = renderInteractionSection(
{ document, result: null, numberOfTries: 0 },
false
)
const inputField = getByPlaceholderText(labels.exercises.write.insertAnswer)
fireEvent.changeText(inputField, 'Die Spachtel')
fireEvent.press(getByText(labels.exercises.write.checkInput))

const documentWithResult: DocumentResult = { document, result: 'correct', numberOfTries: 1 }
expect(storeResult).toHaveBeenCalledWith(documentWithResult)

rerender(<InteractionSection documentWithResult={documentWithResult} isAnswerSubmitted storeResult={storeResult} />)
expect(getByText('Toll, weiter so!', { exact: false })).toBeTruthy()
})

it('should show correct for divided words', async () => {
const { rerender, getByText, getByPlaceholderText } = renderInteractionSection(
{ document: dividedDocument, result: null, numberOfTries: 0 },
false
)
const inputField = getByPlaceholderText(labels.exercises.write.insertAnswer)
fireEvent.changeText(inputField, 'Der zweipolige Phasenprüfer')
fireEvent.press(getByText(labels.exercises.write.checkInput))

const documentWithResult: DocumentResult = { document, result: 'correct', numberOfTries: 1 }
expect(storeResult).toHaveBeenCalledWith(documentWithResult)

rerender(<InteractionSection documentWithResult={documentWithResult} isAnswerSubmitted storeResult={storeResult} />)
expect(getByText('Toll, weiter so!', { exact: false })).toBeTruthy()
})
})

0 comments on commit 6a394dd

Please sign in to comment.