Implemented editing of repos (in UI)

This commit is contained in:
Philipp Czora
2018-08-06 15:41:20 +02:00
parent ffbfdff52e
commit 9a4896b55d
9 changed files with 331 additions and 6 deletions

View File

@@ -0,0 +1,22 @@
//@flow
import React from "react";
import { NavLink } from "../../components/navigation";
import { translate } from "react-i18next";
import type { Repository } from "../types/Repositories";
type Props = { editUrl: string, t: string => string, repository: Repository };
class EditNavLink extends React.Component<Props> {
isEditable = () => {
return this.props.repository._links.update;
};
render() {
if (!this.isEditable()) {
return null;
}
const { editUrl, t } = this.props;
return <NavLink to={editUrl} label={t("edit-nav-link.label")} />;
}
}
export default translate("repos")(EditNavLink);

View File

@@ -0,0 +1,32 @@
import React from "react";
import { mount, shallow } from "enzyme";
import "../../tests/enzyme";
import "../../tests/i18n";
import EditNavLink from "./EditNavLink";
jest.mock("../../components/modals/ConfirmAlert");
jest.mock("../../components/navigation/NavLink", () => () => <div>foo</div>);
describe("EditNavLink", () => {
it("should render nothing, if the modify link is missing", () => {
const repository = {
_links: {}
};
const navLink = shallow(<EditNavLink repository={repository} editUrl="" />);
expect(navLink.text()).toBe("");
});
it("should render the navLink", () => {
const repository = {
_links: {
update: {
href: "/repositories"
}
}
};
const navLink = mount(<EditNavLink repository={repository} editUrl="" />);
expect(navLink.text()).toBe("foo");
});
});