@@ -206,7 +206,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
206
206
private _isSingleton = false
207
207
private _maxInstanceMode : Mode = MAX_MODE_WHEN_EMBEDDED // can be set later
208
208
private _isDirty = false
209
- private _isRunningTests = false
209
+ private _isUIDisabled = false // when inputs are being set programmatically over a longer period
210
210
private _mode : Mode = DEFAULT_MODE
211
211
private _initialData : InitialData | undefined = undefined
212
212
private _options : EditorOptions = { ...DEFAULT_EDITOR_OPTIONS }
@@ -1035,8 +1035,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1035
1035
}
1036
1036
this . html . rootDiv . setAttribute ( ATTRIBUTE_NAMES . nomodes , nomodes . join ( " " ) )
1037
1037
1038
-
1039
- // console.log(`Display/interaction is ${wantedModeStr} - ${mode}`)
1038
+ // console.log(`Current mode is ${modeStr} - ${mode}`)
1040
1039
1041
1040
this . editTools . redrawMgr . addReason ( "mode changed" , null , true )
1042
1041
@@ -1741,26 +1740,45 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1741
1740
}
1742
1741
}
1743
1742
1744
- public async runTestSuite ( testSuite : TestSuite , options ?: { doLog ?: boolean , fast ?: boolean } ) : Promise < TestSuiteResults | undefined > {
1745
-
1746
- if ( this . _isRunningTests ) {
1743
+ public async disableUIWhile < T > ( message : string , action : ( restoreAfter : Map < Input , LogicValue [ ] > ) => Promise < T > ) : Promise < T | undefined > {
1744
+ if ( this . _isUIDisabled ) {
1747
1745
// cannot run tests while already running
1748
1746
return undefined
1749
1747
}
1750
1748
1749
+ this . _isUIDisabled = true
1750
+ const oldMode = this . mode
1751
+ const restoreAfter = new Map < Input , LogicValue [ ] > ( )
1752
+ const hideMsg = this . showMessage ( message , 0 )
1753
+
1754
+ try {
1755
+ this . setMode ( Mode . STATIC , false )
1756
+ const result = await action ( restoreAfter )
1757
+ return result
1758
+ } finally {
1759
+ hideMsg ( )
1760
+ this . setMode ( oldMode , true )
1761
+ for ( const [ input , value ] of restoreAfter ) {
1762
+ input . setValue ( value )
1763
+ }
1764
+ this . _isUIDisabled = false
1765
+ this . recalcPropagateAndDrawIfNeeded ( )
1766
+ }
1767
+
1768
+ }
1769
+
1770
+ public async runTestSuite ( testSuite : TestSuite , options ?: { doLog ?: boolean , fast ?: boolean } ) : Promise < TestSuiteResults | undefined > {
1771
+
1751
1772
const palette = this . editTools . testsPalette
1752
1773
if ( palette === undefined ) {
1753
1774
return undefined
1754
1775
}
1755
1776
1756
- this . _isRunningTests = true
1757
- const oldMode = this . mode
1758
1777
const fast = options ?. fast ?? false
1759
1778
const doLog = options ?. doLog ?? false
1760
- const allOldInValues = new Map < Input , LogicValue [ ] > ( )
1761
1779
1762
- try {
1763
- this . setMode ( Mode . STATIC , false )
1780
+ return this . disableUIWhile ( S . Messages . RunningTests , async restoreAfter => {
1781
+
1764
1782
this . setTestsPaletteVisible ( true ) // after setMode, which may hide it
1765
1783
1766
1784
const results = new TestSuiteResults ( testSuite )
@@ -1785,8 +1803,8 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1785
1803
const [ oldInValues , result ] = await this . runTestCase ( testCase , testSuite , doLog )
1786
1804
testCaseResult = result
1787
1805
for ( const [ input , value ] of oldInValues ) {
1788
- if ( ! allOldInValues . has ( input ) ) {
1789
- allOldInValues . set ( input , value )
1806
+ if ( ! restoreAfter . has ( input ) ) {
1807
+ restoreAfter . set ( input , value )
1790
1808
}
1791
1809
}
1792
1810
}
@@ -1797,15 +1815,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1797
1815
}
1798
1816
}
1799
1817
return results
1800
-
1801
- } finally {
1802
- this . setMode ( oldMode , true )
1803
- for ( const [ input , value ] of allOldInValues ) {
1804
- input . setValue ( value )
1805
- }
1806
- this . _isRunningTests = false
1807
- this . recalcPropagateAndDrawIfNeeded ( )
1808
- }
1818
+ } )
1809
1819
}
1810
1820
1811
1821
public trySetInputsAndRecalc ( inputs : TestCaseValueMap < Input > ) {
@@ -1825,12 +1835,10 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1825
1835
doLog : boolean
1826
1836
) : Promise < [ Map < Input , LogicValue [ ] > , TestCaseResult ] > {
1827
1837
1828
- const fullTestNameParts = [ sourceSuite . name , testCase . name ] . filter ( Boolean )
1829
- const fullTestName = fullTestNameParts . length === 0 ? S . Tests . DefaultTestCaseName : fullTestNameParts . join ( "/" )
1830
- const msg = S . Messages . RunningTestCase . expand ( { name : fullTestName } )
1831
- const hideMsg = this . showMessage ( msg , 0 )
1832
1838
if ( doLog ) {
1833
- console . group ( msg )
1839
+ const fullTestNameParts = [ sourceSuite . name , testCase . name ] . filter ( Boolean )
1840
+ const fullTestName = fullTestNameParts . length === 0 ? S . Tests . DefaultTestCaseName : fullTestNameParts . join ( "/" )
1841
+ console . group ( "Running test case " + fullTestName )
1834
1842
}
1835
1843
1836
1844
testCase . tryFixReferences ( this . editorRoot . components )
@@ -1874,7 +1882,6 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1874
1882
if ( doLog ) {
1875
1883
console . groupEnd ( )
1876
1884
}
1877
- hideMsg ( )
1878
1885
}
1879
1886
}
1880
1887
0 commit comments