- {/* Sort Controls */}
+ {/* Sort Controls / Result Count */}
-
{results.length} results found
+
+ Showing{' '}
+
+ {results.length === 0 ? 0 : startIndex + 1}–{endIndex}
+ {' '}
+ of{' '}
+ {results.length}{' '}
+ results
+
{onSortChange && (
- {results.map((course) => (
+ {/* Results Grid — only the current page's slice */}
+
+ {visibleResults.map((course) => (
= ({
))}
+
+ {/* Pagination Bar */}
+ {totalPages > 1 && (
+
+ )}
);
};
diff --git a/src/app/components/search/__tests__/SearchResults.test.tsx b/src/app/components/search/__tests__/SearchResults.test.tsx
new file mode 100644
index 00000000..6e2e8a7d
--- /dev/null
+++ b/src/app/components/search/__tests__/SearchResults.test.tsx
@@ -0,0 +1,262 @@
+import React from 'react';
+import { render, screen, fireEvent, within } from '@testing-library/react';
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+import { SearchResults, CourseResult } from '../SearchResults';
+
+// ─── Helpers ────────────────────────────────────────────────────────────────
+
+function makeCourse(n: number): CourseResult {
+ return {
+ id: `course-${n}`,
+ title: `Course ${n}`,
+ instructor: `Instructor ${n}`,
+ duration: '2h',
+ rating: 4.5,
+ price: 29.99,
+ originalPrice: null,
+ category: 'Engineering',
+ level: 'beginner',
+ image: `/img/${n}.jpg`,
+ tag: null,
+ color: '#000',
+ };
+}
+
+function makeCourses(count: number): CourseResult[] {
+ return Array.from({ length: count }, (_, i) => makeCourse(i + 1));
+}
+
+// ─── Mocks ──────────────────────────────────────────────────────────────────
+
+// next/link renders as a plain