remove unused code
parent
800625e8a1
commit
de6f886586
|
@ -1,58 +1,72 @@
|
|||
const mockState = {
|
||||
auth: {
|
||||
token: {
|
||||
unencoded: { iss: "http://geocities.com" }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jest.mock("axios", () => ({
|
||||
interceptors: {
|
||||
response: { use: jest.fn() },
|
||||
request: { use: jest.fn() }
|
||||
},
|
||||
get() { return Promise.resolve({ data: mockState }); }
|
||||
}));
|
||||
|
||||
jest.mock("../../session", () => ({
|
||||
Session: {
|
||||
fetchStoredToken: jest.fn(),
|
||||
getAll: () => undefined,
|
||||
clear: jest.fn()
|
||||
clear: jest.fn(),
|
||||
}
|
||||
}));
|
||||
|
||||
jest.mock("../../auth/actions", () => ({
|
||||
didLogin: jest.fn(),
|
||||
setToken: jest.fn()
|
||||
setToken: jest.fn(),
|
||||
}));
|
||||
|
||||
jest.mock("../../refresh_token", () => ({ maybeRefreshToken: jest.fn() }));
|
||||
|
||||
let mockTimeout = Promise.resolve({ token: "fake token data" });
|
||||
jest.mock("promise-timeout", () => ({ timeout: () => mockTimeout }));
|
||||
|
||||
import { ready, storeToken } from "../actions";
|
||||
import { setToken, didLogin } from "../../auth/actions";
|
||||
import { Session } from "../../session";
|
||||
import { auth } from "../../__test_support__/fake_state/token";
|
||||
import { fakeState } from "../../__test_support__/fake_state";
|
||||
|
||||
describe("Actions", () => {
|
||||
it("calls didLogin()", () => {
|
||||
jest.resetAllMocks();
|
||||
describe("ready()", () => {
|
||||
it("uses new token", async () => {
|
||||
const fakeAuth = { token: "fake token data" };
|
||||
mockTimeout = Promise.resolve(fakeAuth);
|
||||
const dispatch = jest.fn();
|
||||
const thunk = ready();
|
||||
thunk(dispatch, fakeState);
|
||||
expect(setToken).toHaveBeenCalled();
|
||||
const state = fakeState();
|
||||
console.warn = jest.fn();
|
||||
await thunk(dispatch, () => state);
|
||||
expect(setToken).toHaveBeenCalledWith(fakeAuth);
|
||||
expect(didLogin).toHaveBeenCalledWith(fakeAuth, dispatch);
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(Session.clear).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Calls Session.clear() when missing auth", () => {
|
||||
jest.resetAllMocks();
|
||||
it("uses old token", async () => {
|
||||
mockTimeout = Promise.reject({ token: "not used" });
|
||||
const dispatch = jest.fn();
|
||||
const thunk = ready();
|
||||
const state = fakeState();
|
||||
console.warn = jest.fn();
|
||||
await thunk(dispatch, () => state);
|
||||
expect(setToken).toHaveBeenLastCalledWith(state.auth);
|
||||
expect(didLogin).toHaveBeenCalledWith(state.auth, dispatch);
|
||||
expect(console.warn)
|
||||
.toHaveBeenCalledWith(expect.stringContaining("Can't refresh token."));
|
||||
expect(Session.clear).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("calls Session.clear() when missing auth", () => {
|
||||
const dispatch = jest.fn();
|
||||
const state = fakeState();
|
||||
delete state.auth;
|
||||
const getState = () => state;
|
||||
const thunk = ready();
|
||||
console.warn = jest.fn();
|
||||
thunk(dispatch, getState);
|
||||
expect(setToken).not.toHaveBeenCalled();
|
||||
expect(didLogin).not.toHaveBeenCalled();
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(Session.clear).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("storeToken()", () => {
|
||||
it("stores token", () => {
|
||||
const old = auth;
|
||||
old.token.unencoded.jti = "old";
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
import * as React from "react";
|
||||
import { shallow } from "enzyme";
|
||||
import { RetryBtn } from "../retry_btn";
|
||||
import { SpecialStatus } from "farmbot";
|
||||
|
||||
describe("<RetryBtn/>", () => {
|
||||
it("is green before saving", () => {
|
||||
const props = {
|
||||
flags: [true],
|
||||
onClick: jest.fn(),
|
||||
status: SpecialStatus.SAVED
|
||||
};
|
||||
const el = shallow(<RetryBtn {...props} />);
|
||||
expect(el.find(".green").length).toBe(1);
|
||||
expect(el.find(".yellow").length).toBe(0);
|
||||
expect(el.find(".red").length).toBe(0);
|
||||
});
|
||||
|
||||
it("is yellow during save", () => {
|
||||
const props = {
|
||||
flags: [false, true],
|
||||
onClick: jest.fn(),
|
||||
status: SpecialStatus.SAVING
|
||||
};
|
||||
const el = shallow(<RetryBtn {...props} />);
|
||||
expect(el.find(".green").length).toBe(0);
|
||||
expect(el.find(".yellow").length).toBe(1);
|
||||
expect(el.find(".red").length).toBe(0);
|
||||
});
|
||||
|
||||
it("is red when problems arise", () => {
|
||||
const props = {
|
||||
flags: [true, false],
|
||||
onClick: jest.fn(),
|
||||
status: SpecialStatus.SAVED
|
||||
};
|
||||
const el = shallow(<RetryBtn {...props} />);
|
||||
expect(el.find(".green").length).toBe(0);
|
||||
expect(el.find(".yellow").length).toBe(0);
|
||||
expect(el.find(".red").length).toBe(1);
|
||||
});
|
||||
});
|
|
@ -1,18 +0,0 @@
|
|||
import * as React from "react";
|
||||
import { SpecialStatus } from "farmbot";
|
||||
import { t } from "../../i18next_wrapper";
|
||||
|
||||
interface RetryBtnProps {
|
||||
flags: boolean[];
|
||||
onClick(): void;
|
||||
status: SpecialStatus;
|
||||
}
|
||||
|
||||
export function RetryBtn(props: RetryBtnProps) {
|
||||
const failures = props.flags.includes(false);
|
||||
const color = failures ? "red" : "green";
|
||||
const css = props.status === "SAVING" ? "yellow" : color;
|
||||
return <button className={css + " fb-button"} onClick={props.onClick}>
|
||||
{t("Check Again")}
|
||||
</button>;
|
||||
}
|
|
@ -23,8 +23,6 @@ import {
|
|||
GardenMapLegend, ZoomControls, PointsSubMenu
|
||||
} from "../garden_map_legend";
|
||||
import { GardenMapLegendProps } from "../../interfaces";
|
||||
import { clickButton } from "../../../../__test_support__/helpers";
|
||||
import { history } from "../../../../history";
|
||||
import { BooleanSetting } from "../../../../session_keys";
|
||||
import {
|
||||
fakeTimeSettings
|
||||
|
@ -96,15 +94,6 @@ describe("<ZoomControls />", () => {
|
|||
});
|
||||
|
||||
describe("<PointsSubMenu />", () => {
|
||||
it("navigates to point creator", () => {
|
||||
const wrapper = mount(<PointsSubMenu
|
||||
toggle={jest.fn()}
|
||||
getConfigValue={jest.fn()} />);
|
||||
clickButton(wrapper, 0, "point creator");
|
||||
expect(history.push).toHaveBeenCalledWith(
|
||||
"/app/designer/points/add");
|
||||
});
|
||||
|
||||
it("shows historic points", () => {
|
||||
const toggle = jest.fn();
|
||||
const wrapper = shallow(<PointsSubMenu
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
import * as React from "react";
|
||||
import { LayerToggle } from "../legend/layer_toggle";
|
||||
import { GardenMapLegendProps } from "../interfaces";
|
||||
import { history } from "../../../history";
|
||||
import { atMaxZoom, atMinZoom } from "../zoom";
|
||||
import { ImageFilterMenu } from "../layers/images/image_filter_menu";
|
||||
import { BugsControls } from "../easter_eggs/bugs";
|
||||
import { State } from "../../interfaces";
|
||||
import { MoveModeLink } from "../../move_to";
|
||||
import { SavedGardensLink } from "../../saved_gardens/saved_gardens";
|
||||
import { GetWebAppConfigValue } from "../../../config_storage/actions";
|
||||
import { BooleanSetting } from "../../../session_keys";
|
||||
import { DevSettings } from "../../../account/dev/dev_support";
|
||||
|
@ -40,11 +38,6 @@ export const PointsSubMenu = ({ toggle, getConfigValue }: {
|
|||
getConfigValue: GetWebAppConfigValue
|
||||
}) =>
|
||||
<div className="map-points-submenu">
|
||||
{!DevSettings.futureFeaturesEnabled() &&
|
||||
<button className={"fb-button green"}
|
||||
onClick={() => history.push("/app/designer/points/add")}>
|
||||
{t("Point Creator")}
|
||||
</button>}
|
||||
<LayerToggle
|
||||
value={!!getConfigValue(BooleanSetting.show_historic_points)}
|
||||
label={t("Historic Points?")}
|
||||
|
@ -111,7 +104,6 @@ export function GardenMapLegend(props: GardenMapLegendProps) {
|
|||
<ZoomControls zoom={props.zoom} getConfigValue={props.getConfigValue} />
|
||||
<LayerToggles {...props} />
|
||||
<MoveModeLink />
|
||||
<SavedGardensLink />
|
||||
<BugsControls />
|
||||
</div>
|
||||
</div>;
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
import * as React from "react";
|
||||
import { mount } from "enzyme";
|
||||
import {
|
||||
RawAddWeed as AddWeed, AddWeedProps, mapStateToProps
|
||||
} from "../weeds_add";
|
||||
import { fakeState } from "../../../__test_support__/fake_state";
|
||||
|
||||
describe("<AddWeed />", () => {
|
||||
const fakeProps = (): AddWeedProps => ({
|
||||
dispatch: jest.fn(),
|
||||
});
|
||||
|
||||
it("renders", () => {
|
||||
const wrapper = mount(<AddWeed {...fakeProps()} />);
|
||||
expect(wrapper.text()).toContain("Add");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mapStateToProps()", () => {
|
||||
it("returns props", () => {
|
||||
const state = fakeState();
|
||||
const props = mapStateToProps(state);
|
||||
expect(props.dispatch).toEqual(expect.any(Function));
|
||||
});
|
||||
});
|
|
@ -1,36 +0,0 @@
|
|||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
DesignerPanel, DesignerPanelContent, DesignerPanelHeader
|
||||
} from "../designer_panel";
|
||||
import { Everything } from "../../interfaces";
|
||||
import { t } from "../../i18next_wrapper";
|
||||
import { Panel } from "../panel_header";
|
||||
|
||||
export interface AddWeedProps {
|
||||
dispatch: Function;
|
||||
}
|
||||
|
||||
export interface AddWeedState {
|
||||
}
|
||||
|
||||
export const mapStateToProps = (props: Everything): AddWeedProps => ({
|
||||
dispatch: props.dispatch,
|
||||
});
|
||||
|
||||
export class RawAddWeed extends React.Component<AddWeedProps, AddWeedState> {
|
||||
state: AddWeedState = {};
|
||||
render() {
|
||||
return <DesignerPanel panelName={"add-weed"} panel={Panel.Weeds}>
|
||||
<DesignerPanelHeader
|
||||
panelName={"weeds"}
|
||||
title={t("Add new weed")}
|
||||
backTo={"/app/designer/weeds"}
|
||||
panel={Panel.Weeds} />
|
||||
<DesignerPanelContent panelName={"add-weed"}>
|
||||
</DesignerPanelContent>
|
||||
</DesignerPanel>;
|
||||
}
|
||||
}
|
||||
|
||||
export const AddWeed = connect(mapStateToProps)(RawAddWeed);
|
|
@ -13,17 +13,10 @@ jest.mock("../../../history", () => ({
|
|||
|
||||
jest.mock("../../../api/crud", () => ({ edit: jest.fn() }));
|
||||
|
||||
let mockDev = false;
|
||||
jest.mock("../../../account/dev/dev_support", () => ({
|
||||
DevSettings: {
|
||||
futureFeaturesEnabled: () => mockDev,
|
||||
}
|
||||
}));
|
||||
|
||||
import * as React from "react";
|
||||
import { mount, shallow } from "enzyme";
|
||||
import {
|
||||
RawSavedGardens as SavedGardens, mapStateToProps, SavedGardensLink,
|
||||
RawSavedGardens as SavedGardens, mapStateToProps,
|
||||
SavedGardenHUD, savedGardenOpen,
|
||||
} from "../saved_gardens";
|
||||
import { clickButton } from "../../../__test_support__/helpers";
|
||||
|
@ -106,25 +99,6 @@ describe("mapStateToProps()", () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe("<SavedGardensLink />", () => {
|
||||
it("opens saved garden panel", () => {
|
||||
mockDev = true;
|
||||
const wrapper = shallow(<SavedGardensLink />);
|
||||
clickButton(wrapper, 0, "saved gardens");
|
||||
expect(history.push).toHaveBeenCalledWith(
|
||||
"/app/designer/gardens");
|
||||
mockDev = false;
|
||||
});
|
||||
|
||||
it("saved garden button hidden", () => {
|
||||
mockDev = false;
|
||||
const wrapper = shallow(<SavedGardensLink />);
|
||||
const btn = wrapper.find("button").at(0);
|
||||
expect(btn.props().hidden).toEqual(true);
|
||||
mockDev = false;
|
||||
});
|
||||
});
|
||||
|
||||
describe("savedGardenOpen", () => {
|
||||
it("is open", () => {
|
||||
const result = savedGardenOpen(["", "", "", "gardens", "4", ""]);
|
||||
|
|
|
@ -62,15 +62,6 @@ export class RawSavedGardens
|
|||
}
|
||||
}
|
||||
|
||||
/** Link to SavedGardens panel for garden map legend. */
|
||||
export const SavedGardensLink = () =>
|
||||
<button className="fb-button green"
|
||||
hidden={true}
|
||||
title={t("open saved gardens panel")}
|
||||
onClick={() => history.push("/app/designer/gardens")}>
|
||||
{t("Saved Gardens")}
|
||||
</button>;
|
||||
|
||||
/** Check if a SavedGarden is currently open (URL approach). */
|
||||
export const savedGardenOpen = (pathArray: string[]) =>
|
||||
pathArray[3] === "gardens" && parseInt(pathArray[4]) > 0
|
||||
|
|
|
@ -16,9 +16,9 @@ import { API } from "../../api/index";
|
|||
import { Session } from "../../session";
|
||||
import { error } from "../../toast/toast";
|
||||
import { formEvent, inputEvent } from "../../__test_support__/fake_html_events";
|
||||
import { TermsCheckbox } from "../../front_page/terms_checkbox";
|
||||
|
||||
describe("<TosUpdate/>", () => {
|
||||
const instance = () => shallow<TosUpdate>(<TosUpdate />).instance();
|
||||
it("renders correctly when envs are set", () => {
|
||||
const oldTos = globalConfig.TOS_URL;
|
||||
const oldPriv = globalConfig.PRIV_URL;
|
||||
|
@ -31,7 +31,7 @@ describe("<TosUpdate/>", () => {
|
|||
});
|
||||
|
||||
it("has a setter", () => {
|
||||
const tosUpdate = instance();
|
||||
const tosUpdate = shallow<TosUpdate>(<TosUpdate />).instance();
|
||||
tosUpdate.setState = jest.fn();
|
||||
tosUpdate.set("email")(inputEvent("foo@bar.com"));
|
||||
expect(tosUpdate.setState).toHaveBeenCalledWith({ email: "foo@bar.com" });
|
||||
|
@ -47,7 +47,7 @@ describe("<TosUpdate/>", () => {
|
|||
|
||||
it("submits a form", async () => {
|
||||
location.assign = jest.fn();
|
||||
const i = instance();
|
||||
const i = shallow<TosUpdate>(<TosUpdate />).instance();
|
||||
i.setState(fake);
|
||||
await i.submit(fakeFormEvent);
|
||||
expect(fakeFormEvent.preventDefault).toHaveBeenCalled();
|
||||
|
@ -59,7 +59,7 @@ describe("<TosUpdate/>", () => {
|
|||
|
||||
it("errors while submitting", async () => {
|
||||
mockPostResponse = Promise.reject({ response: { data: ["error"] } });
|
||||
const i = instance();
|
||||
const i = shallow<TosUpdate>(<TosUpdate />).instance();
|
||||
i.setState(fake);
|
||||
await i.submit(fakeFormEvent);
|
||||
expect(fakeFormEvent.preventDefault).toHaveBeenCalled();
|
||||
|
@ -75,4 +75,31 @@ describe("<TosUpdate/>", () => {
|
|||
["https://farm.bot/privacy/", "https://farm.bot/tos/"]
|
||||
.map(string => expect(el.html()).toContain(string));
|
||||
});
|
||||
|
||||
it("accepts terms", () => {
|
||||
const wrapper = mount<TosUpdate>(<TosUpdate />);
|
||||
const tosForm = shallow(wrapper.instance().tosForm());
|
||||
expect(wrapper.state().agree_to_terms).toBeFalsy();
|
||||
tosForm.find(TermsCheckbox).simulate("change", {
|
||||
currentTarget: { checked: true }
|
||||
});
|
||||
expect(wrapper.state().agree_to_terms).toBeTruthy();
|
||||
});
|
||||
|
||||
it("errors on click", () => {
|
||||
const wrapper = mount<TosUpdate>(<TosUpdate />);
|
||||
expect(wrapper.state().agree_to_terms).toBeFalsy();
|
||||
const tosForm = shallow(wrapper.instance().tosForm());
|
||||
tosForm.find("button").simulate("click");
|
||||
expect(error).toHaveBeenCalledWith("Please agree to the terms.");
|
||||
});
|
||||
|
||||
it("doesn't error on click", () => {
|
||||
const wrapper = mount<TosUpdate>(<TosUpdate />);
|
||||
wrapper.setState({ agree_to_terms: true });
|
||||
expect(wrapper.state().agree_to_terms).toBeTruthy();
|
||||
const tosForm = shallow(wrapper.instance().tosForm());
|
||||
tosForm.find("button").simulate("click");
|
||||
expect(error).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue