Skip to content
Snippets Groups Projects
Select Git revision
  • 593e81be91f0e9ccee5406235464ea65cb630ec3
  • mui5-annotation-on-video-stable default
  • get_setter_canvasSizeInformations
  • fix-error-div-into-p
  • annotation-on-video-v2
  • detached
  • annotation-on-video-r17
  • mui5
  • mui5-react-18
  • jacob-test
  • annotation-on-video protected
  • master
  • test-antoinev1
  • 20-fetch-thumbnail-on-annotation
  • add-research-field
  • Save
  • add-plugin
  • 14-wip-no-seek-to
  • 14-bug-on-video-time-control
  • 9_wip_videotests
  • _upgrade_material_ui
  • latest-tetras-16
  • v3.3.0
  • v3.2.0
  • v3.1.1
  • v3.1.0
  • v3.0.0
  • v3.0.0-rc.7
  • v3.0.0-rc.6
  • v3.0.0-rc.5
  • v3.0.0-rc.4
  • v3.0.0-rc.3
  • v3.0.0-rc.2
  • v3.0.0-rc.1
  • v3.0.0-beta.10
  • v3.0.0-beta.9
  • v3.0.0-beta.8
  • v3.0.0-beta.7
  • v3.0.0-beta.6
  • v3.0.0-beta.5
  • v3.0.0-beta.3
41 results

SearchPanel.test.js

Blame
  • user avatar
    Chris Beer authored
    53c39085
    History
    SearchPanel.test.js 2.80 KiB
    import { render, screen } from 'test-utils';
    import userEvent from '@testing-library/user-event';
    import i18next from 'i18next';
    
    import { SearchPanel } from '../../../src/components/SearchPanel';
    
    /**
     * Helper function to create a shallow wrapper around SearchPanel
     */
    function createWrapper(props) {
      return render(
        <SearchPanel
          id="xyz"
          fetchSearch={() => {}}
          searchService={{ id: 'http://example.com/search' }}
          windowId="window"
          {...props}
        />,
        { preloadedState: { companionWindows: { xyz: { content: 'search' } } } },
      );
    }
    
    describe('SearchPanel', () => {
      it('renders a CompanionWindow', () => {
        createWrapper();
        expect(screen.getByRole('complementary')).toBeInTheDocument();
        expect(screen.getByRole('heading', { name: 'searchTitle' })).toBeInTheDocument();
      });
    
      it('passes a Clear chip as the CompanionWindow title prop', () => {
        createWrapper({ query: 'Wolpertinger' });
    
        expect(screen.getByRole('heading', { name: /searchTitle/ })).toBeInTheDocument();
        expect(screen.getByRole('button', { name: 'clearSearch' })).toBeInTheDocument();
      });
    
      it('the Clear chip calls the removeSearch prop', async () => {
        const user = userEvent.setup();
        const removeSearch = jest.fn();
    
        createWrapper({ query: 'Wolpertinger', removeSearch });
    
        await user.click(screen.getByRole('button', { name: 'clearSearch' }));
    
        expect(removeSearch).toHaveBeenCalled();
      });
    
      it('does not render a Clear chip if there is no search query to be cleared', () => {
        createWrapper();
    
        expect(screen.queryByRole('button', { name: 'clearSearch' })).not.toBeInTheDocument();
      });
    
      it('has the SearchPanelControls component', () => {
        createWrapper();
    
        expect(screen.getByRole('combobox', { name: 'searchInputLabel' })).toBeInTheDocument();
        expect(screen.getByRole('button', { name: 'searchSubmitAria' })).toBeInTheDocument();
      });
    
      it('has the SearchResults list', () => {
        createWrapper();
    
        expect(screen.getByRole('list')).toBeInTheDocument();
      });
    
      it('suggests searches', async () => {
        const user = userEvent.setup();
        const fetchSearch = jest.fn();
        createWrapper({
          fetchSearch, query: '', suggestedSearches: ['abc'], t: i18next.t,
        });
    
        expect(screen.getByRole('button', { name: 'Search this document for "abc"' })).toBeInTheDocument();
        await user.click(screen.getByRole('button', { name: 'Search this document for "abc"' }));
        expect(fetchSearch).toHaveBeenCalledWith('http://example.com/search?q=abc', 'abc');
      });
    
      it('does not suggest searches if the user has made a query', () => {
        const fetchSearch = jest.fn();
        createWrapper({ fetchSearch, query: 'blah', suggestedSearches: ['abc'] });
    
        expect(screen.queryByRole('button', { name: 'Search this document for "abc"' })).not.toBeInTheDocument();
      });
    });