import * as React from 'react';
import {
  describe,
  it,
  jest,
  beforeAll,
  afterEach,
  afterAll,
} from '@jest/globals';
import { render, screen, waitFor } from '@testing-library/react';
import { http, HttpResponse } from 'msw';
import { setupServer } from 'msw/node';
import { BrowserRouter } from 'react-router-dom';
import { ChakraProvider, theme as chakraTheme } from '@chakra-ui/react';
import { Provider } from 'react-redux';

import ErrorBoundary from '../../components/ErrorBoundary';
import { store } from '../../__data__/store';
import Page from '../arm';

const server = setupServer(
  http.post('/api/arm/orders', () => {
    return HttpResponse.json({
      success: true,
      body: [],
    });
  }),
  http.get('/api/arm/masters', () => {
    return HttpResponse.json({
      success: true,
      body: [],
    });
  }),
);

jest.mock('@brojs/cli', () => {
  return {
    getNavigationValue: () => '/auth/login',
    getConfigValue: () => '/api',
  };
});

describe('order page', () => {
  beforeAll(() => server.listen());
  afterEach(() => server.resetHandlers());
  afterAll(() => server.close());

  it('получение пустого списка', async () => {
    render(
      <Provider store={store}>
        <ChakraProvider theme={chakraTheme}>
          <ErrorBoundary>
            <BrowserRouter>
              <Page mockUser={{ name: 'ilnaz' }} />
            </BrowserRouter>
          </ErrorBoundary>
        </ChakraProvider>
      </Provider>,
    );

    await waitFor(() => screen.getByText('Список пуст'));
  });
});
