export function feedReducer(state = feedInitialState, action) { switch (action.type) { case FETCHING_FEED_PAGE: return Object.assign({}, state, { fetchingPage: true, pageBeingFetched: action.page, errorFetchingPage: None() }); case ERROR_FETCHING_FEED_PAGE: return Object.assign({}, state, { fetchingPage: false, pageBeingFetched: None(), errorFetchingPage: Some(action.error) }); case FEED_PAGE_FETCHED: return Object.assign({}, state, { fetchingPage: false, pageBeingFetched: None(), errorFetchingPage: None(), publications: appendFeedPage(state, action.page), lastPageFetched: Some(action.page) }); default: return state; } }
it("initializes the store using the initial state configured", () => { const store = givenTheComicTimeStore(); expect(store.getState().publicationDetail).toEqual({ publicationSelected: None(), fetchingPublication: true, errorFetchingPublication: None(), downloadsInitiated: 0, issuesBeingDownloaded: [], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {}, lastIssuesDownloadedProperly: [], errorsDownloadingIssue: [] }); });
it("saves the error found while downloading the issue if something went wrong getting the issue detailed information", async () => { const store = givenTheComicTimeStore(); givenTheGetIssueReturns(Left(new NetworkError())); await downloadIssueSummary(store, anyIssueSummary); expect(store.getState().publicationDetail).toEqual({ publicationSelected: None(), fetchingPublication: true, errorFetchingPublication: None(), downloadsInitiated: 1, issuesBeingDownloaded: [], lastIssuesDownloadedProperly: [], errorsDownloadingIssue: [anyIssueSummary], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {} }); });
it("saves the issue downloaded as last issue being downloaded if it is downloaded properly", async () => { const store = givenTheComicTimeStore(); givenTheGetIssueReturns(Right(anyIssue)); givenTheDownloadCbzFileReturns(Right()); await downloadIssueSummary(store, anyIssueSummary); expect(store.getState().publicationDetail).toEqual({ publicationSelected: None(), fetchingPublication: true, errorFetchingPublication: None(), downloadsInitiated: 1, issuesBeingDownloaded: [], lastIssuesDownloadedProperly: [anyIssueSummary], errorsDownloadingIssue: [], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {} }); });
it("saves an error if there is something wrong while fetching the publication by id", async () => { const store = givenTheComicTimeStore(); givenTheFetchPublicationReturns(Left(new NetworkError())); await getPublicationById(store, anyPublication); expect(store.getState().publicationDetail).toEqual({ publicationSelected: None(), fetchingPublication: false, errorFetchingPublication: Some(""), downloadsInitiated: 0, issuesBeingDownloaded: [], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {}, lastIssuesDownloadedProperly: [], errorsDownloadingIssue: [] }); });
it("saves the publication fetched", async () => { const store = givenTheComicTimeStore(); givenTheFetchPublicationReturns(Right(anyPublication)); await getPublicationById(store, anyPublication); expect(store.getState().publicationDetail).toEqual({ publicationSelected: Some(anyPublication), fetchingPublication: false, errorFetchingPublication: None(), downloadsInitiated: 0, issuesBeingDownloaded: [], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {}, lastIssuesDownloadedProperly: [], errorsDownloadingIssue: [] }); });
export function publicationDetailReducer( state = publicationDetailInitialState, action ) { switch (action.type) { case FETCHING_PUBLICATION_BY_ID: return Object.assign({}, state, { publicationSelected: None(), fetchingPublication: true, errorFetchingPublication: None() }); case PUBLICATION_FETCHED: return Object.assign({}, state, { publicationSelected: action.publication, fetchingPublication: false, errorFetchingPublication: None() }); case ERROR_FETCHING_PUBLICATION: return Object.assign({}, state, { publicationSelected: None(), fetchingPublication: false, errorFetchingPublication: action.error }); case DOWNLOADING_ISSUE: return Object.assign({}, state, { downloadsInitiated: state.downloadsInitiated + 1, issuesBeingDownloaded: addIssueToTheDownloadsList(state, action.issue), lastIssuesDownloadedProperly: removeIssueFromIssuesDownloadedProperlyList( state, action.issue ), errorsDownloadingIssue: removeIssueFromIssuesDownloadErrorList( state, action.issue ), issuePageDownloadStatus: resetIssuePageDownloadStatus( state, action.issue ), issuePercentageDownloadStatus: resetIssuePercentageDownloadStatus( state, action.issue ) }); case ISSUE_DOWNLOADED_PROPERLY: return Object.assign({}, state, { issuesBeingDownloaded: removeIssueFromIssuesBeingDownloaded( state, action.issue ), lastIssuesDownloadedProperly: addIssueToTheIssuesDownloadedList( state, action.issue ), errorsDownloadingIssue: removeIssueFromIssuesDownloadErrorList( state, action.issue ) }); case ERROR_DOWNLOADING_ISSUE: return Object.assign({}, state, { issuesBeingDownloaded: removeIssueFromIssuesBeingDownloaded( state, action.issue ), lastIssuesDownloadedProperly: removeIssueFromIssuesDownloadedProperlyList( state, action.issue ), errorsDownloadingIssue: addErrorToTheErrorDownloadingIssueList( state, action.issue ), issuePageDownloadStatus: resetIssuePageDownloadStatus( state, action.issue ), issuePercentageDownloadStatus: resetIssuePercentageDownloadStatus( state, action.issue ) }); case UPDATE_ISSUE_DOWNLOAD: return Object.assign({}, state, { issuePageDownloadStatus: updateIssuePageDownloadStatus( state, action.update ), issuePercentageDownloadStatus: updateIssuePercentageDownloadStats( state, action.update ) }); default: return state; } }
}; } function updateIssueDownload(issue, lastPageDownloaded, totalNumberOfPages) { return { type: UPDATE_ISSUE_DOWNLOAD, update: new IssueDownloadUpdate( issue, lastPageDownloaded, totalNumberOfPages ) }; } const publicationDetailInitialState = { publicationSelected: None(), fetchingPublication: true, errorFetchingPublication: None(), downloadsInitiated: 0, issuesBeingDownloaded: [], issuePageDownloadStatus: {}, issuePercentageDownloadStatus: {}, lastIssuesDownloadedProperly: [], errorsDownloadingIssue: [] }; export function publicationDetailReducer( state = publicationDetailInitialState, action ) { switch (action.type) {
return { type: FEED_PAGE_FETCHED, page: page }; } function errorFetchingPage(error) { return { type: ERROR_FETCHING_FEED_PAGE, error: error }; } const feedInitialState = { fetchingPage: false, pageBeingFetched: None(), publications: [], lastPageFetched: None(), errorFetchingPage: None() }; export function feedReducer(state = feedInitialState, action) { switch (action.type) { case FETCHING_FEED_PAGE: return Object.assign({}, state, { fetchingPage: true, pageBeingFetched: action.page, errorFetchingPage: None() }); case ERROR_FETCHING_FEED_PAGE: return Object.assign({}, state, {