added loading indicator and handle failures of repository overview

This commit is contained in:
Sebastian Sdorra
2018-08-01 10:00:53 +02:00
parent 641b3efd31
commit b1c65a3a3c
5 changed files with 50 additions and 36 deletions

View File

@@ -3,6 +3,8 @@ import { apiClient } from "../../apiclient";
import * as types from "../../modules/types";
import type { Action } from "../../types/Action";
import type { RepositoryCollection } from "../types/Repositories";
import {isPending} from "../../modules/pending";
import {getFailure} from "../../modules/failure";
export const FETCH_REPOS = "scm/repos/FETCH_REPOS";
export const FETCH_REPOS_PENDING = `${FETCH_REPOS}_${types.PENDING_SUFFIX}`;
@@ -103,3 +105,11 @@ export function getRepositoryCollection(state: Object) {
};
}
}
export function isFetchReposPending(state: Object) {
return isPending(state, FETCH_REPOS);
}
export function getFetchReposFailure(state: Object) {
return getFailure(state, FETCH_REPOS);
}

View File

@@ -8,7 +8,7 @@ import reducer, {
fetchRepos,
FETCH_REPOS_FAILURE,
fetchReposSuccess,
getRepositoryCollection
getRepositoryCollection, FETCH_REPOS, isFetchReposPending, getFetchReposFailure
} from "./repos";
import type { Repository, RepositoryCollection } from "../types/Repositories";
@@ -267,6 +267,9 @@ describe("repos reducer", () => {
});
describe("repos selectors", () => {
const error = new Error("something goes wrong");
it("should return the repositories collection", () => {
const state = {
repos: {
@@ -282,4 +285,30 @@ describe("repos selectors", () => {
const collection = getRepositoryCollection(state);
expect(collection).toEqual(repositoryCollection);
});
it("should return true, when fetch repos is pending", () => {
const state = {
pending: {
[FETCH_REPOS]: true
}
};
expect(isFetchReposPending(state)).toEqual(true);
});
it("should return false, when fetch repos is not pending", () => {
expect(isFetchReposPending({})).toEqual(false);
});
it("should return error when fetch repos did fail", () => {
const state = {
failure: {
[FETCH_REPOS]: error
}
};
expect(getFetchReposFailure(state)).toEqual(error);
});
it("should return undefined when fetch repos did not fail", () => {
expect(getFetchReposFailure({})).toBe(undefined);
});
});