A drag-and-drop interface for creating and customizing layouts with various elements like text, images, and shapes.
Live Demo: https://dnd.rehanqasim.com
- Interactive drag-and-drop functionality
- Support for text, image, and shape elements
- Custom properties panel for editing elements
- Real-time visual feedback
- Save and load functionality
- Responsive design
- Node.js 18.x or higher
- npm
Follow these steps to set up and run the project locally:
git clone <repository-url>
cd drag-and-drop-playground
npm install
npm run dev
Open http://localhost:3000 in your browser to see the application.
This project uses Jest and React Testing Library for testing.
Various test commands are available to run tests in different modes:
npm test
npm run test:watch
This will re-run tests automatically when files change, making it ideal for development.
npm test -- components/canvas.test.tsx
npm test -- -t "should render sidebar elements"
npm test -- canvas
npm test -- components/elements
npm run test:coverage
The project uses Jest with the following configuration:
- Test Environment: JSDOM (browser-like environment)
- Setup File:
jest.setup.ts
configures common mocks including:window.matchMedia
for responsive design testingnext/navigation
hooks for route testing
- Custom Test Utilities: Located in
__tests__/utils/test-utils.tsx
You can debug tests in VS Code by:
- Setting breakpoints in your test files
- Using the JavaScript Debug Terminal
- Running
npm test:debug
to launch tests with the debugger attached
For more verbose output, use:
npm test -- --verbose
The project maintains test coverage across multiple components and utilities:
Category | Coverage |
---|---|
Components | Core components including Canvas, Sidebar, and Theme Provider |
Elements | Text, Shape, and Image elements with draggable functionality |
UI Components | Button and other UI primitives |
Utilities | Helper functions in /lib |
Coverage reports are generated in the coverage
directory with the following formats:
- HTML report:
coverage/lcov-report/index.html
(open in browser for interactive view) - lcov:
coverage/lcov.info
(for CI integration) - JSON:
coverage/coverage-final.json
(for custom tooling) - Clover XML:
coverage/clover.xml
(for CI/CD systems)
To view the HTML coverage report:
# Generate the report
npm run test:coverage
# Open the report in your default browser (macOS)
open coverage/lcov-report/index.html
The report provides detailed metrics including:
- Line coverage
- Function coverage
- Branch coverage
- Statement coverage
Tests are organized to mirror the application structure:
__tests__/components/
- Component testscanvas.test.tsx
- Tests for Canvas componentsidebar.test.tsx
- Tests for Sidebar componenttheme-provider.test.tsx
- Tests for Theme Providerelements/
- Tests for draggable elementsshape-element.test.tsx
- Shape element teststext-element.test.tsx
- Text element tests
ui/
- UI component testsbutton.test.tsx
- Button component tests
__tests__/lib/
- Utility function testsutils.test.ts
- Tests for utility functions
__tests__/utils/
- Test helperstest-utils.tsx
- Custom render functions and test utilities
Custom test utilities are available in __tests__/utils/test-utils.tsx
to help with:
- Setting up providers (DnD, theme)
- Mock implementations
- Custom render functions
When writing new tests, follow these conventions:
- Create test files that match the structure and naming of your source files
- Use the custom render utilities from
test-utils.tsx
- Mock external dependencies and browser APIs as needed
- Write tests that focus on component behavior and user interactions
- Avoid testing implementation details
To create an optimized production build:
npm run build
To start the production server:
npm start