|
| 1 | +import React from 'react'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import LoadingOverlay from './LoadingOverlay'; |
| 4 | + |
| 5 | +describe('LoadingOverlay', () => { |
| 6 | + it('renders loading spinner and no scrim on initial loading', () => { |
| 7 | + const { container } = render( |
| 8 | + <LoadingOverlay isLoading data-testid="test-overlay" /> |
| 9 | + ); |
| 10 | + expect(screen.getByTestId('test-overlay-spinner')).toBeInTheDocument(); |
| 11 | + expect( |
| 12 | + container.getElementsByClassName('iris-panel-scrim-background').length |
| 13 | + ).toBe(0); |
| 14 | + }); |
| 15 | + |
| 16 | + it('renders error message and no scrim when errorMessage is provided on initial loading', () => { |
| 17 | + const errorMessage = 'An error occurred'; |
| 18 | + const { container } = render( |
| 19 | + <LoadingOverlay errorMessage={errorMessage} /> |
| 20 | + ); |
| 21 | + const errorElement = screen.getByText(errorMessage); |
| 22 | + expect(errorElement).toBeInTheDocument(); |
| 23 | + expect( |
| 24 | + container.getElementsByClassName('iris-panel-scrim-background').length |
| 25 | + ).toBe(0); |
| 26 | + }); |
| 27 | + |
| 28 | + it('renders scrim when loaded and errorMessage is provided', () => { |
| 29 | + const { container } = render( |
| 30 | + <LoadingOverlay isLoaded errorMessage="ERROR_MESSAGE" /> |
| 31 | + ); |
| 32 | + expect( |
| 33 | + container.getElementsByClassName('iris-panel-scrim-background').length |
| 34 | + ).toBe(1); |
| 35 | + }); |
| 36 | + |
| 37 | + it('renders scrim when isLoaded is true and loading again', () => { |
| 38 | + const { container } = render(<LoadingOverlay isLoaded isLoading />); |
| 39 | + expect( |
| 40 | + container.getElementsByClassName('iris-panel-scrim-background').length |
| 41 | + ).toBe(1); |
| 42 | + }); |
| 43 | +}); |
0 commit comments