-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
55 changed files
with
1,851 additions
and
339 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { getDefaultControlGroupInput } from '..'; | ||
import { ControlGroupInput } from './types'; | ||
|
||
export const mockControlGroupInput = (partial?: Partial<ControlGroupInput>): ControlGroupInput => ({ | ||
id: 'mocked_control_group', | ||
...getDefaultControlGroupInput(), | ||
...{ | ||
panels: { | ||
control1: { | ||
order: 0, | ||
width: 'medium', | ||
grow: true, | ||
type: 'mockedOptionsList', | ||
explicitInput: { | ||
id: 'control1', | ||
}, | ||
}, | ||
control2: { | ||
order: 1, | ||
width: 'large', | ||
grow: true, | ||
type: 'mockedRangeSlider', | ||
explicitInput: { | ||
id: 'control2', | ||
}, | ||
}, | ||
control3: { | ||
order: 2, | ||
width: 'small', | ||
grow: true, | ||
type: 'mockedOptionsList', | ||
explicitInput: { | ||
id: 'control3', | ||
}, | ||
}, | ||
}, | ||
}, | ||
...(partial ?? {}), | ||
}); |
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
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,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ReduxEmbeddableContext } from '@kbn/presentation-util-plugin/public/redux_embeddables/types'; | ||
import { ControlOutput } from '../../public/types'; | ||
import { | ||
OptionsListComponentState, | ||
OptionsListEmbeddableInput, | ||
OptionsListReduxState, | ||
} from '../../public/options_list/types'; | ||
import { optionsListReducers } from '../../public/options_list/options_list_reducers'; | ||
|
||
const mockOptionsListComponentState = { | ||
field: undefined, | ||
totalCardinality: 0, | ||
availableOptions: ['woof', 'bark', 'meow', 'quack', 'moo'], | ||
invalidSelections: [], | ||
validSelections: [], | ||
searchString: '', | ||
} as OptionsListComponentState; | ||
|
||
const mockOptionsListEmbeddableInput = { | ||
id: 'sample options list', | ||
fieldName: 'sample field', | ||
dataViewId: 'sample id', | ||
selectedOptions: [], | ||
runPastTimeout: false, | ||
singleSelect: false, | ||
} as OptionsListEmbeddableInput; | ||
|
||
const mockOptionsListOutput = { | ||
loading: false, | ||
} as ControlOutput; | ||
|
||
export const mockOptionsListContext = ( | ||
partialState?: Partial<OptionsListReduxState> | ||
): ReduxEmbeddableContext<OptionsListReduxState, typeof optionsListReducers> => { | ||
const mockReduxState = { | ||
componentState: { | ||
...mockOptionsListComponentState, | ||
...partialState?.componentState, | ||
}, | ||
explicitInput: { | ||
...mockOptionsListEmbeddableInput, | ||
...partialState?.explicitInput, | ||
}, | ||
output: { | ||
...mockOptionsListOutput, | ||
...partialState?.output, | ||
}, | ||
} as OptionsListReduxState; | ||
|
||
return { | ||
actions: {}, | ||
useEmbeddableDispatch: () => {}, | ||
useEmbeddableSelector: (selector: any) => selector(mockReduxState), | ||
} as unknown as ReduxEmbeddableContext<OptionsListReduxState, typeof optionsListReducers>; | ||
}; |
File renamed without changes.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,4 @@ | |
* Side Public License, v 1. | ||
*/ | ||
|
||
export * from './options_list'; | ||
export * from './range_slider'; |
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
File renamed without changes.
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
104 changes: 104 additions & 0 deletions
104
src/plugins/controls/public/options_list/components/options_list_popover.test.tsx
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,104 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { ReactWrapper } from 'enzyme'; | ||
|
||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { findTestSubject } from '@elastic/eui/lib/test'; | ||
import { EmbeddableReduxContext } from '@kbn/presentation-util-plugin/public/redux_embeddables/use_redux_embeddable_context'; | ||
|
||
import { OptionsListPopover, OptionsListPopoverProps } from './options_list_popover'; | ||
import { | ||
OptionsListComponentState, | ||
OptionsListEmbeddableInput, | ||
OptionsListReduxState, | ||
} from '../types'; | ||
import { ControlOutput } from '../..'; | ||
import { mockOptionsListContext } from '../../../common/mocks'; | ||
|
||
describe('Options list popover', () => { | ||
const defaultProps = { | ||
width: 500, | ||
updateSearchString: jest.fn(), | ||
}; | ||
|
||
interface MountOptions { | ||
componentState: Partial<OptionsListComponentState>; | ||
explicitInput: Partial<OptionsListEmbeddableInput>; | ||
output: Partial<ControlOutput>; | ||
popoverProps: Partial<OptionsListPopoverProps>; | ||
} | ||
|
||
function mountComponent(options?: Partial<MountOptions>) { | ||
const compProps = { ...defaultProps, ...(options?.popoverProps ?? {}) }; | ||
const context = mockOptionsListContext({ | ||
componentState: options?.componentState ?? {}, | ||
explicitInput: options?.explicitInput ?? {}, | ||
output: options?.output ?? {}, | ||
} as Partial<OptionsListReduxState>); | ||
|
||
return mountWithIntl( | ||
<EmbeddableReduxContext.Provider value={context}> | ||
<OptionsListPopover {...compProps} /> | ||
</EmbeddableReduxContext.Provider> | ||
); | ||
} | ||
|
||
const clickShowOnlySelections = (popover: ReactWrapper) => { | ||
const showOnlySelectedButton = findTestSubject( | ||
popover, | ||
'optionsList-control-show-only-selected' | ||
); | ||
showOnlySelectedButton.simulate('click'); | ||
}; | ||
|
||
test('available options list width responds to container size', () => { | ||
let popover = mountComponent({ popoverProps: { width: 301 } }); | ||
let availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
expect(availableOptionsDiv.getDOMNode().getAttribute('style')).toBe('width: 301px;'); | ||
|
||
// the div cannot be smaller than 301 pixels wide | ||
popover = mountComponent({ popoverProps: { width: 300 } }); | ||
availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
expect(availableOptionsDiv.getDOMNode().getAttribute('style')).toBe(null); | ||
}); | ||
|
||
test('no available options', () => { | ||
const popover = mountComponent({ componentState: { availableOptions: [] } }); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
const noOptionsDiv = findTestSubject( | ||
availableOptionsDiv, | ||
'optionsList-control-noSelectionsMessage' | ||
); | ||
expect(noOptionsDiv.exists()).toBeTruthy(); | ||
}); | ||
|
||
test('display error message when the show only selected toggle is true but there are no selections', () => { | ||
const popover = mountComponent(); | ||
clickShowOnlySelections(popover); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
const noSelectionsDiv = findTestSubject( | ||
availableOptionsDiv, | ||
'optionsList-control-selectionsEmptyMessage' | ||
); | ||
expect(noSelectionsDiv.exists()).toBeTruthy(); | ||
}); | ||
|
||
test('show only selected options', () => { | ||
const selections = ['woof', 'bark']; | ||
const popover = mountComponent({ | ||
explicitInput: { selectedOptions: selections }, | ||
}); | ||
clickShowOnlySelections(popover); | ||
const availableOptionsDiv = findTestSubject(popover, 'optionsList-control-available-options'); | ||
availableOptionsDiv.children().forEach((child, i) => { | ||
expect(child.text()).toBe(selections[i]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.