<commit_before>import React, { useContext } from 'react';
import { render, act, screen, cleanup } from '@testing-library/react';
import { AuthContext, AuthProvider } from './AuthContext.js';

jest.useFakeTimers();

// Mock the the Firebase Auth onAuthStateChanged function, which pauses for 1
// second before returning a fake user with only a name field set.
const mockOnAuthStateChanged = jest.fn(callback => {
  setTimeout(() => {
    callback({ name: 'Keiffer' })
  }, 1000);
});
jest.mock('firebase/app', () => {
  return {
    initializeApp: () => {
      return {
        auth: () => {
          return {
            onAuthStateChanged: mockOnAuthStateChanged
          }
        }
      }
    }
  }
});

describe('AuthProvider component', () => {
  beforeEach(() => {
    render(<AuthProvider />);
  });

  afterEach(() => {
    cleanup();
  });

  it('initially displays "Loading"', () => {
    act(() => jest.advanceTimersByTime(500));
    expect(screen.getByText('Loading...')).toBeInTheDocument();
  });

  it('returns a provider when onAuthStateChanged is called', () => {
    act(() => jest.advanceTimersByTime(2000));
    expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
  });
});

describe('AuthContext Consumer component', () => {
  // A Consumer component for AuthContext that just displays the current
  // user.
  const TestAuthContextConsumerComponent = () => {
    const {currentUser} = useContext(AuthContext);

    return (
      <div>
        <div>{currentUser.name}</div>
      </div>
    );
  }

  beforeEach(() => {
    render(
      <AuthProvider>
        <TestAuthContextConsumerComponent />
      </AuthProvider>
    );
  })

  afterEach(() => {
    cleanup();
  })

  it('initially displays "Loading"', () => {
    act(() => jest.advanceTimersByTime(500));
    expect(screen.getByText('Loading...')).toBeInTheDocument();
  });

  it('displays the current user when they are authenticated', () => {
    act(() => jest.advanceTimersByTime(2000));
    expect(screen.getByText('Keiffer')).toBeInTheDocument();
  })
});<commit_msg>Clean test file<commit_after>import React, { useContext } from 'react';
import { render, act, screen, cleanup } from '@testing-library/react';
import { AuthContext, AuthProvider } from './AuthContext.js';

jest.useFakeTimers();

// Mock the the Firebase Auth onAuthStateChanged function, which pauses for 1
// second before returning a fake user with only a name field set.
const mockOnAuthStateChanged = jest.fn(callback => {
  setTimeout(() => {
    callback({ name: 'Keiffer' })
  }, 1000);
});
jest.mock('firebase/app', () => {
  return {
    initializeApp: () => {
      return {
        auth: () => {
          return {
            onAuthStateChanged: mockOnAuthStateChanged
          }
        }
      }
    }
  }
});

describe('AuthProvider component', () => {
  beforeEach(() => { render(<AuthProvider />) });

  afterEach(cleanup);

  it('initially displays "Loading"', () => {
    act(() => jest.advanceTimersByTime(500));
    expect(screen.getByText('Loading...')).toBeInTheDocument();
  });

  it('returns a provider when onAuthStateChanged is called', () => {
    act(() => jest.advanceTimersByTime(2000));
    expect(screen.queryByText('Loading...')).not.toBeInTheDocument();
  });
});

describe('AuthContext Consumer component', () => {
  // A Consumer component for AuthContext that just displays the current
  // user.
  const TestAuthContextConsumerComponent = () => {
    const {currentUser} = useContext(AuthContext);

    return (
      <div>
        <div>{currentUser.name}</div>
      </div>
    );
  };

  beforeEach(() => {
    render(
      <AuthProvider>
        <TestAuthContextConsumerComponent />
      </AuthProvider>
    );
  });

  afterEach(() => {
    cleanup();
  });

  it('initially displays "Loading"', () => {
    act(() => jest.advanceTimersByTime(500));
    expect(screen.getByText('Loading...')).toBeInTheDocument();
  });

  it('displays the current user when they are authenticated', () => {
    act(() => jest.advanceTimersByTime(2000));
    expect(screen.getByText('Keiffer')).toBeInTheDocument();
  });
});
{'fraction_non_alphanumeric': 0.17288135593220338, 'fraction_numerical': 0.009200968523002421, 'mean_word_length': 3.2282497441146365, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6195033', 'n_tokens_mistral': 1272, 'n_tokens_neox': 1217, 'n_words': 253}