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
// src/containers/RepoSearchPage/reducer/RepoSearchReducer.js | |
import { actionTypes } from '../RepoSearchConstants'; | |
const initialState = { | |
results: [{ | |
name: 'foo', | |
stargazers_count: 100, | |
id: '1', | |
},{ |
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
// src/containers/RepoSearchPage/reducer/RepoSearchReducer.spec.js | |
import RepoSearchReducer from './RepoSearchReducer'; | |
import { actionTypes } from '../RepoSearchConstants'; | |
const initialState = { | |
results: [], | |
}; | |
describe('RepoSearchReducer', () => { |
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
// src/containers/RepoSearchPage/actions/RepoSearchActions.js | |
import searchService from '../../../services/search/searchService'; | |
import { actionTypes } from '../RepoSearchConstants'; | |
export const fetchRepos = () => async (dispatch) => { | |
const { items } = await searchService.repoSearch(); | |
dispatch({ | |
type: actionTypes.UPDATE_RESULTS, | |
items, |
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
// src/containers/RepoSearchPage/actions/RepoSearchActions.spec.js | |
import { fetchRepos } from './RepoSearchActions'; | |
import searchService from '../../../services/search/searchService'; | |
import { actionTypes } from '../RepoSearchConstants'; | |
jest.mock('../../../services/search/searchService'); | |
describe('repo search actions', () => { | |
describe('fetchRepos', () => { |
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
// src/containers/RepoSearchPage/actions/RepoSearchActions.js | |
import searchService from '../../../services/search/searchService'; | |
export const fetchRepos = () => async (dispatch) => { | |
const { items } = await searchService.repoSearch(); | |
}; |
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
// src/containers/RepoSearchPage/actions/RepoSearchActions.spec.js | |
import { fetchRepos } from './RepoSearchActions'; | |
import searchService from '../../../services/search/searchService'; | |
jest.mock('../../../services/search/searchService'); | |
describe('repo search actions', () => { | |
describe('fetchRepos', () => { | |
it('should call searchService.repoSearch', async () => { |
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
// src/services/search/searchService.js | |
import xhr from '../../xhr/xhr'; | |
const repoSearch = async () => { | |
const { data } = await xhr._get('/search/repositories?q=language:javascript&sort=stars&order=desc'); | |
return data; | |
}; | |
export default { |
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
// src/services/search/searchService.spec.js | |
import searchService from './searchService'; | |
import xhr from '../../xhr/xhr'; | |
// requests the mocked version of the xhr module | |
jest.mock('../../xhr/xhr'); | |
describe('search service', () => { | |
describe('repoSearch', () => { |
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
// src/containers/RepoSearchPage/page/RepoSearchPage.js | |
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { connect } from 'react-redux'; | |
import RepoResultsList from '../components/RepoResultsList/RepoResultsList'; | |
class RepoSearchPage extends Component { | |
constructor(props) { | |
super(props); |
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
import searchService from '../../../services/search/searchService'; | |
import { actionTypes } from '../RepoSearchConstants'; | |
export const fetchRepos = () => async (dispatch) => { | |
let error = ''; | |
dispatch({ | |
type: actionTypes.REQUEST_START, | |
}); | |
try { | |
const { items } = await searchService.repoSearch(); |