From e5dcae6874ccf517a818391923fe1cf8bdeebacf Mon Sep 17 00:00:00 2001 From: Philipp Czora Date: Wed, 7 Nov 2018 16:42:26 +0100 Subject: [PATCH] Fixed flow issues in tests --- .../packages/ui-types/src/Sources.js | 4 +- .../components/RepositoryNavLink.test.js | 8 ++++ .../src/repos/sources/components/FileTree.js | 2 +- .../sources/components/FileTreeLeaf.test.js | 8 +++- scm-ui/src/repos/sources/modules/sources.js | 2 +- .../src/repos/sources/modules/sources.test.js | 46 +++++++++++++------ 6 files changed, 50 insertions(+), 20 deletions(-) diff --git a/scm-ui-components/packages/ui-types/src/Sources.js b/scm-ui-components/packages/ui-types/src/Sources.js index c8b3fafe0c..83274290df 100644 --- a/scm-ui-components/packages/ui-types/src/Sources.js +++ b/scm-ui-components/packages/ui-types/src/Sources.js @@ -1,6 +1,6 @@ // @flow -import type { Collection, Links } from "./hal"; +import type { Links } from "./hal"; // TODO ?? check ?? links export type SubRepository = { @@ -20,6 +20,6 @@ export type File = { subRepository?: SubRepository, // TODO _links: Links, _embedded: { - children: File[] + children: ?File[] } }; diff --git a/scm-ui/src/repos/components/RepositoryNavLink.test.js b/scm-ui/src/repos/components/RepositoryNavLink.test.js index 0d93cb7c4d..a4c060dfe0 100644 --- a/scm-ui/src/repos/components/RepositoryNavLink.test.js +++ b/scm-ui/src/repos/components/RepositoryNavLink.test.js @@ -11,6 +11,9 @@ describe("RepositoryNavLink", () => { it("should render nothing, if the sources link is missing", () => { const repository = { + namespace: "Namespace", + name: "Repo", + type: "GIT", _links: {} }; @@ -20,6 +23,7 @@ describe("RepositoryNavLink", () => { linkName="sources" to="/sources" label="Sources" + activeOnlyWhenExact={true} />, options.get() ); @@ -28,6 +32,9 @@ describe("RepositoryNavLink", () => { it("should render the navLink", () => { const repository = { + namespace: "Namespace", + name: "Repo", + type: "GIT", _links: { sources: { href: "/sources" @@ -41,6 +48,7 @@ describe("RepositoryNavLink", () => { linkName="sources" to="/sources" label="Sources" + activeOnlyWhenExact={true} />, options.get() ); diff --git a/scm-ui/src/repos/sources/components/FileTree.js b/scm-ui/src/repos/sources/components/FileTree.js index e9b5c70d3d..1dd11870ae 100644 --- a/scm-ui/src/repos/sources/components/FileTree.js +++ b/scm-ui/src/repos/sources/components/FileTree.js @@ -96,7 +96,7 @@ class FileTree extends React.Component { }); } - if (tree._embedded) { + if (tree._embedded && tree._embedded.children) { files.push(...tree._embedded.children.sort(compareFiles)); } diff --git a/scm-ui/src/repos/sources/components/FileTreeLeaf.test.js b/scm-ui/src/repos/sources/components/FileTreeLeaf.test.js index d5004521c8..ba36e7a2db 100644 --- a/scm-ui/src/repos/sources/components/FileTreeLeaf.test.js +++ b/scm-ui/src/repos/sources/components/FileTreeLeaf.test.js @@ -8,7 +8,13 @@ describe("create link tests", () => { return { name: "dir", path: path, - directory: true + directory: true, + length: 1, + revision: "1a", + _links: {}, + _embedded: { + children: [] + } }; } diff --git a/scm-ui/src/repos/sources/modules/sources.js b/scm-ui/src/repos/sources/modules/sources.js index 641c1550b6..5868c56df3 100644 --- a/scm-ui/src/repos/sources/modules/sources.js +++ b/scm-ui/src/repos/sources/modules/sources.js @@ -91,7 +91,7 @@ export default function reducer( state: any = {}, action: Action = { type: "UNKNOWN" } ): any { - if (action.type === FETCH_SOURCES_SUCCESS) { + if (action.itemId && action.type === FETCH_SOURCES_SUCCESS) { return { [action.itemId]: action.payload, ...state diff --git a/scm-ui/src/repos/sources/modules/sources.test.js b/scm-ui/src/repos/sources/modules/sources.test.js index 1a5c81e908..dea63eb3d0 100644 --- a/scm-ui/src/repos/sources/modules/sources.test.js +++ b/scm-ui/src/repos/sources/modules/sources.test.js @@ -33,7 +33,13 @@ const repository: Repository = { }; const collection = { + name: "src", + path: "src", + directory: true, + description: "foo", + length: 176, revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4", + subRepository: undefined, _links: { self: { href: @@ -41,20 +47,24 @@ const collection = { } }, _embedded: { - files: [ + children: [ { name: "src", path: "src", directory: true, - description: null, + description: "", length: 176, - lastModified: null, - subRepository: null, + revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4", + lastModified: "", + subRepository: undefined, _links: { self: { href: "http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src" } + }, + _embedded: { + children: [] } }, { @@ -63,8 +73,9 @@ const collection = { directory: false, description: "bump version", length: 780, + revision: "76aae4bb4ceacf0e88938eb5b6832738b7d537b4", lastModified: "2017-07-31T11:17:19Z", - subRepository: null, + subRepository: undefined, _links: { self: { href: @@ -74,6 +85,9 @@ const collection = { href: "http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/history/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/package.json" } + }, + _embedded: { + children: [] } } ] @@ -92,7 +106,9 @@ const noDirectory: File = { "http://localhost:8081/scm/rest/api/v2/repositories/scm/core/sources/76aae4bb4ceacf0e88938eb5b6832738b7d537b4/src" } }, - _embedded: collection + _embedded: { + children: [] + } }; describe("sources fetch", () => { @@ -116,7 +132,7 @@ describe("sources fetch", () => { ]; const store = mockStore({}); - return store.dispatch(fetchSources(repository)).then(() => { + return store.dispatch(fetchSources(repository, "", "")).then(() => { expect(store.getActions()).toEqual(expectedActions); }); }); @@ -145,7 +161,7 @@ describe("sources fetch", () => { }); const store = mockStore({}); - return store.dispatch(fetchSources(repository)).then(() => { + return store.dispatch(fetchSources(repository, "", "")).then(() => { const actions = store.getActions(); expect(actions[0].type).toBe(FETCH_SOURCES_PENDING); expect(actions[1].type).toBe(FETCH_SOURCES_FAILURE); @@ -166,7 +182,7 @@ describe("reducer tests", () => { "scm/core/_/": collection }; expect( - reducer({}, fetchSourcesSuccess(repository, null, null, collection)) + reducer({}, fetchSourcesSuccess(repository, "", "", collection)) ).toEqual(expectedState); }); @@ -207,7 +223,7 @@ describe("selector tests", () => { }); it("should return null", () => { - expect(getSources({}, repository)).toBeFalsy(); + expect(getSources({}, repository, "", "")).toBeFalsy(); }); it("should return the source collection without revision and path", () => { @@ -216,7 +232,7 @@ describe("selector tests", () => { "scm/core/_/": collection } }; - expect(getSources(state, repository)).toBe(collection); + expect(getSources(state, repository, "", "")).toBe(collection); }); it("should return the source collection with revision and path", () => { @@ -234,11 +250,11 @@ describe("selector tests", () => { [FETCH_SOURCES + "/scm/core/_/"]: true } }; - expect(isFetchSourcesPending(state, repository)).toEqual(true); + expect(isFetchSourcesPending(state, repository, "", "")).toEqual(true); }); it("should return false, when fetch sources is not pending", () => { - expect(isFetchSourcesPending({}, repository)).toEqual(false); + expect(isFetchSourcesPending({}, repository, "", "")).toEqual(false); }); const error = new Error("incredible error from hell"); @@ -249,10 +265,10 @@ describe("selector tests", () => { [FETCH_SOURCES + "/scm/core/_/"]: error } }; - expect(getFetchSourcesFailure(state, repository)).toEqual(error); + expect(getFetchSourcesFailure(state, repository, "", "")).toEqual(error); }); it("should return undefined when fetch sources did not fail", () => { - expect(getFetchSourcesFailure({}, repository)).toBe(undefined); + expect(getFetchSourcesFailure({}, repository, "", "")).toBe(undefined); }); });