Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit ports in constructed URL #383

Merged
merged 4 commits into from
Apr 12, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add UrlToRepo tests
See also: GH-259
  • Loading branch information
alexanderchiu committed Apr 1, 2021
commit 8c44588a04f365cc37505b6e083e2fc47e18ec85
70 changes: 70 additions & 0 deletions ui/assets/js/common.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,73 @@ describe("ExpandVars", () => {
expect(ExpandVars(template, {})).toBe(template);
});
});

describe("UrlToRepo", () => {
test("Generate url from repo with default values", () => {
const repo = {
url: "https://www.github.com/YourOrganization/RepoOne.git",
"url-pattern":
{
"base-url": "{url}/blob/{rev}/{path}{anchor}",
anchor: "#L{line}"
}
};
const path = "test.txt"
const line = null
const rev = "master"
expect(UrlToRepo(repo, path, line, rev)).toBe(
"https://www.github.com/YourOrganization/RepoOne/blob/master/test.txt"
);
});

test("Generate url from repo with default values and line", () => {
const repo = {
url: "https://www.github.com/YourOrganization/RepoOne.git",
"url-pattern":
{
"base-url": "{url}/blob/{rev}/{path}{anchor}",
anchor: "#L{line}"
}
};
const path = "test.txt"
const line = "12"
const rev = "master"
expect(UrlToRepo(repo, path, line, rev)).toBe(
"https://www.github.com/YourOrganization/RepoOne/blob/master/test.txt#L12"
);
});

test("Generate url from for ssh style repo with default values", () => {
const repo = {
url: "git@github.com:YourOrganization/RepoOne.git",
"url-pattern":
{
"base-url": "{url}/blob/{rev}/{path}{anchor}",
anchor: "#L{line}"
}
};
const path = "test.txt"
const line = null
const rev = "master"
expect(UrlToRepo(repo, path, line, rev)).toBe(
"//github.com/YourOrganization/RepoOne/blob/master/test.txt"
);
});

test("Generate url from for ssh bitbucket mercurial style repo", () => {
const repo = {
url: "ssh://hg@bitbucket.org/YourOrganization/RepoOne",
"url-pattern":
{
"base-url" : "{url}/src/master/{path}{anchor}",
"anchor" : "#{filename}-{line}"
}
};
const path = "test.txt"
const line = null
const rev = "master"
expect(UrlToRepo(repo, path, line, rev)).toBe(
"//bitbucket.org/YourOrganization/RepoOne/src/master/test.txt"
);
});
});