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
This commit is contained in:
John Knox
2019-10-22 07:35:36 -07:00
committed by Facebook Github Bot
parent c63f145ffb
commit 836a065e59

View File

@@ -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));
}}
/>