correct tests and use index resource type

This commit is contained in:
Maren Süwer
2018-10-15 13:52:45 +02:00
parent efdc57055d
commit 09130ca283
4 changed files with 18 additions and 14 deletions

View File

@@ -13,11 +13,12 @@ import {
isFetchIndexResourcesPending isFetchIndexResourcesPending
} from "../modules/indexResource"; } from "../modules/indexResource";
import PluginLoader from "./PluginLoader"; import PluginLoader from "./PluginLoader";
import type { IndexResources } from "@scm-manager/ui-types";
type Props = { type Props = {
error: Error, error: Error,
loading: boolean, loading: boolean,
indexResources: any, indexResources: IndexResources,
// dispatcher functions // dispatcher functions
fetchIndexResources: () => void, fetchIndexResources: () => void,
@@ -34,7 +35,7 @@ class Index extends Component<Props> {
render() { render() {
const { indexResources, loading, error, t } = this.props; const { indexResources, loading, error, t } = this.props;
if (error) { if (error) {
return ( return (
<ErrorPage <ErrorPage
title={t("app.error.title")} title={t("app.error.title")}
@@ -42,10 +43,9 @@ class Index extends Component<Props> {
error={error} error={error}
/> />
); );
} } else if (loading || !indexResources) {
else if (loading || !indexResources) {
return <Loading />; return <Loading />;
} else { } else {
return ( return (
<PluginLoader> <PluginLoader>
<App /> <App />

View File

@@ -18,7 +18,7 @@ import {
Image Image
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import classNames from "classnames"; import classNames from "classnames";
import { fetchIndexResources, getLoginLink } from "../modules/indexResource"; import { getLoginLink } from "../modules/indexResource";
const styles = { const styles = {
avatar: { avatar: {

View File

@@ -8,7 +8,7 @@ import { getFailure } from "./failure";
import { import {
callFetchIndexResources, callFetchIndexResources,
FETCH_INDEXRESOURCES_SUCCESS, FETCH_INDEXRESOURCES_SUCCESS,
fetchIndexResources, fetchIndexResources, fetchIndexResourcesPending,
fetchIndexResourcesSuccess fetchIndexResourcesSuccess
} from "./indexResource"; } from "./indexResource";
@@ -156,6 +156,7 @@ export const login = (
return apiClient return apiClient
.post(loginLink, login_data) .post(loginLink, login_data)
.then(response => { .then(response => {
dispatch(fetchIndexResourcesPending())
return callFetchIndexResources(); return callFetchIndexResources();
}) })
.then(response => { .then(response => {

View File

@@ -97,16 +97,20 @@ describe("auth actions", () => {
headers: { "content-type": "application/json" } headers: { "content-type": "application/json" }
}); });
fetchMock.getOnce("/api/v2/", { const meLink = {
_links: { me: {
me: { href: "/me"
href: "/me"
}
} }
};
fetchMock.getOnce("/api/v2/", {
_links: meLink
}); });
const expectedActions = [ const expectedActions = [
{ type: LOGIN_PENDING }, { type: LOGIN_PENDING },
{ type: FETCH_INDEXRESOURCES_PENDING },
{ type: FETCH_INDEXRESOURCES_SUCCESS, payload: { _links: meLink } },
{ type: LOGIN_SUCCESS, payload: me } { type: LOGIN_SUCCESS, payload: me }
]; ];
@@ -208,8 +212,7 @@ describe("auth actions", () => {
const expectedActions = [ const expectedActions = [
{ type: LOGOUT_PENDING }, { type: LOGOUT_PENDING },
{ type: LOGOUT_SUCCESS }, { type: LOGOUT_SUCCESS },
{ type: FETCH_INDEXRESOURCES_PENDING }, { type: FETCH_INDEXRESOURCES_PENDING }
{ type: FETCH_INDEXRESOURCES_SUCCESS }
]; ];
const store = mockStore({}); const store = mockStore({});