-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #308 from digitalfabrik/LUN-131-logic-for-unlockin…
…g-exercises LUN-131: Logic for unlocking exercises
- Loading branch information
Showing
12 changed files
with
151 additions
and
65 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
release-notes/unreleased/LUN-131-logic-for-unlocking-exercises-2.yml
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,6 @@ | ||
issue_key: LUN-131 | ||
show_in_stores: true | ||
platforms: | ||
- android | ||
- ios | ||
de: Freischaltungsmechanismus für Übungen |
6 changes: 6 additions & 0 deletions
6
release-notes/unreleased/LUN-131-logic-for-unlocking-exercises.yml
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,6 @@ | ||
issue_key: LUN-131 | ||
show_in_stores: true | ||
platforms: | ||
- android | ||
- ios | ||
de: Fortschrittsanzeige für Übungen |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import RNAsyncStorage from '@react-native-async-storage/async-storage' | ||
import { RouteProp } from '@react-navigation/native' | ||
import { fireEvent } from '@testing-library/react-native' | ||
import { mocked } from 'jest-mock' | ||
import React from 'react' | ||
|
||
import { EXERCISES } from '../../../constants/data' | ||
import useLoadDocuments from '../../../hooks/useLoadDocuments' | ||
import { RoutesParams } from '../../../navigation/NavigationTypes' | ||
import DocumentBuilder from '../../../testing/DocumentBuilder' | ||
import createNavigationMock from '../../../testing/createNavigationPropMock' | ||
import { getReturnOf } from '../../../testing/helper' | ||
import { mockDisciplines } from '../../../testing/mockDiscipline' | ||
import render from '../../../testing/render' | ||
import ExercisesScreen from '../ExercisesScreen' | ||
|
||
jest.mock('@react-navigation/native') | ||
jest.mock('../../../hooks/useLoadDocuments') | ||
|
||
describe('ExercisesScreen', () => { | ||
const documents = new DocumentBuilder(1).build() | ||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
RNAsyncStorage.clear() | ||
mocked(useLoadDocuments).mockReturnValue(getReturnOf(documents)) | ||
}) | ||
|
||
const navigation = createNavigationMock<'Exercises'>() | ||
const route: RouteProp<RoutesParams, 'Exercises'> = { | ||
key: 'key-0', | ||
name: 'Exercises', | ||
params: { | ||
disciplineId: mockDisciplines()[0].id, | ||
disciplineTitle: mockDisciplines()[0].title, | ||
discipline: mockDisciplines()[0], | ||
documents: null | ||
} | ||
} | ||
|
||
it('should render correctly', () => { | ||
const { getAllByText } = render(<ExercisesScreen route={route} navigation={navigation} />) | ||
EXERCISES.forEach(exercise => { | ||
expect(getAllByText(exercise.title)).toBeDefined() | ||
expect(getAllByText(exercise.description)).toBeDefined() | ||
}) | ||
}) | ||
|
||
it('should show modal on navigation if locked', async () => { | ||
const { getByText, getByTestId } = render(<ExercisesScreen route={route} navigation={navigation} />) | ||
expect(getByTestId('locking-modal')).toHaveProp('visible', false) | ||
const lockedExercise = getByText(EXERCISES[1].title) | ||
fireEvent.press(lockedExercise) | ||
expect(getByTestId('locking-modal')).toHaveProp('visible', true) | ||
expect(navigation.navigate).not.toHaveBeenCalled() | ||
}) | ||
|
||
it('should trigger navigation if unlocked', () => { | ||
const { getAllByText } = render(<ExercisesScreen route={route} navigation={navigation} />) | ||
const nextExercise = getAllByText(EXERCISES[0].title) | ||
fireEvent.press(nextExercise[1]) | ||
expect(navigation.navigate).toHaveBeenCalledWith(EXERCISES[0].screen, { | ||
closeExerciseAction: undefined, | ||
disciplineId: mockDisciplines()[0].id, | ||
disciplineTitle: mockDisciplines()[0].title, | ||
documents | ||
}) | ||
}) | ||
}) |
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.