import React from 'react'; import '@testing-library/jest-dom'; import { act, cleanup, render } from '@testing-library/react'; import SolarCast from './SolarCast'; import { advanceBy, clear} from 'jest-date-mock'; import { eventLength, urlEvents, views } from './mocks'; // These lengths should always be longer than 8s // Due the the max loading time defined in // ./src/Package/Components/ViewRenderer.tsx beforeEach(() => { jest.useFakeTimers(); }); afterEach(() => { clear(); cleanup(); jest.clearAllTimers(); jest.useRealTimers(); }); /** * ░ 0 * ▓ 1 * > ░ 2 * ▓ 3 * ▓ 4 * ░ 5 */ it('Solarcast should render correctly at url event index 2', function () { const { queryByTestId } = render( ); expect(queryByTestId('view-idle')).toBeInTheDocument(); expect(queryByTestId('view-url-1')).not.toBeInTheDocument(); expect(queryByTestId('view-url-2')).not.toBeInTheDocument(); expect(queryByTestId('view-url-3')).not.toBeInTheDocument(); act(() => { advanceBy(eventLength * 1000); jest.advanceTimersByTime(eventLength * 1000); }); expect(queryByTestId('view-idle')).toBeInTheDocument(); expect(queryByTestId('view-url-1')).not.toBeInTheDocument(); expect(queryByTestId('view-url-2')).toBeInTheDocument(); expect(queryByTestId('view-url-3')).not.toBeInTheDocument(); });