import { mockFailureResponse } from '../../../mocks/server';
import { expectPageTestIds, expectPageTitle } from '../../../utils/test/expects';
import TermsAndConditionsPage, { TERMS_AND_CONDITIONS_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('TermsAndConditionsPage component', () => {
  test('successful render component', async () => {
    const result = renderWithClient(<TermsAndConditionsPage />, MemoryRouter);
    await expectPageTitle(TERMS_AND_CONDITIONS_PAGE_TITLE);
    await expectPageTestIds(result);
    expect(
      await result.findByText('شرایط و قوانین سامانه همکاری در فروش فلش کارت های مدمشاور')
    ).toBeInTheDocument();
  });

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