Skip to content

Commit c4123eb

Browse files
committed
fix(mobile): ignore scheduled-task edits from the previous environment
1 parent adffe7c commit c4123eb

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.test.tsx‎

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,20 @@ vi.mock("../../components/EnvironmentMachineSymbol", () => ({
3636
EnvironmentMachineSymbol: () => null,
3737
ENVIRONMENT_MACHINE_SYMBOLS: {},
3838
}));
39-
vi.mock("../../components/ui/Menu", () => ({ Menu: () => null }));
39+
vi.mock("../../components/ui/Menu", () => ({
40+
Menu: ({
41+
actions,
42+
onPressAction,
43+
}: {
44+
actions: readonly { id: string; title: string }[];
45+
onPressAction: (event: { nativeEvent: { event: string } }) => void;
46+
}) =>
47+
actions.map(({ id, title }) => (
48+
<button key={id} onClick={() => onPressAction({ nativeEvent: { event: id } })}>
49+
Select {title}
50+
</button>
51+
)),
52+
}));
4053
vi.mock("../../components/ui/ScreenScrollView", () => ({ ScreenScrollView: Children }));
4154
vi.mock("./components/SettingsScreen", () => ({ SettingsScreen: Children }));
4255
vi.mock("./components/SettingsSection", () => ({ SettingsSection: Children }));
@@ -80,14 +93,20 @@ vi.mock("../../components/ui/ThemedSwitch", () => ({
8093
}) => <button onClick={() => onValueChange(!value)}>Toggle enabled</button>,
8194
}));
8295
vi.mock("../../state/entities", () => ({
83-
useProjects: () => [{ environmentId: "environment", id: "project", title: "Project" }],
96+
useProjects: () => [
97+
{ environmentId: "environment", id: "project", title: "Project" },
98+
{ environmentId: "target", id: "target-project", title: "Target project" },
99+
],
84100
useServerConfigs: () => new Map(),
85101
useEnvironmentServerConfig: () => null,
86102
}));
87103
vi.mock("./settings-environment-filter", () => ({
88104
useSettingsEnvironmentFilter: () => ({
89105
selectedTargets: [{ environmentId: "environment", label: "Environment" }],
90-
availableTargets: [{ environmentId: "environment", label: "Environment" }],
106+
availableTargets: [
107+
{ environmentId: "environment", label: "Environment" },
108+
{ environmentId: "target", label: "Target" },
109+
],
91110
selectedProjectKey: null,
92111
projectGroups: [],
93112
}),
@@ -226,4 +245,18 @@ describe("scheduled task batched edits", () => {
226245
appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current?.draft.schedule.filters,
227246
).toHaveLength(2);
228247
});
248+
it("keeps the target project when an old picker fires after changing environments", () => {
249+
const editor = appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current;
250+
if (!editor) throw new Error("Missing editor");
251+
act(() => startScheduledTaskEditor({ ...editor, draft: { ...editor.draft, task: null } }));
252+
act(() => {
253+
button("Interval").click();
254+
button("Select Target").click();
255+
button("Select Project").click();
256+
});
257+
expect(appAtomRegistry.get(scheduledTaskEditorSessionAtom)?.current).toMatchObject({
258+
environmentId: "target",
259+
draft: { projectId: "target-project", schedule: { mode: "interval" } },
260+
});
261+
});
229262
});

‎apps/mobile/src/features/settings/SettingsScheduledTasksRouteScreen.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,9 @@ function SettingsScheduledTaskEditorScreen({ title }: { readonly title: string }
615615
setDraft={(update) => {
616616
if (!saving)
617617
setEditor((current) =>
618-
current ? { ...current, draft: update(current.draft) } : current,
618+
current && current.environmentId === editor.environmentId
619+
? { ...current, draft: update(current.draft) }
620+
: current,
619621
);
620622
}}
621623
onSaved={() => {

0 commit comments

Comments
 (0)