Make commands disable, not unregister, based on their machineActor (#5070)
* Make "Find and select command" global to commandBarMachine * Make commands not removed based on their actor state, only disabled * Sort commands better in CommandComboBox * Break out sort logic, add a few unit tests * Fix missed name change * Needed to make one more change from source branch: since `optionsFromContext` now only gets fired once, I/O-based options need to use the `options` config instead. --------- Co-authored-by: 49fl <ircsurfer33@gmail.com>
This commit is contained in:
49
src/lib/commandUtils.test.ts
Normal file
49
src/lib/commandUtils.test.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { CommandWithDisabledState, sortCommands } from './commandUtils'
|
||||
|
||||
function commandWithDisabled(
|
||||
name: string,
|
||||
disabled: boolean,
|
||||
groupId = 'modeling'
|
||||
): CommandWithDisabledState {
|
||||
return {
|
||||
command: {
|
||||
name,
|
||||
groupId,
|
||||
needsReview: false,
|
||||
onSubmit: () => {},
|
||||
},
|
||||
disabled,
|
||||
}
|
||||
}
|
||||
|
||||
describe('Command sorting', () => {
|
||||
it(`Puts modeling commands first`, () => {
|
||||
const initial = [
|
||||
commandWithDisabled('a', false, 'settings'),
|
||||
commandWithDisabled('b', false, 'modeling'),
|
||||
commandWithDisabled('c', false, 'settings'),
|
||||
]
|
||||
const sorted = initial.sort(sortCommands)
|
||||
expect(sorted[0].command.groupId).toBe('modeling')
|
||||
})
|
||||
|
||||
it(`Puts disabled commands last`, () => {
|
||||
const initial = [
|
||||
commandWithDisabled('a', true, 'modeling'),
|
||||
commandWithDisabled('z', false, 'modeling'),
|
||||
commandWithDisabled('a', false, 'settings'),
|
||||
]
|
||||
const sorted = initial.sort(sortCommands)
|
||||
expect(sorted[sorted.length - 1].disabled).toBe(true)
|
||||
})
|
||||
|
||||
it(`Puts settings commands second to last`, () => {
|
||||
const initial = [
|
||||
commandWithDisabled('a', true, 'modeling'),
|
||||
commandWithDisabled('z', false, 'modeling'),
|
||||
commandWithDisabled('a', false, 'settings'),
|
||||
]
|
||||
const sorted = initial.sort(sortCommands)
|
||||
expect(sorted[1].command.groupId).toBe('settings')
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user