File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { expect , test } from "@playwright/test" ;
22import { goto , toast , undoButton } from "./helpers" ;
33
4+ test ( "what-if target stays editable while the factory re-solves" , async ( { page } ) => {
5+ await goto ( page , "/whatif" ) ;
6+
7+ const firstDemand = page . getByRole ( "spinbutton" ) . first ( ) ;
8+ await expect ( firstDemand ) . toBeVisible ( ) ;
9+ await firstDemand . selectText ( ) ;
10+ await firstDemand . pressSequentially ( "12.34" , { delay : 100 } ) ;
11+
12+ // Each character starts another solve. The demand list must remain mounted,
13+ // preserving both the in-progress value and keyboard focus throughout them.
14+ await expect ( firstDemand ) . toBeFocused ( ) ;
15+ await expect ( firstDemand ) . toHaveValue ( "12.34" ) ;
16+ await expect ( page . getByText ( "Block changes" , { exact : false } ) . first ( ) ) . toBeVisible ( {
17+ timeout : 15_000 ,
18+ } ) ;
19+ await expect ( firstDemand ) . toBeFocused ( ) ;
20+ await expect ( firstDemand ) . toHaveValue ( "12.34" ) ;
21+ } ) ;
22+
423/**
524 * What-if "Apply all" (whole-factory re-balance): overriding a final product's
625 * target surfaces the per-block changes, and Apply all commits every one of them
Original file line number Diff line number Diff line change 11import { createFileRoute , Link } from "@tanstack/react-router" ;
2- import { useQuery } from "@tanstack/react-query" ;
2+ import { keepPreviousData , useQuery } from "@tanstack/react-query" ;
33import { useState } from "react" ;
44import { factoryWhatIfFn } from "../server/factorio" ;
55import { Icon , IconProvider } from "../lib/icons" ;
@@ -43,6 +43,9 @@ function WhatIf() {
4343 const wf = useQuery ( {
4444 queryKey : [ "whatif" , overrides ] ,
4545 queryFn : ( ) => factoryWhatIfFn ( { data : { demands : overrides } } ) ,
46+ // Changing a target starts a fresh whole-factory solve. Keep the demand rows
47+ // mounted while it runs so the active input does not lose focus mid-edit.
48+ placeholderData : keepPreviousData ,
4649 } ) ;
4750 const r = wf . data ;
4851 const changed = ( r ?. blocks ?? [ ] ) . filter ( ( b ) => Math . abs ( b . scale - 1 ) > SCALE_EPS ) ;
You can’t perform that action at this time.
0 commit comments