Skip to content

Commit 56dc5af

Browse files
committed
Keep manual result entry visible after finishing a brew
1 parent e1e1d67 commit 56dc5af

4 files changed

Lines changed: 41 additions & 5 deletions

File tree

src/views/BrewingView.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export class BrewingView extends ItemView {
175175
});
176176
}
177177

178-
private renderContent(focusStep?: FlowStep): void {
178+
private renderContent(focusStep?: FlowStep, alsoExpand?: FlowStep): void {
179179
this.accordion.destroy();
180180
for (const fn of this.cleanups) fn();
181181
this.cleanups = [];
@@ -194,6 +194,9 @@ export class BrewingView extends ItemView {
194194
const targetStep = focusStep ?? (this.flowState.step as FlowStep);
195195
if (shouldFocus) {
196196
this.accordion.focusStep(targetStep);
197+
if (alsoExpand !== undefined) {
198+
this.accordion.expandStep(alsoExpand);
199+
}
197200
this.lastFocusedStep = this.flowState.step;
198201
}
199202
this.accordion.update();
@@ -213,7 +216,7 @@ export class BrewingView extends ItemView {
213216
return {
214217
flowState: this.flowState,
215218
plugin: this.plugin,
216-
renderContent: (focusStep) => this.renderContent(focusStep),
219+
renderContent: (focusStep, alsoExpand) => this.renderContent(focusStep, alsoExpand),
217220
accordion: {
218221
update: () => this.accordion.update(),
219222
expand: (step) => this.accordion.expandStep(step),

src/views/StepRenderers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface AccordionActions {
3636
export interface StepRenderContext {
3737
flowState: BrewFlowState;
3838
plugin: CubicJBrewingPlugin;
39-
renderContent: (focusStep?: FlowStep) => void;
39+
renderContent: (focusStep?: FlowStep, alsoExpand?: FlowStep) => void;
4040
accordion: AccordionActions;
4141
timerController: TimerController;
4242
getWeightText: () => string;

src/views/steps/renderBrewing.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function renderBrewing(container: HTMLElement, ctx: StepRenderContext): v
2424
});
2525
doneBtn.addEventListener('click', () => {
2626
ctx.flowState.finishBrewing(undefined, undefined);
27-
ctx.renderContent();
27+
ctx.renderContent('brewing', 'saving');
2828
});
2929
return;
3030
}
@@ -67,7 +67,11 @@ export function renderBrewing(container: HTMLElement, ctx: StepRenderContext): v
6767
} else {
6868
ctx.flowState.finishBrewing(undefined, undefined);
6969
}
70-
ctx.renderContent();
70+
if (ctx.recorder.getPoints().length > 0) {
71+
ctx.renderContent();
72+
} else {
73+
ctx.renderContent('brewing', 'saving');
74+
}
7175
} catch (err) {
7276
console.error('[StepRenderers] brew stop failed:', err);
7377
new Notice(t('brew.unexpectedError'));

tests/views/steps/renderBrewing.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,35 @@ describe('renderBrewing phase controls', () => {
215215
expect(ctx.timerController.cancelRun).not.toHaveBeenCalled();
216216
});
217217

218+
it('finishing without a recorded profile keeps focus on brewing and expands saving', async () => {
219+
const container = createContainer();
220+
const flowState = makeFlowState('filter');
221+
flowState.beginBrewingRun();
222+
const { ctx } = makeContext(flowState, [], 'disconnected');
223+
renderBrewing(container, ctx);
224+
(container.querySelector('.brew-flow-stop-btn') as HTMLButtonElement).click();
225+
await vi.waitFor(() => expect(ctx.renderContent).toHaveBeenCalledWith('brewing', 'saving'));
226+
expect(ctx.flowState.step).toBe('saving');
227+
});
228+
229+
it('espresso done keeps focus on brewing and expands saving', () => {
230+
const container = createContainer();
231+
const { ctx } = makeContext(makeFlowState('espresso'));
232+
renderBrewing(container, ctx);
233+
(container.querySelector('.brew-flow-stop-btn') as HTMLButtonElement).click();
234+
expect(ctx.renderContent).toHaveBeenCalledWith('brewing', 'saving');
235+
expect(ctx.flowState.step).toBe('saving');
236+
});
237+
238+
it('finishing with a recorded profile focuses saving as before', async () => {
239+
const container = createContainer();
240+
const ctx = makeRunningContext();
241+
renderBrewing(container, ctx);
242+
(container.querySelector('.brew-flow-stop-btn') as HTMLButtonElement).click();
243+
await vi.waitFor(() => expect(ctx.renderContent).toHaveBeenCalledWith());
244+
expect(ctx.flowState.step).toBe('saving');
245+
});
246+
218247
it('cancel rejection still re-renders a coherent armed brewing state', async () => {
219248
const container = createContainer();
220249
const ctx = makeRunningContext();

0 commit comments

Comments
 (0)