Skip to content

Instantly share code, notes, and snippets.

@tanner-west
Created April 27, 2022 15:30
Show Gist options
  • Save tanner-west/a2b154549187606bc2d7222978836fbc to your computer and use it in GitHub Desktop.
Save tanner-west/a2b154549187606bc2d7222978836fbc to your computer and use it in GitHub Desktop.
import React from 'react';
import {Provider} from 'react-redux';
import {configureStore} from '@reduxjs/toolkit';
import {fireEvent, render} from '@testing-library/react-native';
import {ApplicationProvider} from '@ui-kitten/components';
import * as eva from '@eva-design/eva';
import questionsReducer from '../../questions/questionsSlice';
import QuizScreen from '../QuizScreen';
jest.mock('react-native-toast-message', () => ({
show: jest.fn(),
hide: jest.fn(),
}));
const mockNavigation = {
setOptions: jest.fn()
}
export const store = configureStore({
reducer: {questions: questionsReducer},
preloadedState: {
questions: {
loadingGetQuestions: false,
list: [
{
id: '123-ABC',
text: 'What is 2 + 2?',
answers: ['4', '1', '16', '24'],
correctAnswer: 0,
},
{
id: '456-XYZ',
text: 'What is 12 * 12?',
answers: ['1000', '240', '144', '24'],
correctAnswer: 2,
},
],
},
},
});
describe('<QuizScreen />', () => {
const {getByText} = render(
<Provider store={store}>
<ApplicationProvider {...eva} theme={eva.light}>
<QuizScreen navigation={mockNavigation}/>
</ApplicationProvider>
</Provider>,
);
it('should finish quiz and see results page', () => {
const answerRadio1 = getByText('4');
fireEvent(answerRadio1, 'onPress');
const submitButton1 = getByText('Submit');
fireEvent(submitButton1, 'onPress');
getByText(/Correct/);
const nextButton1 = getByText('Next');
fireEvent(nextButton1, 'onPress');
const answerRadio2 = getByText('24');
fireEvent(answerRadio2, 'onPress');
const submitButton2 = getByText('Submit');
fireEvent(submitButton2, 'onPress');
getByText(/Incorrect/);
const nextButton2 = getByText('Next');
fireEvent(nextButton2, 'onPress');
getByText('Question 1');
getByText('Question 2');
getByText('4 (Correct)');
getByText('24 (Incorrect)');
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment