Skip to content

Commit

Permalink
Merge pull request #975 from gabrielburnworth/staging
Browse files Browse the repository at this point in the history
Deprecated code removal and linting
  • Loading branch information
gabrielburnworth committed Aug 31, 2018
2 parents 36eba92 + 94997b1 commit ecd9ab9
Show file tree
Hide file tree
Showing 69 changed files with 365 additions and 420 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ before_script:
- bundle exec rake db:create db:migrate
script:
- bundle exec rspec --fail-fast=3
- npm run tslint
- npm run typecheck
- npm run test-slow
- npm run coverage
1 change: 1 addition & 0 deletions webpack/__tests__/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const fakeProps = (): AppProps => {
firmwareConfig: undefined,
xySwap: false,
animate: false,
getConfigValue: jest.fn(),
};
};

Expand Down
9 changes: 1 addition & 8 deletions webpack/__tests__/refresh_token_no_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,7 @@ jest.mock("axios", () => ({
}
}));

jest.mock("../session", () => {
return {
Session: {
clear: jest.fn(),
deprecatedGetBool: jest.fn(),
}
};
});
jest.mock("../session", () => ({ Session: { clear: jest.fn(), } }));

import { maybeRefreshToken } from "../refresh_token";
import { API } from "../api/index";
Expand Down
2 changes: 0 additions & 2 deletions webpack/__tests__/routes_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ let mockAuth: AuthState | undefined = undefined;
jest.mock("../session", () => ({
Session: {
fetchStoredToken: jest.fn(() => mockAuth),
deprecatedGetNum: () => undefined,
deprecatedGetBool: () => undefined,
getAll: () => undefined,
clear: jest.fn()
}
Expand Down
57 changes: 0 additions & 57 deletions webpack/__tests__/session_test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,3 @@
import { fakeWebAppConfig } from "../__test_support__/fake_state/resources";
import { fakeState } from "../__test_support__/fake_state";

const mockConfig = fakeWebAppConfig();
jest.mock("../resources/selectors_by_kind", () => ({
getWebAppConfig: () => mockConfig
}));

jest.mock("../api/crud", () => ({
edit: jest.fn(),
save: jest.fn(),
}));

const mockState = fakeState();
jest.mock("../redux/store", () => ({
store: {
dispatch: jest.fn(),
getState: () => mockState,
}
}));

import {
isNumericSetting,
isBooleanSetting,
Expand All @@ -27,7 +6,6 @@ import {
Session,
} from "../session";
import { auth } from "../__test_support__/fake_state/token";
import { edit, save } from "../api/crud";

describe("fetchStoredToken", () => {
it("can't fetch token", () => {
Expand Down Expand Up @@ -61,41 +39,6 @@ describe("safeBooleanSetting", () => {
});
});

describe("deprecatedGetNum", () => {
it("gets number", () => {
const result = Session.deprecatedGetNum("success_log");
expect(result).toEqual(3);
});
});

describe("deprecatedSetNum", () => {
it("sets number", () => {
Session.deprecatedSetNum("success_log", 0);
expect(edit).toHaveBeenCalledWith(expect.any(Object), { success_log: 0 });
expect(save).toHaveBeenCalledWith(mockConfig.uuid);
});
});

describe("setBool", () => {
it("sets bool", () => {
Session.setBool("x_axis_inverted", false);
expect(edit).toHaveBeenCalledWith(expect.any(Object), {
x_axis_inverted: false
});
expect(save).toHaveBeenCalledWith(mockConfig.uuid);
});
});

describe("invertBool", () => {
it("inverts bool", () => {
Session.invertBool("x_axis_inverted");
expect(edit).toHaveBeenCalledWith(expect.any(Object), {
x_axis_inverted: true
});
expect(save).toHaveBeenCalledWith(mockConfig.uuid);
});
});

describe("safeNumericSetting", () => {
it("safely returns num", () => {
expect(() => safeNumericSetting("no")).toThrow();
Expand Down
4 changes: 3 additions & 1 deletion webpack/account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ export class Account extends React.Component<Props, State> {
<ChangePassword />
</Row>
<Row>
<LabsFeatures />
<LabsFeatures
dispatch={this.props.dispatch}
getConfigValue={this.props.getConfigValue} />
</Row>
<Row>
<DeleteAccount onClick={deleteAcct} />
Expand Down
2 changes: 2 additions & 0 deletions webpack/account/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { User } from "../auth/interfaces";
import { TaggedUser } from "farmbot";
import { GetWebAppConfigValue } from "../config_storage/actions";

export interface Props {
user: TaggedUser;
dispatch: Function;
getConfigValue: GetWebAppConfigValue;
}

/** JSON form that gets POSTed to the API when user updates their info. */
Expand Down
2 changes: 1 addition & 1 deletion webpack/account/labs/__tests__/fetch_lab_features_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchLabFeatures } from "../labs_features_list_data";
describe("fetchLabFeatures", () => {
window.location.reload = jest.fn();
it("basically just initializes stuff", () => {
const val = fetchLabFeatures();
const val = fetchLabFeatures(jest.fn());
expect(val.length).toBe(9);
expect(val[0].value).toBeFalsy();
const { callback } = val[0];
Expand Down
23 changes: 4 additions & 19 deletions webpack/account/labs/__tests__/labs_features_list_data_test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
const mockStorj: Dictionary<boolean> = {};

jest.mock("../../../session", () => {
return {
Session: {
deprecatedGetBool: (k: string) => {
mockStorj[k] = !!mockStorj[k];
return mockStorj[k];
},
invertBool: (k: string) => {
mockStorj[k] = !mockStorj[k];
return mockStorj[k];
}
}
};
});

import { Dictionary } from "farmbot";
import { maybeToggleFeature, LabsFeature } from "../labs_features_list_data";
import { BooleanSetting } from "../../../session_keys";
Expand All @@ -29,7 +14,7 @@ describe("maybeToggleFeature()", () => {
storageKey: BooleanSetting.stub_config,
confirmationMessage: "are you sure?"
};
const out = maybeToggleFeature(data);
const out = maybeToggleFeature(x => mockStorj[x], jest.fn())(data);
expect(data.value).toBeFalsy();
expect(out).toBeUndefined();
expect(window.confirm).toHaveBeenCalledWith(data.confirmationMessage);
Expand All @@ -44,15 +29,15 @@ describe("maybeToggleFeature()", () => {
storageKey: BooleanSetting.stub_config,
confirmationMessage: "are you sure?"
};
const out = maybeToggleFeature(data);
const out = maybeToggleFeature(x => mockStorj[x], jest.fn())(data);
out ?
expect(out.value).toBeTruthy() : fail("out === undefined. Thats bad");
expect(out).toBeTruthy();
});

it("Does not require consent when going from true to false", () => {
window.confirm = jest.fn(() => true);
const output = maybeToggleFeature({
const output = maybeToggleFeature(x => mockStorj[x], jest.fn())({
name: "Example",
value: (mockStorj[BooleanSetting.stub_config] = true),
description: "I stub this.",
Expand All @@ -71,7 +56,7 @@ describe("maybeToggleFeature()", () => {
description: "I stub this.",
storageKey: BooleanSetting.stub_config
};
const out = maybeToggleFeature(data);
const out = maybeToggleFeature(x => mockStorj[x], jest.fn())(data);
out ?
expect(out.value).toBeTruthy() : fail("out === undefined. Thats bad");
expect(out).toBeTruthy();
Expand Down
6 changes: 4 additions & 2 deletions webpack/account/labs/__tests__/labs_features_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const mockFeatures = [
];

const mocks = {
"maybeToggleFeature": jest.fn(),
"maybeToggleFeature": jest.fn(() => jest.fn()),
"fetchLabFeatures": jest.fn(() => mockFeatures)
};

Expand All @@ -21,7 +21,9 @@ import { LabsFeatures } from "../labs_features";

describe("<LabsFeatures/>", () => {
it("triggers the correct callback on click", () => {
const el = mount(<LabsFeatures />);
const el = mount(<LabsFeatures
dispatch={jest.fn()}
getConfigValue={jest.fn()} />);
expect(mocks.fetchLabFeatures.mock.calls.length).toBeGreaterThan(0);
el.find("button").simulate("click");
expect(mockFeatures[0].callback).toHaveBeenCalled();
Expand Down
19 changes: 14 additions & 5 deletions webpack/account/labs/labs_features.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ import { LabsFeaturesList } from "./labs_features_list_ui";
import { maybeToggleFeature } from "./labs_features_list_data";
import { t } from "i18next";
import { ToolTips } from "../../constants";
import { GetWebAppConfigValue } from "../../config_storage/actions";

export class LabsFeatures extends React.Component<{}, {}> {
interface LabsFeaturesProps {
getConfigValue: GetWebAppConfigValue;
dispatch: Function;
}

export class LabsFeatures extends React.Component<LabsFeaturesProps, {}> {
state = {};

render() {
const { getConfigValue, dispatch } = this.props;
return <Widget className="peripherals-widget">
<WidgetHeader title={t("App Settings")}
helpText={ToolTips.LABS}>
</WidgetHeader>
<WidgetBody>
<LabsFeaturesList onToggle={(x) => {
maybeToggleFeature(x);
this.forceUpdate();
}} />
<LabsFeaturesList
getConfigValue={getConfigValue}
onToggle={x => {
maybeToggleFeature(getConfigValue, dispatch)(x);
this.forceUpdate();
}} />
</WidgetBody>
</Widget>;
}
Expand Down
Loading

0 comments on commit ecd9ab9

Please sign in to comment.