import React from 'react';
import { describe, it, expect } from 'vitest';
import { Provider } from 'react-redux';
import { store } from '@/state/store';
import { ThemeProvider, createTheme } from '@mui/material/styles';
import { MemoryRouter } from 'react-router-dom';
import NavBar from '@/components/layout/Navbar/Navbar';
import { render, screen, fireEvent } from '@testing-library/react';

describe('Switch name menu — loading state', () => {
  it('shows Loading… while names are loading', async () => {
    render(
      <Provider store={store}>
        <ThemeProvider theme={createTheme()}>
          <MemoryRouter>
            <NavBar
              isAuthenticated={true}
              hasBlog={false}
              userName={'alice'}
              userAvatar={''}
              blog={null}
              authenticate={() => {}}
              hasAttemptedToFetchBlogInitial={false}
              allNames={[]}
              onSwitchActiveName={() => {}}
              userBlogs={[]}
              onSelectBlog={() => {}}
              authStatus={'succeeded'}
              namesStatus={'loading'}
            />
          </MemoryRouter>
        </ThemeProvider>
      </Provider>,
    );

    const trigger = screen.getByText('alice');
    fireEvent.click(trigger);
    expect(await screen.findByText((t) => /Loading/.test(t))).toBeInTheDocument();
  });
});
