adding test and ui to home page #6
Merged
corentin.richard
merged 1 commits from unitTesting
into master
2 years ago
@ -0,0 +1,9 @@
|
||||
// somewhere in your configuration files
|
||||
import AsyncStorageMock from '@react-native-async-storage/async-storage/jest/async-storage-mock';
|
||||
|
||||
AsyncStorageMock.multiGet = jest.fn(([keys], callback) => {
|
||||
// do something here to retrieve data
|
||||
callback([]);
|
||||
});
|
||||
|
||||
export default AsyncStorageMock;
|
After Width: | Height: | Size: 281 KiB |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,36 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import testReducer from "../setup/testReducer";
|
||||
import { Provider } from "react-redux";
|
||||
import { render } from "react-dom";
|
||||
import Item from "../../components/ListItemComponent";
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
appReducer: testReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleWare) =>
|
||||
getDefaultMiddleWare({
|
||||
serializableCheck: false
|
||||
})
|
||||
});
|
||||
|
||||
const Wrapper = ({children}) => (<Provider store={store}>{children}</Provider>);
|
||||
|
||||
describe('<Item/>', ()=> {
|
||||
test('Assert displayed values', () =>{
|
||||
const expectedCardInfos = store.getState().appReducer.cards[0];
|
||||
|
||||
render(<Wrapper>
|
||||
<Item route={{
|
||||
card: expectedCardInfos,
|
||||
bool: false
|
||||
}} ></Item>
|
||||
</Wrapper>)
|
||||
|
||||
expect(screen.getByTestId('card-url')).toHaveProperty("source", {uri: expectedCardInfos.img})
|
||||
|
||||
|
||||
})
|
||||
})
|
@ -0,0 +1,44 @@
|
||||
import { configureStore } from "@reduxjs/toolkit";
|
||||
import testReducer from "../setup/testReducer";
|
||||
import { Provider } from "react-redux";
|
||||
import { render } from "react-dom";
|
||||
import Item from "../../components/ListItemComponent";
|
||||
import { fireEvent } from "@testing-library/react-native";
|
||||
import AsyncStorageMock from "../../__mocks__/@react-native-community/async-storage";
|
||||
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
appReducer: testReducer,
|
||||
},
|
||||
middleware: (getDefaultMiddleWare) =>
|
||||
getDefaultMiddleWare({
|
||||
serializableCheck: false
|
||||
})
|
||||
});
|
||||
|
||||
const Wrapper = ({children}) => (<Provider store={store}>{children}</Provider>);
|
||||
|
||||
describe('<Item/>', ()=> {
|
||||
test('Assert displayed values for fav list', () =>{
|
||||
const expectedCardInfos = store.getState().appReducer.favoriteCards[0];
|
||||
|
||||
render(<Wrapper>
|
||||
<Item route={{
|
||||
card: expectedCardInfos,
|
||||
bool: true,
|
||||
}} ></Item>
|
||||
</Wrapper>)
|
||||
|
||||
expect(screen.getByTestId('card-url')).toHaveProperty("source", {uri: expectedCardInfos.img})
|
||||
|
||||
let size = store.getState().appReducer.favoriteCards.length;
|
||||
|
||||
fireEvent.press(screen.getByTestId("button"))
|
||||
|
||||
expect(store.getState().appReducer.favoriteCards.length).toBe(size - 1)
|
||||
|
||||
})
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
import { Card } from "../../models/Card";
|
||||
import { setCardsList } from "../../redux/actions/action_setCardsList";
|
||||
|
||||
describe('setCardLIst',() => {
|
||||
it('should take the list', () => {
|
||||
const payload = [new Card("1","test1","",""),new Card("2","test2","","",true)];
|
||||
const expectation = {
|
||||
type: "FETCH_DATA",
|
||||
payload: payload,
|
||||
};
|
||||
|
||||
expect(setCardsList(payload)).toEqual(expectation);
|
||||
})
|
||||
})
|
@ -0,0 +1,16 @@
|
||||
import { Card } from "../../models/Card";
|
||||
import { setFavList } from "../../redux/actions/action_setFavList";
|
||||
import { setList } from "../../redux/actions/action_setFavs";
|
||||
|
||||
|
||||
describe('setFavs',() => {
|
||||
it('should take the list', () => {
|
||||
const payload = [new Card("1","test1","",""),new Card("2","test2","","",true)];
|
||||
const expectation = {
|
||||
type: "SET_FAVS",
|
||||
payload: payload,
|
||||
};
|
||||
|
||||
expect(setList(payload)).toEqual(expectation);
|
||||
})
|
||||
})
|
@ -0,0 +1,25 @@
|
||||
import appReducer from "../../redux/reducers/appReducer";
|
||||
|
||||
describe('Test Reducer', () => {
|
||||
let initialState = {
|
||||
cards: [],
|
||||
favoriteCards: []
|
||||
}
|
||||
|
||||
it('should return initial state', () => {
|
||||
expect(appReducer(undefined, {})).toEqual(initialState);
|
||||
});
|
||||
|
||||
it('should handle FETCH_DATA', () => {
|
||||
const payload = [new Card("1","test1","",""),new Card("2","test2","","",true)];
|
||||
expect(
|
||||
appReducer(initialState, {
|
||||
type: "FETCH_DATA",
|
||||
payload,
|
||||
})
|
||||
).toEqual({
|
||||
cards: payload,
|
||||
favoriteCards: [],
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,3 @@
|
||||
import mockAsyncStorage from '@react-native-async-storage/async-storage/jest/async-storage-mock';
|
||||
|
||||
jest.mock('@react-native-community/async-storage', () => mockAsyncStorage);
|
@ -0,0 +1,13 @@
|
||||
import { Card } from "../../models/Card";
|
||||
import appReducer from "../../redux/reducers/appReducer"
|
||||
|
||||
const initialState = {
|
||||
cards: [new Card("1","test1","url1","urlGold2")],
|
||||
favoriteCards: [new Card("1","test1","url1","urlGold2")]
|
||||
}
|
||||
|
||||
//@ts-ignore
|
||||
export default testReducer = (state = initialState, action) => {
|
||||
//@ts-ignore
|
||||
return appReducer(initialState,action);
|
||||
}
|
Loading…
Reference in new issue