From 6baf759df90f37d047eb9f41c6a6b56799ce7341 Mon Sep 17 00:00:00 2001 From: Florian Scholdei Date: Tue, 6 Oct 2020 10:27:50 +0200 Subject: [PATCH] Move FileLink.test.ts --- .../FileLink.test.ts} | 26 ++++++++++++++----- .../sources/components/content/FileLink.tsx | 4 +-- 2 files changed, 21 insertions(+), 9 deletions(-) rename scm-ui/ui-webapp/src/repos/sources/components/{FileTreeLeaf.test.ts => content/FileLink.test.ts} (62%) diff --git a/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.test.ts b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.test.ts similarity index 62% rename from scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.test.ts rename to scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.test.ts index 91d321e5f2..77dbff0867 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/FileTreeLeaf.test.ts +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.test.ts @@ -22,10 +22,22 @@ * SOFTWARE. */ -import { createLink } from "./FileTreeLeaf"; +import { createRelativeLink, createFolderLink } from "./FileLink"; import { File } from "@scm-manager/ui-types"; -describe("create link tests", () => { +describe("create relative link tests", () => { + it("should create relative link", () => { + expect(createRelativeLink("http://localhost:8081/scm/repo/scmadmin/scm-manager")).toBe( + "/scm/repo/scmadmin/scm-manager" + ); + expect(createRelativeLink("ssh://_anonymous@repo.scm-manager.org:1234/repo/public/anonymous-access")).toBe( + "/repo/public/anonymous-access" + ); + expect(createRelativeLink("ssh://server.local/project.git")).toBe("/project.git"); + }); +}); + +describe("create folder link tests", () => { function dir(path: string): File { return { name: "dir", @@ -40,13 +52,13 @@ describe("create link tests", () => { }; } - it("should create link", () => { - expect(createLink("src", dir("main"))).toBe("src/main/"); - expect(createLink("src", dir("/main"))).toBe("src/main/"); - expect(createLink("src", dir("/main/"))).toBe("src/main/"); + it("should create folder link", () => { + expect(createFolderLink("src", dir("main"))).toBe("src/main/"); + expect(createFolderLink("src", dir("/main"))).toBe("src/main/"); + expect(createFolderLink("src", dir("/main/"))).toBe("src/main/"); }); it("should return base url if the directory path is empty", () => { - expect(createLink("src", dir(""))).toBe("src/"); + expect(createFolderLink("src", dir(""))).toBe("src/"); }); }); diff --git a/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx index 8cd0ba1f0d..34ecf0a5c6 100644 --- a/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx +++ b/scm-ui/ui-webapp/src/repos/sources/components/content/FileLink.tsx @@ -46,12 +46,12 @@ const isLocalRepository = (repositoryUrl: string) => { return host === window.location.hostname; }; -const createRelativeLink = (repositoryUrl: string) => { +export const createRelativeLink = (repositoryUrl: string) => { const paths = repositoryUrl.split("/"); return "/" + paths.slice(3).join("/"); }; -const createFolderLink = (base: string, file: File) => { +export const createFolderLink = (base: string, file: File) => { let link = base; if (file.path) { let path = file.path;