import { mockFailureResponse } from '../../../mocks/server';
import { expectPageTestIds, expectPageTitle } from '../../../utils/test/expects';
import RootPage, { ROOT_PAGE_TITLE } from '../index';
import { renderWithClient } from '../../../utils/test/react-query';
import { createRouterWrapper } from '../../../utils/test/react-router-dom';
import App from '../../../App';
import { MemoryRouter } from 'react-router-dom';

describe('RootPage component', () => {
  test('successful render component', async () => {
    const result = renderWithClient(<RootPage />, MemoryRouter);
    await expectPageTitle(ROOT_PAGE_TITLE);
    await expectPageTestIds(result);
  });

  test('not redirect to login with not authenticated user', async () => {
    mockFailureResponse();
    renderWithClient(<App />, createRouterWrapper('/'));
    expect(window.location.pathname).not.toBe('/login');
  });
});
