From 836a065e59ff3a7b43a97d3a7ed83ec2858e80df Mon Sep 17 00:00:00 2001 From: John Knox Date: Tue, 22 Oct 2019 07:35:36 -0700 Subject: [PATCH] Fix settings sheet tests Summary: The config fields do some async validity checking and possibly update their own state after render. So their renders need to be wrapped in `act()` so that it includes their updates too. This fixes those tests, and also adds mocking for valid and invalid file paths. Reviewed By: passy Differential Revision: D18036449 fbshipit-source-id: 7eec2992313c77e539da0c375966c7c65c30732d --- src/chrome/settings/configFields.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/chrome/settings/configFields.tsx b/src/chrome/settings/configFields.tsx index 3dbc4e638..693f13d71 100644 --- a/src/chrome/settings/configFields.tsx +++ b/src/chrome/settings/configFields.tsx @@ -57,7 +57,12 @@ export function FilePathConfigField(props: { const [value, setValue] = useState(props.defaultValue); const [isValid, setIsValid] = useState(true); fs.stat(value) - .then(stat => setIsValid(stat.isDirectory())) + .then(stat => stat.isDirectory()) + .then(valid => { + if (valid !== isValid) { + setIsValid(valid); + } + }) .catch(_ => setIsValid(false)); return ( @@ -71,7 +76,12 @@ export function FilePathConfigField(props: { setValue(e.target.value); props.onChange(e.target.value); fs.stat(e.target.value) - .then(stat => setIsValid(stat.isDirectory())) + .then(stat => stat.isDirectory()) + .then(valid => { + if (valid !== isValid) { + setIsValid(valid); + } + }) .catch(_ => setIsValid(false)); }} />