mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-07 05:55:44 +01:00
merge with branch 2.0.0-m3
This commit is contained in:
@@ -9,9 +9,18 @@ type Props = {
|
||||
};
|
||||
|
||||
class Image extends React.Component<Props> {
|
||||
|
||||
createImageSrc = () => {
|
||||
const { src } = this.props;
|
||||
if (src.startsWith("http")) {
|
||||
return src;
|
||||
}
|
||||
return withContextPath(src);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { src, alt, className } = this.props;
|
||||
return <img className={className} src={withContextPath(src)} alt={alt} />;
|
||||
const { alt, className } = this.props;
|
||||
return <img className={className} src={this.createImageSrc()} alt={alt} />;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,21 @@ export function withContextPath(path: string) {
|
||||
return contextPath + path;
|
||||
}
|
||||
|
||||
export function withEndingSlash(url: string) {
|
||||
if (url.endsWith("/")) {
|
||||
return url;
|
||||
}
|
||||
return url + "/";
|
||||
}
|
||||
|
||||
export function concat(base: string, ...parts: string[]) {
|
||||
let url = base;
|
||||
for ( let p of parts) {
|
||||
url = withEndingSlash(url) + p;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
export function getPageFromMatch(match: any) {
|
||||
let page = parseInt(match.params.page, 10);
|
||||
if (isNaN(page) || !page) {
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
// @flow
|
||||
import { getPageFromMatch } from "./urls";
|
||||
import { concat, getPageFromMatch, withEndingSlash } from "./urls";
|
||||
|
||||
describe("tests for withEndingSlash", () => {
|
||||
|
||||
it("should append missing slash", () => {
|
||||
expect(withEndingSlash("abc")).toBe("abc/");
|
||||
});
|
||||
|
||||
it("should not append a second slash", () => {
|
||||
expect(withEndingSlash("abc/")).toBe("abc/");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("concat tests", () => {
|
||||
|
||||
it("should concat the parts to a single url", () => {
|
||||
expect(concat("a")).toBe("a");
|
||||
expect(concat("a", "b")).toBe("a/b");
|
||||
expect(concat("a", "b", "c")).toBe("a/b/c");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("tests for getPageFromMatch", () => {
|
||||
function createMatch(page: string) {
|
||||
|
||||
Reference in New Issue
Block a user