kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
				
				
				
			Add tests for Search
							rodzic
							
								
									35f878526f
								
							
						
					
					
						commit
						f8b6f8db28
					
				| 
						 | 
				
			
			@ -125,7 +125,7 @@ const Account = ({
 | 
			
		|||
  const LinkEl: any = showProfileHoverCard ? Link : 'div';
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
    <div className='flex-shrink-0 group block w-full overflow-hidden' ref={overflowRef}>
 | 
			
		||||
    <div data-testid='account' className='flex-shrink-0 group block w-full overflow-hidden' ref={overflowRef}>
 | 
			
		||||
      <HStack alignItems={actionAlignment} justifyContent='between'>
 | 
			
		||||
        <HStack alignItems='center' space={3} grow>
 | 
			
		||||
          <ProfilePopper
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -289,6 +289,7 @@ export default class AutosuggestInput extends ImmutablePureComponent {
 | 
			
		|||
          aria-autocomplete='list'
 | 
			
		||||
          id={id}
 | 
			
		||||
          maxLength={maxLength}
 | 
			
		||||
          data-testid='autosuggest-input'
 | 
			
		||||
        />
 | 
			
		||||
 | 
			
		||||
        <div className={classNames({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
import userEvent from '@testing-library/user-event';
 | 
			
		||||
import React from 'react';
 | 
			
		||||
 | 
			
		||||
import { __stub } from 'soapbox/api';
 | 
			
		||||
 | 
			
		||||
import { render, screen } from '../../../../jest/test-helpers';
 | 
			
		||||
import Search from '../search';
 | 
			
		||||
 | 
			
		||||
describe('<Search />', () => {
 | 
			
		||||
  it('successfully renders', async() => {
 | 
			
		||||
    render(<Search autosuggest />);
 | 
			
		||||
    expect(screen.getByLabelText('Search')).toBeInTheDocument();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('handles onChange', async() => {
 | 
			
		||||
    __stub(mock => {
 | 
			
		||||
      mock.onGet('/api/v1/accounts/search').reply(200, [{ id: 1 }]);
 | 
			
		||||
    });
 | 
			
		||||
    const user = userEvent.setup();
 | 
			
		||||
 | 
			
		||||
    render(<Search autosuggest />);
 | 
			
		||||
 | 
			
		||||
    await user.type(screen.getByLabelText('Search'), '@jus');
 | 
			
		||||
 | 
			
		||||
    expect(screen.getByLabelText('Search')).toHaveValue('@jus');
 | 
			
		||||
    expect(screen.getByTestId('account')).toBeInTheDocument();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -8,3 +8,6 @@ afterEach(() => clearApiMocks());
 | 
			
		|||
 | 
			
		||||
// Mock external dependencies
 | 
			
		||||
jest.mock('uuid', () => ({ v4: jest.fn(() => 1) }));
 | 
			
		||||
 | 
			
		||||
const intersectionObserverMock = () => ({ observe: () => null, disconnect: () => null });
 | 
			
		||||
window.IntersectionObserver = jest.fn().mockImplementation(intersectionObserverMock);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue