Update tests and create new FooterDonateLink component

Signed-off-by: Eric Stout <ericwstout@gmail.com>
This commit is contained in:
Eric Stout
2019-09-04 22:30:29 -05:00
parent 3485679a4e
commit 96febff5ae
4 changed files with 63 additions and 13 deletions
+2 -9
View File
@@ -11,6 +11,7 @@
import React, { Suspense } from "react";
import { withTranslation } from "react-i18next";
import FooterUpdateStatus from "./FooterUpdateStatus";
import FooterDonateLink from "./FooterDonateLink";
const Footer = (props: any) => {
const { t } = props;
@@ -20,15 +21,7 @@ const Footer = (props: any) => {
<div>
<i className="fab fa-paypal" />
<strong>
<a
id="paypalDonation"
href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3J2L3Z4DHW9UY"
target="_blank"
rel="noopener noreferrer"
>
&nbsp;
{t("Donate")}
</a>
<FooterDonateLink t={t} />
</strong>{" "}
{t("if you found this useful")}
</div>
@@ -0,0 +1,28 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* Web Interface
* Footer Donate Link component
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
import React from "react";
const FooterDonateLink = (props: any) => {
const { t } = props;
return (
<a
id="paypalDonation"
href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=3J2L3Z4DHW9UY"
target="_blank"
rel="noopener noreferrer"
>
&nbsp;
{t("Donate")}
</a>
);
};
export default FooterDonateLink;
@@ -0,0 +1,29 @@
/* Pi-hole: A black hole for Internet advertisements
* (c) 2019 Pi-hole, LLC (https://pi-hole.net)
* Network-wide ad blocking via your own hardware.
*
* Web Interface
* Footer component test
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
import React from "react";
import { shallow } from "enzyme";
import FooterDonateLink from "../FooterDonateLink";
it("renders without crashing", () => {
shallow(<FooterDonateLink t={(text: string) => text} />);
});
it("opens a new tab", () => {
expect(
shallow(<FooterDonateLink t={(text: string) => text} />).prop("target")
).toBe("_blank");
});
it("opens new tab securely", () => {
expect(
shallow(<FooterDonateLink t={(text: string) => text} />).prop("rel")
).toBe("noopener noreferrer");
});
@@ -14,15 +14,15 @@ import * as React from "react";
import { Link } from "react-router-dom";
it("renders as null if no update is available", () => {
const wrapper = shallow(
<FooterUpdateStatus updateAvailable={false} />
).dive();
const wrapper = shallow(<FooterUpdateStatus updateAvailable={false} />);
expect(wrapper).toBeEmptyRender();
});
it("renders a link to the versions page if there is an update", () => {
const wrapper = shallow(<FooterUpdateStatus updateAvailable={true} />).dive();
const wrapper = shallow(
<FooterUpdateStatus t={(text: string) => text} updateAvailable={true} />
);
expect(wrapper.find(Link).props().to).toEqual("/settings/versions");
});