1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

fix: show popover on empty state (#5611)

This commit is contained in:
Mateusz Kwasniewski 2023-12-12 11:40:00 +01:00 committed by GitHub
parent 43c563af57
commit 850b78a699
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 4 deletions

View File

@ -5,7 +5,7 @@ import { FilterDateItem, IFilterDateItemProps } from './FilterDateItem';
const getDate = (option: string) => screen.getByText(option); const getDate = (option: string) => screen.getByText(option);
const setup = (initialState: FilterItemParams) => { const setup = (initialState: FilterItemParams | null) => {
const recordedChanges: FilterItemParams[] = []; const recordedChanges: FilterItemParams[] = [];
const mockProps: IFilterDateItemProps = { const mockProps: IFilterDateItemProps = {
label: 'Test Label', label: 'Test Label',
@ -51,6 +51,14 @@ describe('FilterDateItem Component', () => {
]); ]);
}); });
it('renders initial popover when no existing value', async () => {
const mockState = null;
const recordedChanges = setup(mockState);
await screen.findByText('21');
});
it('switches operator', async () => { it('switches operator', async () => {
const mockState = { const mockState = {
operator: 'IS_ON_OR_AFTER', operator: 'IS_ON_OR_AFTER',

View File

@ -33,7 +33,9 @@ export const FilterDateItem: FC<IFilterDateItemProps> = ({
}; };
useEffect(() => { useEffect(() => {
open(); if (!state) {
open();
}
}, []); }, []);
const onClose = () => { const onClose = () => {

View File

@ -5,7 +5,7 @@ import { FilterItem, FilterItemParams, IFilterItemProps } from './FilterItem';
const getOption = (option: string) => const getOption = (option: string) =>
screen.getByText(option).closest('li')!.querySelector('input')!; screen.getByText(option).closest('li')!.querySelector('input')!;
const setup = (initialState: FilterItemParams) => { const setup = (initialState: FilterItemParams | null) => {
const recordedChanges: FilterItemParams[] = []; const recordedChanges: FilterItemParams[] = [];
const mockProps: IFilterItemProps = { const mockProps: IFilterItemProps = {
label: 'Test Label', label: 'Test Label',
@ -67,6 +67,14 @@ describe('FilterItem Component', () => {
]); ]);
}); });
it('renders initial popover when no existing value', async () => {
const mockState = null;
const recordedChanges = setup(mockState);
await screen.findByPlaceholderText('Search');
});
it('renders explicit and extra options', async () => { it('renders explicit and extra options', async () => {
const mockState = { const mockState = {
operator: 'IS_ANY_OF', operator: 'IS_ANY_OF',

View File

@ -46,7 +46,9 @@ export const FilterItem: FC<IFilterItemProps> = ({
}; };
useEffect(() => { useEffect(() => {
open(); if (!state) {
open();
}
}, []); }, []);
const onClose = () => { const onClose = () => {