|
| 1 | +import React from 'react'; |
| 2 | +import { Provider } from 'react-redux'; |
| 3 | +import { cleanup, fireEvent, render } from 'react-native-testing-library'; |
| 4 | +import configureStore from '../store'; |
| 5 | +import TodoList from './TodoList'; |
| 6 | + |
| 7 | +describe('Application test', () => { |
| 8 | + afterEach(cleanup); |
| 9 | + |
| 10 | + test('it should execute with a store with 4 elements', () => { |
| 11 | + const initialState = { |
| 12 | + todos: [ |
| 13 | + { id: 1, text: 'Sing something', date: new Date() }, |
| 14 | + { id: 2, text: 'Dance something', date: new Date() }, |
| 15 | + { id: 3, text: 'Sleep something', date: new Date() }, |
| 16 | + { id: 4, text: 'Sleep something', date: new Date() }, |
| 17 | + ], |
| 18 | + }; |
| 19 | + const store = configureStore(initialState); |
| 20 | + |
| 21 | + const component = ( |
| 22 | + <Provider store={store}> |
| 23 | + <TodoList /> |
| 24 | + </Provider> |
| 25 | + ); |
| 26 | + |
| 27 | + const { getAllByText } = render(component); |
| 28 | + const todoElems = getAllByText(/something/i); |
| 29 | + |
| 30 | + expect(todoElems.length).toEqual(4); |
| 31 | + }); |
| 32 | + |
| 33 | + test('should execute with 2 elements and end up with 1 after delete', () => { |
| 34 | + const initialState = { |
| 35 | + todos: [ |
| 36 | + { id: 1, text: 'Sing something', date: new Date() }, |
| 37 | + { id: 2, text: 'Dance something', date: new Date() }, |
| 38 | + ], |
| 39 | + }; |
| 40 | + const store = configureStore(initialState); |
| 41 | + |
| 42 | + const component = ( |
| 43 | + <Provider store={store}> |
| 44 | + <TodoList /> |
| 45 | + </Provider> |
| 46 | + ); |
| 47 | + |
| 48 | + const { getAllByText } = render(component); |
| 49 | + const todoElems = getAllByText(/something/i); |
| 50 | + |
| 51 | + expect(todoElems.length).toBe(2); |
| 52 | + |
| 53 | + const buttons = getAllByText('Delete'); |
| 54 | + expect(buttons.length).toBe(2); |
| 55 | + |
| 56 | + fireEvent.press(buttons[0]); |
| 57 | + expect(getAllByText('Delete').length).toBe(1); |
| 58 | + }); |
| 59 | +}); |
0 commit comments