Skip to content

Commit

Permalink
minor public sequence bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielburnworth committed Oct 6, 2021
1 parent d70a33b commit 3b93d11
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 24 deletions.
2 changes: 1 addition & 1 deletion app/models/device.rb
Expand Up @@ -244,7 +244,7 @@ def provide_feedback(message, slug = "Not provided")
since = self.users.first.created_at.to_s
firmware_kind = fbos_config.firmware_hardware
osm_url = "https://www.openstreetmap.org"
location_url = "[#{lat},#{lng}](#{osm_url}/?mlat=#{lat}&mlon=#{lng}&zoom=10)"
location_url = "<#{osm_url}/?mlat=#{lat}&mlon=#{lng}&zoom=10|#{lat},#{lng}>"
version = fbos_version.nil? ? "unknown" : "v#{fbos_version}"
info = [
"`Device ID`: #{id}",
Expand Down
1 change: 1 addition & 0 deletions frontend/css/global.scss
Expand Up @@ -1783,6 +1783,7 @@ ul {
textarea {
height: 100% !important;
font-family: monospace;
pointer-events: revert !important;
}
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/sequences/__tests__/actions_test.ts
Expand Up @@ -149,7 +149,7 @@ describe("publishSequence()", () => {
"http://localhost/api/sequences/123/publish", { copyright: "" });
expect(success).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledWith(
"Error: error", { title: "Publish error." });
"Error: error", { title: "Publish error" });
});
});

Expand All @@ -172,7 +172,7 @@ describe("unpublishSequence()", () => {
"http://localhost/api/sequences/123/unpublish");
expect(success).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledWith(
"Error: error", { title: "Unpublish error." });
"Error: error", { title: "Unpublish error" });
});
});

Expand All @@ -193,7 +193,7 @@ describe("installSequence()", () => {
"http://localhost/api/sequences/123/install");
expect(success).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledWith(
"Error: error", { title: "Install error." });
"Error: error", { title: "Install error" });
});
});

Expand All @@ -209,13 +209,13 @@ describe("upgradeSequence()", () => {
expect(error).not.toHaveBeenCalled();
});

it("errors while publishing sequence", async () => {
it("errors while upgrading sequence", async () => {
mockPost = Promise.reject({ response: { data: "error" } });
await upgradeSequence(123, 1)();
expect(axios.post).toHaveBeenCalledWith(
"http://localhost/api/sequences/123/upgrade/1");
expect(success).not.toHaveBeenCalled();
expect(error).toHaveBeenCalledWith(
"Error: error", { title: "Upgrade error." });
"Error: error", { title: "Upgrade error" });
});
});
8 changes: 4 additions & 4 deletions frontend/sequences/actions.ts
Expand Up @@ -66,17 +66,17 @@ export const closeCommandMenu = () => ({
export const publishSequence = (id: number | undefined, copyright: string) => () =>
axios.post(`${API.current.sequencesPath}${id}/publish`, { copyright })
.then(() => { },
err => error(prettyPrintApiErrors(err), { title: t("Publish error.") }));
err => error(prettyPrintApiErrors(err), { title: t("Publish error") }));

export const unpublishSequence = (id: number | undefined) => () =>
axios.post(`${API.current.sequencesPath}${id}/unpublish`)
.then(() => { },
err => error(prettyPrintApiErrors(err), { title: t("Unpublish error.") }));
err => error(prettyPrintApiErrors(err), { title: t("Unpublish error") }));

export const installSequence = (id: number | undefined) => () =>
axios.post(`${API.current.sequencesPath}${id}/install`)
.then(() => { },
err => error(prettyPrintApiErrors(err), { title: t("Install error.") }));
err => error(prettyPrintApiErrors(err), { title: t("Install error") }));

