Skip to content
Snippets Groups Projects

fix(search): selecting from search prevents further search (MIN-245)

3 files
+ 97
3
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -7,6 +7,7 @@ import {
} from '@/utils/testing/getReduxWrapperWithStore';
import { fireEvent, render, screen } from '@testing-library/react';
import { useRouter } from 'next/router';
import { initialStateFixture } from '@/redux/drawer/drawerFixture';
import { SearchBar } from './SearchBar.component';
const renderComponent = (initialStore?: InitialStoreState): { store: StoreType } => {
@@ -114,4 +115,92 @@ describe('SearchBar - component', () => {
expect(reactions.data).toStrictEqual([]);
});
it('should open search drawer if it is not open', () => {
const { store } = renderComponent({
drawer: initialStateFixture,
});
const state = store.getState();
expect(state.drawer.isOpen).toBeFalsy();
const input = screen.getByTestId<HTMLInputElement>('search-input');
fireEvent.change(input, { target: { value: 'nadh' } });
const button = screen.getByRole('button');
fireEvent.click(button);
const {
drawer: { isOpen, drawerName },
} = store.getState();
expect(isOpen).toBeTruthy();
expect(drawerName).toBe('search');
});
it('should open the search drawer if any other drawer is open', () => {
const { store } = renderComponent({
drawer: {
...initialStateFixture,
drawerName: 'export',
isOpen: true,
},
});
const state = store.getState();
expect(state.drawer.isOpen).toBeTruthy();
const input = screen.getByTestId<HTMLInputElement>('search-input');
fireEvent.change(input, { target: { value: 'nadh' } });
const button = screen.getByRole('button');
fireEvent.click(button);
const {
drawer: { isOpen, drawerName },
} = store.getState();
expect(isOpen).toBeTruthy();
expect(drawerName).toBe('search');
});
it('should only select tab if search drawer is already open', () => {
const { store } = renderComponent({
drawer: {
...initialStateFixture,
drawerName: 'search',
isOpen: true,
searchDrawerState: {
...initialStateFixture.searchDrawerState,
selectedSearchElement: '',
},
},
});
const state = store.getState();
const { drawer } = state;
expect(drawer.isOpen).toBeTruthy();
expect(drawer.searchDrawerState.selectedSearchElement).toBe('');
const input = screen.getByTestId<HTMLInputElement>('search-input');
fireEvent.change(input, { target: { value: 'nadh' } });
const button = screen.getByRole('button');
fireEvent.click(button);
const {
drawer: {
isOpen,
drawerName,
searchDrawerState: { selectedSearchElement },
},
} = store.getState();
expect(isOpen).toBeTruthy();
expect(drawerName).toBe('search');
expect(selectedSearchElement).toBe('nadh');
});
});
Loading