feat(code): condense plan approval options#3066
Conversation
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
|
Reviews (1): Last reviewed commit: "feat(code): condense plan approval optio..." | Re-trigger Greptile |
| it("defaults to auto when there is no prior or remembered mode", async () => { | ||
| const user = userEvent.setup(); | ||
| const { onSelect } = renderSelector([ | ||
| AUTO, | ||
| ACCEPT_EDITS, | ||
| DEFAULT_MODE, | ||
| REJECT, | ||
| ]); | ||
|
|
||
| await user.click(screen.getByText("Approve and proceed")); | ||
|
|
||
| expect(onSelect).toHaveBeenCalledTimes(1); | ||
| expect(onSelect).toHaveBeenCalledWith("auto"); | ||
| }); | ||
|
|
||
| it("defaults to the remembered last choice over the auto fallback", async () => { | ||
| const user = userEvent.setup(); | ||
| useSettingsStore.setState({ lastPlanApprovalMode: "acceptEdits" }); | ||
| const { onSelect } = renderSelector([AUTO, ACCEPT_EDITS, DEFAULT_MODE]); | ||
|
|
||
| await user.click(screen.getByText("Approve and proceed")); | ||
|
|
||
| expect(onSelect).toHaveBeenCalledWith("acceptEdits"); | ||
| }); |
There was a problem hiding this comment.
Tests 1 and 2 exercise the same behaviour (initial mode pre-selection on approve) with different inputs; the team prefers parameterised tests. A single
it.each table would express both cases more concisely and make it easy to add future combinations (e.g., a remembered mode that is no longer in the options list).
| it("defaults to auto when there is no prior or remembered mode", async () => { | |
| const user = userEvent.setup(); | |
| const { onSelect } = renderSelector([ | |
| AUTO, | |
| ACCEPT_EDITS, | |
| DEFAULT_MODE, | |
| REJECT, | |
| ]); | |
| await user.click(screen.getByText("Approve and proceed")); | |
| expect(onSelect).toHaveBeenCalledTimes(1); | |
| expect(onSelect).toHaveBeenCalledWith("auto"); | |
| }); | |
| it("defaults to the remembered last choice over the auto fallback", async () => { | |
| const user = userEvent.setup(); | |
| useSettingsStore.setState({ lastPlanApprovalMode: "acceptEdits" }); | |
| const { onSelect } = renderSelector([AUTO, ACCEPT_EDITS, DEFAULT_MODE]); | |
| await user.click(screen.getByText("Approve and proceed")); | |
| expect(onSelect).toHaveBeenCalledWith("acceptEdits"); | |
| }); | |
| it.each([ | |
| { | |
| label: "no prior or remembered mode", | |
| lastMode: null as null, | |
| options: [AUTO, ACCEPT_EDITS, DEFAULT_MODE, REJECT], | |
| expected: "auto", | |
| }, | |
| { | |
| label: "remembered last choice over the auto fallback", | |
| lastMode: "acceptEdits" as const, | |
| options: [AUTO, ACCEPT_EDITS, DEFAULT_MODE], | |
| expected: "acceptEdits", | |
| }, | |
| ])("defaults to $expected when $label", async ({ lastMode, options, expected }) => { | |
| const user = userEvent.setup(); | |
| useSettingsStore.setState({ lastPlanApprovalMode: lastMode }); | |
| const { onSelect } = renderSelector(options); | |
| await user.click(screen.getByText("Approve and proceed")); | |
| expect(onSelect).toHaveBeenCalledTimes(1); | |
| expect(onSelect).toHaveBeenCalledWith(expected); | |
| }); |
Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
| if (!selectedMode) { | ||
| return ( | ||
| <ActionSelector | ||
| title="Implementation Plan" | ||
| question="Approve this plan to proceed?" | ||
| options={toSelectorOptions(options)} | ||
| onSelect={onSelect} | ||
| onCancel={onCancel} | ||
| /> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Duplicate string literals in fallback path
The strings "Implementation Plan" and "Approve this plan to proceed?" appear verbatim in both the degenerate-case ActionSelector fallback (lines 194–196) and the main render path (lines 248–254). Extracting them to constants at the top of the function would satisfy OnceAndOnlyOnce and prevent the two copies from drifting.
Context Used: Do not attempt to comment on incorrect alphabetica... (source)
Generated-By: PostHog Code Task-Id: 787ae949-1b72-4246-afc9-d30ebe3c96a3
5c2de91 to
7bdef00
Compare

Problem
plan approval options are getting 🥜
Changes
made them nice and condensed - two buttons:
user's last plan approval mode is stored and used as the default, falling back to "auto"
How did you test this?
manually, storybook
Automatic notifications