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

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

  test('redirect to login with not authenticated user', async () => {
    mockFailureResponse();
    const result = renderWithClient(<App />, createRouterWrapper('/home'));
    await expectRedirectedToLoginPage(result);
  });
});
