This file contains hidden or 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
| import React, { useState } from 'react'; | |
| function Example() { | |
| const [state, setState] = useState({counter:0}); | |
| const add1ToCounter = () => { | |
| const newCounterValue = state.counter + 1; | |
| setState({ counter: newCounterValue}); | |
| } | |
| return ( |
This file contains hidden or 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
| import { REPOS_SUCCESS } from "../constants/ActionTypes"; | |
| import reposReducer from "./repos"; | |
| describe("repos service", () => { | |
| it("should handle REPOS_SUCCESS action", () => { | |
| const action = { | |
| type: REPOS_SUCCESS, | |
| repos: [{}] | |
| }; | |
| const state = reposReducer(null, action); |
This file contains hidden or 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
| import { combineReducers } from "redux"; | |
| import repos from "./repos"; | |
| const rootReducer = combineReducers({ | |
| repos | |
| }); | |
| export default rootReducer; |
This file contains hidden or 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
| import { REPOS_SUCCESS } from "../constants/ActionTypes"; | |
| const initialState = { | |
| repos: [], | |
| status: null | |
| }; | |
| export default function repos(state = initialState, action) { | |
| switch (action.type) { | |
| case REPOS_SUCCESS: |
This file contains hidden or 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
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| import { REPOS_SUCCESS } from "../constants/ActionTypes"; | |
| import "../index.css"; | |
| import MessagePage from "../components/MessagePage"; | |
| import Repos from "../components/Repos"; | |
| import NavBar from "../components/NavBar"; | |
| import User from "./User"; |
This file contains hidden or 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
| import React from "react"; | |
| import ReactDOM from "react-dom"; | |
| import { Provider } from "react-redux"; | |
| import ConnectedMain from "./ConnectedMain"; | |
| describe("connected main", () => { | |
| const store = { | |
| getState: () => ({ repos: { repos: [], status: "" } }), | |
| subscribe: () => {}, |
This file contains hidden or 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
| import { getReposByUsername as action } from "./repos"; | |
| import { | |
| REPOS_SUCCESS, | |
| REPOS_EMPTY, | |
| REPOS_NOT_FOUND, | |
| REPOS_ERROR | |
| } from "../constants/ActionTypes"; | |
| describe("repos action", () => { | |
| const username = "user"; |
This file contains hidden or 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
| import { reposServiceFunction } from "./repos"; | |
| describe("repos service", () => { | |
| const mockAxios = { | |
| get: jest.fn() | |
| }; | |
| it("should call axios with repos url", () => { | |
| const username = "user"; | |
| reposServiceFunction(mockAxios).getResposByUserName(username); |
This file contains hidden or 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
| import { connect } from "react-redux"; | |
| import { getReposByUsernameInjector } from "../actions/repos"; | |
| import Main from "../components/Main"; | |
| const mapStateToProps = state => ({ | |
| reposState: state.repos | |
| }); | |
| const mapDispatchToProps = dispatch => ({ |
This file contains hidden or 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
| import reposService from "../services/repos"; | |
| import { | |
| REPOS_REQUEST, | |
| REPOS_EMPTY, | |
| REPOS_SUCCESS, | |
| REPOS_NOT_FOUND, | |
| REPOS_ERROR | |
| } from "../constants/ActionTypes"; | |
| export const getReposByUsername = async (dispatch, reposService, username) => { |