A highly customizable React top-loading bar component with hook-based, ref-based, and state-based control patterns.
64
Build a React application that displays a simulated file upload interface with an automatic progress indicator at the top of the page. The loading indicator should automatically progress while the upload is in progress, and allow manual completion when the upload finishes.
Create a component called FileUploadDemo that:
The top loading bar should:
Create the following files:
FileUploadDemo.jsx - Main component implementationFileUploadDemo.test.js - Test suiteProvides the UI framework.
Provides the loading indicator component.
Provides testing utilities for React components.
test('loading bar starts automatically when upload begins', () => {
render(<FileUploadDemo />);
const startButton = screen.getByText('Start Upload');
fireEvent.click(startButton);
// The loading bar should be present and animating
expect(screen.getByText('Uploading file...')).toBeInTheDocument();
});test('upload completes after 5 seconds', async () => {
jest.useFakeTimers();
render(<FileUploadDemo />);
const startButton = screen.getByText('Start Upload');
fireEvent.click(startButton);
expect(screen.getByText('Uploading file...')).toBeInTheDocument();
act(() => {
jest.advanceTimersByTime(5000);
});
await waitFor(() => {
expect(screen.getByText('Upload Complete!')).toBeInTheDocument();
});
jest.useRealTimers();
});test('reset button appears after completion and restarts demo', async () => {
jest.useFakeTimers();
render(<FileUploadDemo />);
// Start upload
fireEvent.click(screen.getByText('Start Upload'));
// Complete upload
act(() => {
jest.advanceTimersByTime(5000);
});
await waitFor(() => {
expect(screen.getByText('Reset')).toBeInTheDocument();
});
// Click reset
fireEvent.click(screen.getByText('Reset'));
expect(screen.getByText('Start Upload')).toBeInTheDocument();
jest.useRealTimers();
});The implementation should:
Install with Tessl CLI
npx tessl i tessl/npm-react-top-loading-barevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10