-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: limit selection actions in direct query (#1246)
* refactor: compensate for checkboxes in item width * test: search highlight rendering test * refactor: disable some select actions in dq mode * fix: rm test * refactor: add flags fallback to context * refactor: send flags through options instead of context * refactor: rm flags completely
- Loading branch information
1 parent
6dbd394
commit ca46370
Showing
6 changed files
with
198 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
apis/nucleus/src/components/listbox/interactions/__tests__/listbox-selection-toolbar.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
import createListboxSelectionToolbar from '../listbox-selection-toolbar'; | ||
|
||
describe('getScrollIndex', () => { | ||
let layout; | ||
let model; | ||
let translator; | ||
let selectionState; | ||
let isDirectQuery; | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
afterAll(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
|
||
beforeEach(() => { | ||
isDirectQuery = false; | ||
layout = { | ||
qListObject: { | ||
qDimensionInfo: { | ||
qStateCounts: { | ||
qOption: 2, | ||
qAlternative: 2, | ||
qExcluded: 2, | ||
qDeselected: 2, | ||
}, | ||
qIsOneAndOnlyOne: false, | ||
}, | ||
}, | ||
}; | ||
model = { | ||
selectListObjectAll: jest.fn(), | ||
selectListObjectPossible: jest.fn(), | ||
selectListObjectAlternative: jest.fn(), | ||
selectListObjectExcluded: jest.fn(), | ||
}; | ||
translator = { | ||
get: jest.fn((t) => t), | ||
}; | ||
selectionState = { | ||
clearItemStates: jest.fn(), | ||
}; | ||
}); | ||
|
||
const create = (overrides = {}) => | ||
createListboxSelectionToolbar({ | ||
layout, | ||
model, | ||
translator, | ||
selectionState, | ||
isDirectQuery, | ||
...overrides, | ||
}); | ||
|
||
it('should create all actions', () => { | ||
const actions = create(); | ||
expect(actions).toHaveLength(4); | ||
|
||
const [all, possible, alternative, excluded] = actions; | ||
|
||
expect(all).toMatchObject({ key: 'selectAll', label: 'Selection.SelectAll', type: 'menu-icon-button' }); | ||
expect(possible).toMatchObject({ | ||
key: 'selectPossible', | ||
label: 'Selection.SelectPossible', | ||
type: 'menu-icon-button', | ||
}); | ||
expect(alternative).toMatchObject({ | ||
key: 'selectAlternative', | ||
label: 'Selection.SelectAlternative', | ||
type: 'menu-icon-button', | ||
}); | ||
expect(excluded).toMatchObject({ | ||
key: 'selectExcluded', | ||
label: 'Selection.SelectExcluded', | ||
type: 'menu-icon-button', | ||
}); | ||
|
||
expect(all.enabled()).toEqual(true); | ||
expect(possible.enabled()).toEqual(true); | ||
expect(alternative.enabled()).toEqual(true); | ||
expect(excluded.enabled()).toEqual(true); | ||
}); | ||
|
||
it('should not create any actions if single select', () => { | ||
layout.qListObject.qDimensionInfo.qIsOneAndOnlyOne = true; | ||
const actions = create({ layout }); | ||
expect(actions).toEqual([]); | ||
}); | ||
|
||
it('should only create two actions in direct query mode', () => { | ||
const actions = create({ isDirectQuery: true }); | ||
expect(actions).toHaveLength(2); | ||
|
||
const [all, possible] = actions; | ||
|
||
expect(all).toMatchObject({ key: 'selectAll', label: 'Selection.SelectAll', type: 'menu-icon-button' }); | ||
expect(possible).toMatchObject({ | ||
key: 'selectPossible', | ||
label: 'Selection.SelectPossible', | ||
type: 'menu-icon-button', | ||
}); | ||
}); | ||
|
||
describe('test each action', () => { | ||
let all; | ||
let possible; | ||
let alternative; | ||
let excluded; | ||
|
||
beforeEach(() => { | ||
const actions = create(); | ||
[all, possible, alternative, excluded] = actions; | ||
|
||
expect(selectionState.clearItemStates).not.toHaveBeenCalled(); | ||
}); | ||
|
||
afterEach(() => { | ||
expect(selectionState.clearItemStates).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('select all', () => { | ||
all.action(); | ||
expect(model.selectListObjectAll).toHaveBeenCalledTimes(1); | ||
expect(model.selectListObjectAll).toBeCalledWith('/qListObjectDef'); | ||
}); | ||
it('select possible', () => { | ||
possible.action(); | ||
expect(model.selectListObjectPossible).toHaveBeenCalledTimes(1); | ||
expect(model.selectListObjectPossible).toBeCalledWith('/qListObjectDef'); | ||
}); | ||
it('select alternative', () => { | ||
alternative.action(); | ||
expect(model.selectListObjectAlternative).toHaveBeenCalledTimes(1); | ||
expect(model.selectListObjectAlternative).toBeCalledWith('/qListObjectDef'); | ||
}); | ||
it('select excluded', () => { | ||
excluded.action(); | ||
expect(model.selectListObjectExcluded).toHaveBeenCalledTimes(1); | ||
expect(model.selectListObjectExcluded).toBeCalledWith('/qListObjectDef'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
apis/nucleus/src/components/listbox/utils/__tests__/is-direct-query.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { default: isDirectQueryEnabled } = require('../is-direct-query'); | ||
|
||
describe('isDirectQuery', () => { | ||
const appLayout = { qIsDirectQueryMode: false }; | ||
|
||
test('should return false since app is not a DQ app', async () => { | ||
const dq = isDirectQueryEnabled({ appLayout }); | ||
expect(dq).toEqual(false); | ||
}); | ||
|
||
test('should return true since it is a DQ app', async () => { | ||
appLayout.qIsDirectQueryMode = true; | ||
const dq = isDirectQueryEnabled({ appLayout }); | ||
expect(dq).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default function isDirectQueryEnabled({ appLayout }) { | ||
const isDQ = !!appLayout?.qIsDirectQueryMode; | ||
return isDQ; | ||
} |