export const upgradeSequence = (
id: number | undefined,
Expand All @@ -85,4 +85,4 @@ export const upgradeSequence = (
() =>
axios.post(`${API.current.sequencesPath}${id}/upgrade/${sequenceVersionId}`)
.then(() => success(t("Sequence upgraded.")),
err => error(prettyPrintApiErrors(err), { title: t("Upgrade error.") }));
err => error(prettyPrintApiErrors(err), { title: t("Upgrade error") }));
8 changes: 1 addition & 7 deletions frontend/sequences/panel/__tests__/preview_test.tsx
Expand Up @@ -20,10 +20,6 @@ jest.mock("../../../api/crud", () => ({
edit: jest.fn(),
}));

jest.mock("../../set_active_sequence_by_name", () => ({
setActiveSequenceByName: jest.fn(),
}));

import React from "react";
import { mount, shallow } from "enzyme";
import {
Expand All @@ -41,7 +37,6 @@ import { fakeState } from "../../../__test_support__/fake_state";
import { BooleanSetting } from "../../../session_keys";
import { edit } from "../../../api/crud";
import { push } from "../../../history";
import { setActiveSequenceByName } from "../../set_active_sequence_by_name";
import { installSequence } from "../../actions";

describe("mapStateToProps()", () => {
Expand Down Expand Up @@ -80,8 +75,7 @@ describe("<DesignerSequencePreview />", () => {
expect(importBtn.text()).toEqual("import");
await importBtn.simulate("click");
expect(installSequence).toHaveBeenCalledWith(sequence.body.id);
expect(setActiveSequenceByName).toHaveBeenCalled();
expect(push).toHaveBeenCalledWith("/app/designer/sequences/fake");
expect(push).toHaveBeenCalledWith("/app/designer/sequences");
});

it("loads sequence", async () => {
Expand Down
7 changes: 1 addition & 6 deletions frontend/sequences/panel/preview.tsx
Expand Up @@ -34,8 +34,6 @@ import {
} from "../sequence_editor_middle_active";
import moment from "moment";
import { edit } from "../../api/crud";
import { urlFriendly } from "../../util";
import { setActiveSequenceByName } from "../set_active_sequence_by_name";

interface LoadSequenceVersionProps {
id: string;
Expand Down Expand Up @@ -212,10 +210,7 @@ const ImportBanner = (props: ImportBannerProps) => {
<button className={"transparent-button"}
onClick={() => {
installSequence(sequence.body.id)()
.then(() => {
push(`/app/designer/sequences/${urlFriendly(sequence.body.name)}`);
setActiveSequenceByName();
});
.then(() => push("/app/designer/sequences"));
publishAction(setImporting);
}}>
{importing ? t("importing") : t("import")}
Expand Down
12 changes: 12 additions & 0 deletions frontend/sequences/step_tiles/__tests__/tile_lua_support_test.tsx
Expand Up @@ -46,4 +46,16 @@ describe("<LuaTextArea />", () => {
mockEditStep.mock.calls[0][0].executor(p.currentStep);
expect(p.currentStep).toEqual({ kind: "lua", args: { lua: "123" } });
});

it("doesn't make changes when read-only", () => {
const p = fakeProps();
p.readOnly = true;
const wrapper = shallow<LuaTextArea<Lua>>(<LuaTextArea {...p} />);
const fallback = shallow(wrapper.instance().FallbackEditor({}));
fallback.find("textarea").simulate("change", {
currentTarget: { value: "123" }
});
fallback.find("textarea").simulate("blur");
expect(mockEditStep).not.toHaveBeenCalled();
});
});
3 changes: 2 additions & 1 deletion frontend/sequences/step_tiles/tile_lua_support.tsx
Expand Up @@ -21,6 +21,7 @@ export class LuaTextArea<Step extends Lua | Assertion>
state: LuaTextAreaState = { lua: this.props.currentStep.args.lua };

updateStep = debounce((newLua: string) => {
if (this.props.readOnly) { return; }
this.props.dispatch(editStep({
step: this.props.currentStep,
index: this.props.index,
Expand All @@ -34,7 +35,7 @@ export class LuaTextArea<Step extends Lua | Assertion>
this.updateStep(this.state.lua);
};

setLua = (value: string) => this.setState({ lua: value });
setLua = (value: string) => !this.props.readOnly && this.setState({ lua: value });

FallbackEditor = ({ loading }: { loading?: boolean }) =>
<textarea className={loading ? "" : "fallback-lua-editor"}
Expand Down

0 comments on commit 3b93d11

Please sign in to comment.