mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 15:35:49 +01:00
Move FileLink.test.ts
This commit is contained in:
@@ -22,10 +22,22 @@
|
|||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { createLink } from "./FileTreeLeaf";
|
import { createRelativeLink, createFolderLink } from "./FileLink";
|
||||||
import { File } from "@scm-manager/ui-types";
|
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 {
|
function dir(path: string): File {
|
||||||
return {
|
return {
|
||||||
name: "dir",
|
name: "dir",
|
||||||
@@ -40,13 +52,13 @@ describe("create link tests", () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should create link", () => {
|
it("should create folder link", () => {
|
||||||
expect(createLink("src", dir("main"))).toBe("src/main/");
|
expect(createFolderLink("src", dir("main"))).toBe("src/main/");
|
||||||
expect(createLink("src", dir("/main"))).toBe("src/main/");
|
expect(createFolderLink("src", dir("/main"))).toBe("src/main/");
|
||||||
expect(createLink("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", () => {
|
it("should return base url if the directory path is empty", () => {
|
||||||
expect(createLink("src", dir(""))).toBe("src/");
|
expect(createFolderLink("src", dir(""))).toBe("src/");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -46,12 +46,12 @@ const isLocalRepository = (repositoryUrl: string) => {
|
|||||||
return host === window.location.hostname;
|
return host === window.location.hostname;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createRelativeLink = (repositoryUrl: string) => {
|
export const createRelativeLink = (repositoryUrl: string) => {
|
||||||
const paths = repositoryUrl.split("/");
|
const paths = repositoryUrl.split("/");
|
||||||
return "/" + paths.slice(3).join("/");
|
return "/" + paths.slice(3).join("/");
|
||||||
};
|
};
|
||||||
|
|
||||||
const createFolderLink = (base: string, file: File) => {
|
export const createFolderLink = (base: string, file: File) => {
|
||||||
let link = base;
|
let link = base;
|
||||||
if (file.path) {
|
if (file.path) {
|
||||||
let path = file.path;
|
let path = file.path;
|
||||||
|
|||||||
Reference in New Issue
Block a user