|
| 1 | +import * as React from 'react'; |
| 2 | +import { fireEvent, render, screen } from '@testing-library/react'; |
| 3 | +import { |
| 4 | + Basic, |
| 5 | + ErrorState, |
| 6 | + LoadingState, |
| 7 | + Offline, |
| 8 | +} from './ReferenceManyCountBase.stories'; |
| 9 | + |
| 10 | +describe('ReferenceManyCountBase', () => { |
| 11 | + it('should display an error if error is defined', async () => { |
| 12 | + jest.spyOn(console, 'error') |
| 13 | + .mockImplementationOnce(() => {}) |
| 14 | + .mockImplementationOnce(() => {}); |
| 15 | + |
| 16 | + render(<ErrorState />); |
| 17 | + await screen.findByText('Error!'); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should display the loading state', async () => { |
| 21 | + render(<LoadingState />); |
| 22 | + await screen.findByText('loading...', undefined, { timeout: 2000 }); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should render the total', async () => { |
| 26 | + render(<Basic />); |
| 27 | + await screen.findByText('3'); |
| 28 | + }); |
| 29 | + |
| 30 | + it('should render the offline prop node when offline', async () => { |
| 31 | + render(<Offline />); |
| 32 | + fireEvent.click(await screen.findByText('Simulate offline')); |
| 33 | + fireEvent.click(await screen.findByText('Toggle Child')); |
| 34 | + await screen.findByText('You are offline, cannot load data'); |
| 35 | + fireEvent.click(await screen.findByText('Simulate online')); |
| 36 | + await screen.findByText('3'); |
| 37 | + fireEvent.click(await screen.findByText('Simulate offline')); |
| 38 | + expect( |
| 39 | + screen.queryByText('You are offline, cannot load data') |
| 40 | + ).toBeNull(); |
| 41 | + await screen.findByText('3'); |
| 42 | + fireEvent.click(await screen.findByText('Simulate online')); |
| 43 | + }); |
| 44 | +}); |
0 commit comments