From 09130ca2830df0b8fef1daca472fe20975b58e71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maren=20S=C3=BCwer?= Date: Mon, 15 Oct 2018 13:52:45 +0200 Subject: [PATCH] correct tests and use index resource type --- scm-ui/src/containers/Index.js | 10 +++++----- scm-ui/src/containers/Login.js | 2 +- scm-ui/src/modules/auth.js | 3 ++- scm-ui/src/modules/auth.test.js | 17 ++++++++++------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/scm-ui/src/containers/Index.js b/scm-ui/src/containers/Index.js index 55d5fc1ab8..0fe6364f6e 100644 --- a/scm-ui/src/containers/Index.js +++ b/scm-ui/src/containers/Index.js @@ -13,11 +13,12 @@ import { isFetchIndexResourcesPending } from "../modules/indexResource"; import PluginLoader from "./PluginLoader"; +import type { IndexResources } from "@scm-manager/ui-types"; type Props = { error: Error, loading: boolean, - indexResources: any, + indexResources: IndexResources, // dispatcher functions fetchIndexResources: () => void, @@ -34,7 +35,7 @@ class Index extends Component { render() { const { indexResources, loading, error, t } = this.props; - if (error) { + if (error) { return ( { error={error} /> ); - } - else if (loading || !indexResources) { + } else if (loading || !indexResources) { return ; - } else { + } else { return ( diff --git a/scm-ui/src/containers/Login.js b/scm-ui/src/containers/Login.js index 16f586e433..8a06478045 100644 --- a/scm-ui/src/containers/Login.js +++ b/scm-ui/src/containers/Login.js @@ -18,7 +18,7 @@ import { Image } from "@scm-manager/ui-components"; import classNames from "classnames"; -import { fetchIndexResources, getLoginLink } from "../modules/indexResource"; +import { getLoginLink } from "../modules/indexResource"; const styles = { avatar: { diff --git a/scm-ui/src/modules/auth.js b/scm-ui/src/modules/auth.js index 47461106c0..fd5068aeb8 100644 --- a/scm-ui/src/modules/auth.js +++ b/scm-ui/src/modules/auth.js @@ -8,7 +8,7 @@ import { getFailure } from "./failure"; import { callFetchIndexResources, FETCH_INDEXRESOURCES_SUCCESS, - fetchIndexResources, + fetchIndexResources, fetchIndexResourcesPending, fetchIndexResourcesSuccess } from "./indexResource"; @@ -156,6 +156,7 @@ export const login = ( return apiClient .post(loginLink, login_data) .then(response => { + dispatch(fetchIndexResourcesPending()) return callFetchIndexResources(); }) .then(response => { diff --git a/scm-ui/src/modules/auth.test.js b/scm-ui/src/modules/auth.test.js index 99695bb4d4..1839701e0a 100644 --- a/scm-ui/src/modules/auth.test.js +++ b/scm-ui/src/modules/auth.test.js @@ -97,16 +97,20 @@ describe("auth actions", () => { headers: { "content-type": "application/json" } }); - fetchMock.getOnce("/api/v2/", { - _links: { - me: { - href: "/me" - } + const meLink = { + me: { + href: "/me" } + }; + + fetchMock.getOnce("/api/v2/", { + _links: meLink }); const expectedActions = [ { type: LOGIN_PENDING }, + { type: FETCH_INDEXRESOURCES_PENDING }, + { type: FETCH_INDEXRESOURCES_SUCCESS, payload: { _links: meLink } }, { type: LOGIN_SUCCESS, payload: me } ]; @@ -208,8 +212,7 @@ describe("auth actions", () => { const expectedActions = [ { type: LOGOUT_PENDING }, { type: LOGOUT_SUCCESS }, - { type: FETCH_INDEXRESOURCES_PENDING }, - { type: FETCH_INDEXRESOURCES_SUCCESS } + { type: FETCH_INDEXRESOURCES_PENDING } ]; const store = mockStore({});