Skip to content

Conversation

@szirpesf
Copy link
Contributor

Summary

This PR introduces a complete product comparison feature that allows users to compare up to 4 products side-by-side, with persistent state across browser sessions.

Features Added

Core Functionality

  • Product Comparison System with up to 4 products
  • Persistent state via localStorage
  • Responsive design (mobile cards, desktop table)
  • Real-time updates with floating badge

New Components

  1. ComparisonProvider - Global state management with localStorage persistence
  2. useComparison Hook - Convenient access to comparison functionality
  3. CompareButton - Reusable button/icon component for adding products
  4. ComparisonDrawer - Side drawer for quick product management
  5. ComparisonBadge - Floating badge for quick access
  6. ProductComparison Page - Full comparison page at /compare

Integration Points

  • Added comparison functionality to ProductView and ProductTile components
  • Integrated ComparisonProvider into App component
  • Added comparison route to routing configuration
  • Export useComparison hook from hooks index

Technical Details

Files Added

  • PRODUCT_COMPARISON.md - Complete feature documentation
  • app/components/compare-button/ - Button component with tests
  • app/components/comparison-badge/ - Floating badge component
  • app/components/comparison-drawer/ - Side drawer component
  • app/contexts/comparison-provider.jsx - Context provider
  • app/hooks/use-comparison.js - Hook with tests
  • app/pages/product-comparison/ - Comparison page

User Experience

  • Toast notifications for user feedback
  • Maximum 4 products with duplicate prevention
  • Easy removal from comparison list
  • Redirects to home if no products selected

Accessibility

  • Proper ARIA labels throughout
  • Keyboard navigation support
  • Screen reader friendly

Testing

  • Unit tests for useComparison hook
  • Unit tests for CompareButton component
  • Tests cover state management and persistence

Documentation

Complete documentation in PRODUCT_COMPARISON.md including:

  • API reference
  • Usage examples
  • Integration guide
  • Testing instructions

✨ New Features:
- Product comparison with up to 4 products
- Side drawer for quick comparison management
- Dedicated comparison page with responsive design
- Floating comparison badge for easy access
- localStorage persistence across sessions

🏗️ Implementation:
- ComparisonProvider context for global state management
- useComparison hook for easy integration
- CompareButton component with icon and button variants
- ComparisonDrawer for quick product management
- ComparisonBadge floating indicator
- ProductComparison page with detailed comparison table

🔧 Integration Points:
- Added compare buttons to ProductTile components
- Integrated comparison into ProductView (product detail page)
- Enabled comparison on product list pages
- Added /compare route for full comparison experience

🧪 Testing & Quality:
- Comprehensive unit tests for hook and components
- Accessibility features (ARIA labels, keyboard navigation)
- Internationalization support with react-intl
- Error handling and user feedback via toasts

📱 User Experience:
- Responsive design (table on desktop, cards on mobile)
- Smooth animations and transitions
- Toast notifications for user feedback
- Maximum 4 products limit with duplicate prevention

📚 Documentation:
- Complete feature documentation in PRODUCT_COMPARISON.md
- Code examples and usage patterns
- API documentation for all components and hooks

This feature enables users to compare products side-by-side with a seamless,
accessible, and responsive experience following PWA Kit best practices.
@szirpesf szirpesf requested a review from a team as a code owner December 30, 2025 03:31
@salesforce-cla
Copy link

Thanks for the contribution! Before we can merge this, we need @szirpe to sign the Salesforce Inc. Contributor License Agreement.

@cc-prodsec
Copy link
Collaborator

cc-prodsec commented Dec 30, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@szirpesf szirpesf marked this pull request as draft December 30, 2025 03:33
@szirpesf szirpesf changed the title Add Comprehensive Product Comparison Functionality DRAFT - DO NOT MERGE - TEST PR ONLY Dec 30, 2025
duration: 2000
})
}
} catch (error) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catch is not needed

expect(screen.getByText(/removed from comparison/i)).toBeInTheDocument()
})

test('prevents adding when maximum products reached', async () => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants