import {useRef} from 'react';
import {useSearchParams} from 'react-router-dom';
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
import Link from 'sentry/components/links/link';
import {useLocation} from 'sentry/utils/useLocation';
import {useNavigate} from 'sentry/utils/useNavigate';
import {useParams} from 'sentry/utils/useParams';
describe('rerender', () => {
// Taken from https://testing-library.com/docs/example-update-props/
let idCounter = 1;
function NumberDisplay({number}: {number: number}) {
const id = useRef(idCounter++); // to ensure we don't remount a different instance
return (
{number}{id.current}
);
}
test('calling render with the same component on the same container does not remount', () => {
const {rerender} = render();
expect(screen.getByTestId('number-display')).toHaveTextContent('1');
// re-render the same component with different props
rerender();
expect(screen.getByTestId('number-display')).toHaveTextContent('2');
expect(screen.getByTestId('instance-id')).toHaveTextContent('1');
});
});
describe('disableRouterMocks', () => {
it('starts with the correct initial location', () => {
const {router} = render(, {
disableRouterMocks: true,
initialRouterConfig: {location: '/foo/'},
});
expect(router.location.pathname).toBe('/foo/');
});
it('should react to clicking a Link', async () => {
function TestComp() {
const location = useLocation();
return (