Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat(admin): add backend search to Companies, Job Titles, and Skills lists

Khuram Niaz414a6bdd1dd8
diff --git a/__tests__/CompaniesContainer.spec.tsx b/__tests__/CompaniesContainer.spec.tsx
new file mode 100644
index 0000000..e77cff6
--- /dev/null
+++ b/__tests__/CompaniesContainer.spec.tsx
@@ -0,0 +1,254 @@
+import CompaniesContainer from "@/components/admin/CompaniesContainer";
+import { screen, render, waitFor, act } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { getCompanyList, getCompanyById } from "@/actions/company.actions";
+
+vi.mock("@/actions/company.actions", () => ({
+ getCompanyList: vi.fn(),
+ getCompanyById: vi.fn(),
+ deleteCompanyById: vi.fn(),
+ addCompany: vi.fn(),
+ updateCompany: vi.fn(),
+}));
+
+describe("CompaniesContainer Search Functionality", () => {
+ const mockCompanies = [
+ { id: "1", label: "Amazon", value: "amazon", createdBy: "user-1" },
+ { id: "2", label: "Google", value: "google", createdBy: "user-1" },
+ ];
+
+ const user = userEvent.setup({ delay: null });
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ describe("Search Input", () => {
+ it("should render search input with placeholder", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(
+ screen.getByPlaceholderText("Search companies..."),
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should update search input value when typing", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(
+ screen.getByPlaceholderText("Search companies..."),
+ ).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+
+ await act(async () => {
+ await user.type(searchInput, "Amazon");
+ });
+
+ expect(searchInput).toHaveValue("Amazon");
+ });
+
+ it("should debounce search input for 300ms", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+
+ await act(async () => {
+ await user.type(searchInput, "A");
+ });
+
+ // Should not have called getCompanyList yet (debounce not elapsed)
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledTimes(2);
+ });
+ });
+
+ it("should call getCompanyList with search term after debounce", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+
+ await act(async () => {
+ await user.type(searchInput, "Amazon");
+ });
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledWith(1, 25, "applied", "Amazon");
+ });
+ });
+
+ it("should not trigger search on initial mount with empty search", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+ });
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+ expect(getCompanyList).toHaveBeenCalledWith(1, 25, "applied", undefined);
+ });
+
+ it("should trigger search when clearing search term after searching", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 2,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+
+ await act(async () => {
+ await user.type(searchInput, "Amazon");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledWith(1, 25, "applied", "Amazon");
+ });
+
+ await act(async () => {
+ await user.clear(searchInput);
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenLastCalledWith(
+ 1,
+ 25,
+ "applied",
+ undefined,
+ );
+ });
+ });
+
+ it("should display filtered companies after search", async () => {
+ (getCompanyList as any)
+ .mockResolvedValueOnce({ data: mockCompanies, total: 2 })
+ .mockResolvedValueOnce({
+ data: [mockCompanies[0]],
+ total: 1,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Amazon")).toBeInTheDocument();
+ expect(screen.getByText("Google")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+ await act(async () => {
+ await user.type(searchInput, "Amazon");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Amazon")).toBeInTheDocument();
+ expect(screen.queryByText("Google")).not.toBeInTheDocument();
+ });
+ });
+
+ it("should preserve search term when loading more companies", async () => {
+ (getCompanyList as any).mockResolvedValue({
+ data: mockCompanies,
+ total: 5,
+ });
+
+ render(<CompaniesContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Amazon")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search companies...");
+ await act(async () => {
+ await user.type(searchInput, "Amazon");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledWith(1, 25, "applied", "Amazon");
+ });
+
+ const loadMoreButton = await screen.findByRole("button", {
+ name: /load more/i,
+ });
+ await act(async () => {
+ await user.click(loadMoreButton);
+ });
+
+ await waitFor(() => {
+ expect(getCompanyList).toHaveBeenCalledWith(2, 25, "applied", "Amazon");
+ });
+ });
+ });
+});
diff --git a/__tests__/JobTitlesContainer.spec.tsx b/__tests__/JobTitlesContainer.spec.tsx
new file mode 100644
index 0000000..97ad164
--- /dev/null
+++ b/__tests__/JobTitlesContainer.spec.tsx
@@ -0,0 +1,198 @@
+import JobTitlesContainer from "@/components/admin/JobTitlesContainer";
+import { screen, render, waitFor, act } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { getJobTitleList, deleteJobTitleById } from "@/actions/jobtitle.actions";
+
+vi.mock("@/actions/jobtitle.actions", () => ({
+ getJobTitleList: vi.fn(),
+ deleteJobTitleById: vi.fn(),
+}));
+
+describe("JobTitlesContainer Search Functionality", () => {
+ const mockTitles = [
+ { id: "1", label: "Software Engineer", value: "software engineer", createdBy: "user-1" },
+ { id: "2", label: "Product Manager", value: "product manager", createdBy: "user-1" },
+ ];
+
+ const user = userEvent.setup({ delay: null });
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ describe("Search Input", () => {
+ it("should render search input with placeholder", async () => {
+ (getJobTitleList as any).mockResolvedValue({
+ data: mockTitles,
+ total: 2,
+ });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(
+ screen.getByPlaceholderText("Search job titles..."),
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should debounce search input for 300ms", async () => {
+ (getJobTitleList as any).mockResolvedValue({
+ data: mockTitles,
+ total: 2,
+ });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search job titles...");
+
+ await act(async () => {
+ await user.type(searchInput, "P");
+ });
+
+ expect(getJobTitleList).toHaveBeenCalledTimes(1);
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledTimes(2);
+ });
+ });
+
+ it("should call getJobTitleList with search term after debounce", async () => {
+ (getJobTitleList as any).mockResolvedValue({
+ data: mockTitles,
+ total: 2,
+ });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search job titles...");
+
+ await act(async () => {
+ await user.type(searchInput, "Product");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ "applied",
+ "Product",
+ );
+ });
+ });
+
+ it("should not trigger search on initial mount with empty search", async () => {
+ (getJobTitleList as any).mockResolvedValue({
+ data: mockTitles,
+ total: 2,
+ });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledTimes(1);
+ });
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ expect(getJobTitleList).toHaveBeenCalledTimes(1);
+ expect(getJobTitleList).toHaveBeenCalledWith(1, 25, "applied", undefined);
+ });
+
+ it("should display filtered job titles after search", async () => {
+ (getJobTitleList as any)
+ .mockResolvedValueOnce({ data: mockTitles, total: 2 })
+ .mockResolvedValueOnce({ data: [mockTitles[1]], total: 1 });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Software Engineer")).toBeInTheDocument();
+ expect(screen.getByText("Product Manager")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search job titles...");
+ await act(async () => {
+ await user.type(searchInput, "Product");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Product Manager")).toBeInTheDocument();
+ expect(
+ screen.queryByText("Software Engineer"),
+ ).not.toBeInTheDocument();
+ });
+ });
+
+ it("should preserve search term when loading more job titles", async () => {
+ (getJobTitleList as any).mockResolvedValue({
+ data: mockTitles,
+ total: 5,
+ });
+
+ render(<JobTitlesContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("Software Engineer")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search job titles...");
+ await act(async () => {
+ await user.type(searchInput, "Engineer");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledWith(
+ 1,
+ 25,
+ "applied",
+ "Engineer",
+ );
+ });
+
+ const loadMoreButton = await screen.findByRole("button", {
+ name: /load more/i,
+ });
+ await act(async () => {
+ await user.click(loadMoreButton);
+ });
+
+ await waitFor(() => {
+ expect(getJobTitleList).toHaveBeenCalledWith(
+ 2,
+ 25,
+ "applied",
+ "Engineer",
+ );
+ });
+ });
+ });
+});
diff --git a/__tests__/TagsContainer.spec.tsx b/__tests__/TagsContainer.spec.tsx
new file mode 100644
index 0000000..26bc7a5
--- /dev/null
+++ b/__tests__/TagsContainer.spec.tsx
@@ -0,0 +1,179 @@
+import TagsContainer from "@/components/admin/TagsContainer";
+import { screen, render, waitFor, act } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
+import { getTagList, deleteTagById } from "@/actions/tag.actions";
+
+vi.mock("@/actions/tag.actions", () => ({
+ getTagList: vi.fn(),
+ deleteTagById: vi.fn(),
+ createTag: vi.fn(),
+}));
+
+describe("TagsContainer Search Functionality", () => {
+ const mockTags = [
+ {
+ id: "1",
+ label: "React",
+ value: "react",
+ createdBy: "user-1",
+ _count: { jobs: 1, questions: 0, skills: 0 },
+ },
+ {
+ id: "2",
+ label: "Python",
+ value: "python",
+ createdBy: "user-1",
+ _count: { jobs: 0, questions: 1, skills: 0 },
+ },
+ ];
+
+ const user = userEvent.setup({ delay: null });
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+ vi.useFakeTimers({ shouldAdvanceTime: true });
+ });
+
+ afterEach(() => {
+ vi.useRealTimers();
+ });
+
+ describe("Search Input", () => {
+ it("should render search input with placeholder", async () => {
+ (getTagList as any).mockResolvedValue({ data: mockTags, total: 2 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(
+ screen.getByPlaceholderText("Search skills..."),
+ ).toBeInTheDocument();
+ });
+ });
+
+ it("should debounce search input for 300ms", async () => {
+ (getTagList as any).mockResolvedValue({ data: mockTags, total: 2 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search skills...");
+
+ await act(async () => {
+ await user.type(searchInput, "P");
+ });
+
+ expect(getTagList).toHaveBeenCalledTimes(1);
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledTimes(2);
+ });
+ });
+
+ it("should call getTagList with search term after debounce", async () => {
+ (getTagList as any).mockResolvedValue({ data: mockTags, total: 2 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledTimes(1);
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search skills...");
+
+ await act(async () => {
+ await user.type(searchInput, "Python");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledWith(1, 25, "Python");
+ });
+ });
+
+ it("should not trigger search on initial mount with empty search", async () => {
+ (getTagList as any).mockResolvedValue({ data: mockTags, total: 2 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledTimes(1);
+ });
+
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ expect(getTagList).toHaveBeenCalledTimes(1);
+ expect(getTagList).toHaveBeenCalledWith(1, 25, undefined);
+ });
+
+ it("should display filtered skills after search", async () => {
+ (getTagList as any)
+ .mockResolvedValueOnce({ data: mockTags, total: 2 })
+ .mockResolvedValueOnce({ data: [mockTags[1]], total: 1 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("React")).toBeInTheDocument();
+ expect(screen.getByText("Python")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search skills...");
+ await act(async () => {
+ await user.type(searchInput, "Python");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(screen.getByText("Python")).toBeInTheDocument();
+ expect(screen.queryByText("React")).not.toBeInTheDocument();
+ });
+ });
+
+ it("should preserve search term when loading more skills", async () => {
+ (getTagList as any).mockResolvedValue({ data: mockTags, total: 5 });
+
+ render(<TagsContainer />);
+
+ await waitFor(() => {
+ expect(screen.getByText("React")).toBeInTheDocument();
+ });
+
+ const searchInput = screen.getByPlaceholderText("Search skills...");
+ await act(async () => {
+ await user.type(searchInput, "React");
+ });
+ await act(async () => {
+ vi.advanceTimersByTime(300);
+ });
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledWith(1, 25, "React");
+ });
+
+ const loadMoreButton = await screen.findByRole("button", {
+ name: /load more/i,
+ });
+ await act(async () => {
+ await user.click(loadMoreButton);
+ });
+
+ await waitFor(() => {
+ expect(getTagList).toHaveBeenCalledWith(2, 25, "React");
+ });
+ });
+ });
+});
diff --git a/__tests__/company.actions.spec.ts b/__tests__/company.actions.spec.ts
index 9cd65bf..7b64df3 100644
--- a/__tests__/company.actions.spec.ts
+++ b/__tests__/company.actions.spec.ts
@@ -155,6 +155,99 @@ describe("Company Actions", () => {
expect(prisma.company.findMany).not.toHaveBeenCalled();
expect(prisma.company.count).not.toHaveBeenCalled();
});
+
+ it("should filter companies by label when search is provided", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ const mockData = [
+ {
+ id: "company-id",
+ label: "Amazon",
+ value: "amazon",
+ logoUrl: "logo.png",
+ },
+ ];
+ const mockTotal = 1;
+
+ (prisma.company.findMany as any).mockResolvedValue(mockData);
+ (prisma.company.count as any).mockResolvedValue(mockTotal);
+
+ const result = await getCompanyList(1, 10, undefined, "Ama");
+
+ expect(result).toEqual({ data: mockData, total: mockTotal });
+ expect(prisma.company.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Ama" } },
+ skip: 0,
+ take: 10,
+ orderBy: { jobsApplied: { _count: "desc" } },
+ });
+ expect(prisma.company.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Ama" } },
+ });
+ });
+
+ it("should combine search filter with countBy select/counts", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ const mockData = [
+ {
+ id: "company-id",
+ label: "Amazon",
+ value: "amazon",
+ logoUrl: "logo.png",
+ },
+ ];
+ const mockTotal = 1;
+
+ (prisma.company.findMany as any).mockResolvedValue(mockData);
+ (prisma.company.count as any).mockResolvedValue(mockTotal);
+ (prisma.job.groupBy as any).mockResolvedValue([]);
+
+ const result = await getCompanyList(1, 10, "applied", "Ama");
+
+ const expectedData = mockData.map((c) => ({
+ ...c,
+ _count: { jobsRejected: 0, jobsTotal: 0 },
+ }));
+ expect(result).toEqual({ data: expectedData, total: mockTotal });
+ expect(prisma.company.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Ama" } },
+ skip: 0,
+ take: 10,
+ select: {
+ id: true,
+ label: true,
+ value: true,
+ logoUrl: true,
+ _count: {
+ select: {
+ jobsApplied: {
+ where: {
+ applied: true,
+ },
+ },
+ },
+ },
+ },
+ orderBy: { jobsApplied: { _count: "desc" } },
+ });
+ expect(prisma.company.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Ama" } },
+ });
+ });
+
+ it("should not apply a label filter when search is empty", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.company.findMany as any).mockResolvedValue([]);
+ (prisma.company.count as any).mockResolvedValue(0);
+
+ await getCompanyList(1, 10, undefined, "");
+
+ expect(prisma.company.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ orderBy: { jobsApplied: { _count: "desc" } },
+ });
+ });
});
describe("getAllCompanies", () => {
diff --git a/__tests__/jobtitle.actions.spec.ts b/__tests__/jobtitle.actions.spec.ts
index 8a8896f..509a3c0 100644
--- a/__tests__/jobtitle.actions.spec.ts
+++ b/__tests__/jobtitle.actions.spec.ts
@@ -172,6 +172,43 @@ describe("Job Title Actions", () => {
expect(result).toEqual({ success: false, message: "Database error" });
});
+
+ it("should filter job titles by label when search is provided", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ const mockData = [
+ { id: "title-1", label: "Developer", value: "developer" },
+ ];
+ (prisma.jobTitle.findMany as any).mockResolvedValue(mockData);
+ (prisma.jobTitle.count as any).mockResolvedValue(1);
+
+ const result = await getJobTitleList(1, 10, undefined, "Dev");
+
+ expect(result).toEqual({ data: mockData, total: 1 });
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Dev" } },
+ skip: 0,
+ take: 10,
+ orderBy: { jobs: { _count: "desc" } },
+ });
+ expect(prisma.jobTitle.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Dev" } },
+ });
+ });
+
+ it("should not apply a label filter when search is empty", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.jobTitle.findMany as any).mockResolvedValue([]);
+ (prisma.jobTitle.count as any).mockResolvedValue(0);
+
+ await getJobTitleList(1, 10, undefined, "");
+
+ expect(prisma.jobTitle.findMany).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id },
+ skip: 0,
+ take: 10,
+ orderBy: { jobs: { _count: "desc" } },
+ });
+ });
});
describe("createJobTitle", () => {
diff --git a/__tests__/tag.actions.spec.ts b/__tests__/tag.actions.spec.ts
index c361ac5..2961888 100644
--- a/__tests__/tag.actions.spec.ts
+++ b/__tests__/tag.actions.spec.ts
@@ -141,6 +141,39 @@ describe("Tag Actions", () => {
expect(result).toEqual({ success: false, message: "DB error" });
});
+
+ it("should filter tags by label when search is provided", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ const mockData = [{ ...mockTag, _count: { jobs: 3, questions: 2 } }];
+ (prisma.tag.findMany as any).mockResolvedValue(mockData);
+ (prisma.tag.count as any).mockResolvedValue(1);
+
+ const result = await getTagList(1, 10, "Rea");
+
+ expect(result).toEqual({ data: mockData, total: 1 });
+ expect(prisma.tag.findMany).toHaveBeenCalledWith(
+ expect.objectContaining({
+ where: { createdBy: mockUser.id, label: { contains: "Rea" } },
+ }),
+ );
+ expect(prisma.tag.count).toHaveBeenCalledWith({
+ where: { createdBy: mockUser.id, label: { contains: "Rea" } },
+ });
+ });
+
+ it("should not apply a label filter when search is empty", async () => {
+ (getCurrentUser as any).mockResolvedValue(mockUser);
+ (prisma.tag.findMany as any).mockResolvedValue([]);
+ (prisma.tag.count as any).mockResolvedValue(0);
+
+ await getTagList(1, 10, "");
+
+ expect(prisma.tag.findMany).toHaveBeenCalledWith(
+ expect.objectContaining({
+ where: { createdBy: mockUser.id },
+ }),
+ );
+ });
});
// createTag
diff --git a/e2e/admin-companies.spec.ts b/e2e/admin-companies.spec.ts
new file mode 100644
index 0000000..8dd9181
--- /dev/null
+++ b/e2e/admin-companies.spec.ts
@@ -0,0 +1,107 @@
+import { randomUUID } from "crypto";
+import { type Page } from "@playwright/test";
+import {
+ test,
+ expect,
+ uniqueName,
+ type CleanupRegistry,
+} from "./fixtures";
+
+async function navigateToCompanies(page: Page) {
+ await page.goto("/dashboard/admin");
+ await page.waitForLoadState("networkidle");
+ await page.getByTestId("add-company-btn").waitFor({ state: "visible" });
+}
+
+// Opens the New Company dialog and saves a company with the given name.
+// Registers it for teardown as soon as it's persisted. Verifies via the
+// search box rather than the unfiltered (page-1, applied-count-ordered)
+// list: the admin account has 70+ pre-existing companies, so a brand new
+// row (0 applied jobs, tied with many others) isn't guaranteed to land on
+// page 1 of the default listing.
+async function createCompany(
+ page: Page,
+ companyName: string,
+ cleanup: CleanupRegistry,
+) {
+ await page.getByTestId("add-company-btn").click();
+ await expect(page.getByText("Add Company")).toBeVisible();
+
+ await page.getByLabel("Company Name").fill(companyName);
+ await page.getByRole("button", { name: /save/i }).click();
+ cleanup.company(companyName);
+
+ // Wait for the dialog to fully close before touching the search box —
+ // filling it while the dialog is still closing is a no-op (the input
+ // isn't interactable yet), leaving the search term empty.
+ await expect(page.getByText("Add Company")).not.toBeVisible();
+
+ const searchInput = page.getByPlaceholder("Search companies...");
+ await searchInput.fill(companyName);
+ await expect(
+ page.getByRole("cell", { name: companyName, exact: true }),
+ ).toBeVisible();
+ await searchInput.fill("");
+}
+
+test.describe("Admin Companies search", () => {
+ test("filters the companies list by name from the backend", async ({
+ page,
+ cleanup,
+ }) => {
+ // Shared suffix lets one search term match both companies below,
+ // without depending on the unfiltered (pagination-sensitive) list.
+ const suffix = randomUUID().slice(0, 8);
+ const companyA = `Umbrella Corp ${suffix}`;
+ const companyB = `Wayne Enterprises ${suffix}`;
+
+ await navigateToCompanies(page);
+ await createCompany(page, companyA, cleanup);
+ await createCompany(page, companyB, cleanup);
+
+ const searchInput = page.getByPlaceholder("Search companies...");
+ await searchInput.fill(companyA);
+
+ await expect(
+ page.getByRole("cell", { name: companyA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: companyB, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(companyB);
+
+ await expect(
+ page.getByRole("cell", { name: companyB, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: companyA, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(suffix);
+
+ await expect(
+ page.getByRole("cell", { name: companyA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: companyB, exact: true }),
+ ).toBeVisible();
+ });
+
+ test("shows no rows for a search term that matches nothing", async ({
+ page,
+ cleanup,
+ }) => {
+ const companyName = uniqueName("Stark Industries");
+
+ await navigateToCompanies(page);
+ await createCompany(page, companyName, cleanup);
+
+ const searchInput = page.getByPlaceholder("Search companies...");
+ await searchInput.fill(uniqueName("no-such-company"));
+
+ await expect(
+ page.getByRole("cell", { name: companyName, exact: true }),
+ ).not.toBeVisible();
+ });
+});
diff --git a/e2e/admin-job-titles.spec.ts b/e2e/admin-job-titles.spec.ts
new file mode 100644
index 0000000..33cb156
--- /dev/null
+++ b/e2e/admin-job-titles.spec.ts
@@ -0,0 +1,53 @@
+import { randomUUID } from "crypto";
+import { test, expect, createNewJob } from "./fixtures";
+
+test.describe("Admin Job Titles search", () => {
+ test("filters the job titles list by name from the backend", async ({
+ page,
+ cleanup,
+ }) => {
+ // Shared suffix lets one search term match both titles below, without
+ // depending on the unfiltered (pagination-sensitive) list — the admin
+ // account has 200+ pre-existing job titles, so a brand new row (0
+ // applied jobs, tied with many others) isn't guaranteed to land on page
+ // 1 of the default listing.
+ const suffix = randomUUID().slice(0, 8);
+ const titleA = `Data Scientist ${suffix}`;
+ const titleB = `DevOps Engineer ${suffix}`;
+
+ await createNewJob(page, titleA, cleanup);
+ await createNewJob(page, titleB, cleanup);
+
+ await page.goto("/dashboard/admin?tab=job-titles");
+ await page.waitForLoadState("networkidle");
+
+ const searchInput = page.getByPlaceholder("Search job titles...");
+ await expect(searchInput).toBeVisible();
+ await searchInput.fill(titleA);
+
+ await expect(
+ page.getByRole("cell", { name: titleA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: titleB, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(titleB);
+
+ await expect(
+ page.getByRole("cell", { name: titleB, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: titleA, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(suffix);
+
+ await expect(
+ page.getByRole("cell", { name: titleA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: titleB, exact: true }),
+ ).toBeVisible();
+ });
+});
diff --git a/e2e/admin-skills.spec.ts b/e2e/admin-skills.spec.ts
new file mode 100644
index 0000000..bb1de77
--- /dev/null
+++ b/e2e/admin-skills.spec.ts
@@ -0,0 +1,86 @@
+import { randomUUID } from "crypto";
+import { type Page } from "@playwright/test";
+import { test, expect, uniqueName, type CleanupRegistry } from "./fixtures";
+
+async function navigateToSkills(page: Page) {
+ await page.goto("/dashboard/admin?tab=skills");
+ await page.waitForLoadState("networkidle");
+ await page.getByRole("button", { name: /new skill/i }).waitFor({
+ state: "visible",
+ });
+}
+
+// Opens the New Skill dialog and saves a skill tag with the given name.
+// Registers it for teardown as soon as it's persisted. Verifies via the
+// search box rather than the unfiltered (page-1, count-ordered) list: the
+// admin account has 100+ pre-existing skill tags, so a brand new row isn't
+// guaranteed to land on page 1 of the default listing.
+async function createSkill(
+ page: Page,
+ skillName: string,
+ cleanup: CleanupRegistry,
+) {
+ await page.getByRole("button", { name: /new skill/i }).click();
+ await expect(page.getByText("Add New Skill")).toBeVisible();
+
+ await page.getByLabel("Skill Name").fill(skillName);
+ await page.getByRole("button", { name: /save/i }).click();
+ cleanup.tag(skillName);
+
+ // Wait for the dialog to fully close before touching the search box —
+ // filling it while the dialog is still closing is a no-op (the input
+ // isn't interactable yet), leaving the search term empty.
+ await expect(page.getByText("Add New Skill")).not.toBeVisible();
+
+ const searchInput = page.getByPlaceholder("Search skills...");
+ await searchInput.fill(skillName);
+ await expect(
+ page.getByRole("cell", { name: skillName, exact: true }),
+ ).toBeVisible();
+ await searchInput.fill("");
+}
+
+test.describe("Admin Skills search", () => {
+ test("filters the skills list by name from the backend", async ({
+ page,
+ cleanup,
+ }) => {
+ // Shared suffix lets one search term match both skills below, without
+ // depending on the unfiltered (pagination-sensitive) list.
+ const suffix = randomUUID().slice(0, 8);
+ const skillA = `Kubernetes ${suffix}`;
+ const skillB = `GraphQL ${suffix}`;
+
+ await navigateToSkills(page);
+ await createSkill(page, skillA, cleanup);
+ await createSkill(page, skillB, cleanup);
+
+ const searchInput = page.getByPlaceholder("Search skills...");
+ await searchInput.fill(skillA);
+
+ await expect(
+ page.getByRole("cell", { name: skillA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: skillB, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(skillB);
+
+ await expect(
+ page.getByRole("cell", { name: skillB, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: skillA, exact: true }),
+ ).not.toBeVisible();
+
+ await searchInput.fill(suffix);
+
+ await expect(
+ page.getByRole("cell", { name: skillA, exact: true }),
+ ).toBeVisible();
+ await expect(
+ page.getByRole("cell", { name: skillB, exact: true }),
+ ).toBeVisible();
+ });
+});
diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.ts
index fd4bc03..37233d2 100644
--- a/src/actions/company.actions.ts
+++ b/src/actions/company.actions.ts
@@ -12,6 +12,7 @@ export const getCompanyList = async (
page: number = 1,
limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,
countBy?: string,
+ search?: string,
): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
@@ -21,11 +22,17 @@ export const getCompanyList = async (
}
const skip = (page - 1) * limit;
+ const whereClause: any = {
+ createdBy: user.id,
+ };
+
+ if (search) {
+ whereClause.label = { contains: search };
+ }
+
const [data, total, rejectedCounts, totalCounts] = await Promise.all([
prisma.company.findMany({
- where: {
- createdBy: user.id,
- },
+ where: whereClause,
skip,
take: limit,
...(countBy
@@ -54,9 +61,7 @@ export const getCompanyList = async (
},
}),
prisma.company.count({
- where: {
- createdBy: user.id,
- },
+ where: whereClause,
}),
countBy
? prisma.job.groupBy({
diff --git a/src/actions/jobtitle.actions.ts b/src/actions/jobtitle.actions.ts
index 53386d4..947edd8 100644
--- a/src/actions/jobtitle.actions.ts
+++ b/src/actions/jobtitle.actions.ts
@@ -26,7 +26,8 @@ export const getAllJobTitles = async (): Promise<any | undefined> => {
export const getJobTitleList = async (
page: number = 1,
limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,
- countBy?: string
+ countBy?: string,
+ search?: string,
): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
@@ -36,11 +37,17 @@ export const getJobTitleList = async (
}
const skip = (page - 1) * limit;
+ const whereClause: any = {
+ createdBy: user.id,
+ };
+
+ if (search) {
+ whereClause.label = { contains: search };
+ }
+
const [data, total, totalCounts] = await Promise.all([
prisma.jobTitle.findMany({
- where: {
- createdBy: user.id,
- },
+ where: whereClause,
skip,
take: limit,
...(countBy
@@ -68,9 +75,7 @@ export const getJobTitleList = async (
},
}),
prisma.jobTitle.count({
- where: {
- createdBy: user.id,
- },
+ where: whereClause,
}),
countBy
? prisma.job.groupBy({
diff --git a/src/actions/tag.actions.ts b/src/actions/tag.actions.ts
index 3c0dcff..6f01ce5 100644
--- a/src/actions/tag.actions.ts
+++ b/src/actions/tag.actions.ts
@@ -25,6 +25,7 @@ export const getAllTags = async (): Promise<any | undefined> => {
export const getTagList = async (
page: number = 1,
limit: number = APP_CONSTANTS.RECORDS_PER_PAGE,
+ search?: string,
): Promise<any | undefined> => {
try {
const user = await getCurrentUser();
@@ -33,9 +34,14 @@ export const getTagList = async (
}
const skip = (page - 1) * limit;
+ const whereClause: any = { createdBy: user.id };
+ if (search) {
+ whereClause.label = { contains: search };
+ }
+
const [data, total] = await Promise.all([
prisma.tag.findMany({
- where: { createdBy: user.id },
+ where: whereClause,
skip,
take: limit,
select: {
@@ -46,7 +52,7 @@ export const getTagList = async (
},
orderBy: { jobs: { _count: "desc" } },
}),
- prisma.tag.count({ where: { createdBy: user.id } }),
+ prisma.tag.count({ where: whereClause }),
]);
return { data, total };
diff --git a/src/components/admin/CompaniesContainer.tsx b/src/components/admin/CompaniesContainer.tsx
index 8d998b5..b97331d 100644
--- a/src/components/admin/CompaniesContainer.tsx
+++ b/src/components/admin/CompaniesContainer.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import AddCompany from "./AddCompany";
import CompaniesTable from "./CompaniesTable";
import { Card, CardContent, CardTitle } from "../ui/card";
@@ -10,6 +10,7 @@ import { APP_CONSTANTS } from "@/lib/constants";
import Loading from "../Loading";
import { Button } from "../ui/button";
import { RecordsCount } from "../RecordsCount";
+import { SearchInput } from "../SearchInput";
function CompaniesContainer() {
const [companies, setCompanies] = useState<Company[]>([]);
@@ -18,13 +19,16 @@ function CompaniesContainer() {
const [dialogOpen, setDialogOpen] = useState(false);
const [editCompany, setEditCompany] = useState(null);
const [loading, setLoading] = useState<boolean>(false);
+ const [searchTerm, setSearchTerm] = useState("");
+ const hasSearched = useRef(false);
const loadCompanies = useCallback(
- async (page: number) => {
+ async (page: number, search?: string) => {
setLoading(true);
const { data, total } = await getCompanyList(
page,
APP_CONSTANTS.RECORDS_PER_PAGE,
- "applied"
+ "applied",
+ search
);
if (data) {
setCompanies((prev) => (page === 1 ? data : [...prev, ...data]));
@@ -37,8 +41,8 @@ function CompaniesContainer() {
);
const reloadCompanies = useCallback(async () => {
- await loadCompanies(1);
- }, [loadCompanies]);
+ await loadCompanies(1, searchTerm || undefined);
+ }, [loadCompanies, searchTerm]);
const resetEditCompany = () => {
setEditCompany(null);
@@ -48,6 +52,19 @@ function CompaniesContainer() {
(async () => await loadCompanies(1))();
}, [loadCompanies]);
+ useEffect(() => {
+ if (searchTerm !== "") {
+ hasSearched.current = true;
+ }
+ if (searchTerm === "" && !hasSearched.current) return;
+
+ const timer = setTimeout(() => {
+ loadCompanies(1, searchTerm || undefined);
+ }, 300);
+ return () => clearTimeout(timer);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [searchTerm]);
+
const onEditCompany = async (companyId: string) => {
const company = await getCompanyById(companyId);
setEditCompany(company);
@@ -66,6 +83,11 @@ function CompaniesContainer() {
)}
</div>
<div className="flex flex-wrap items-center gap-2 sm:ml-auto">
+ <SearchInput
+ value={searchTerm}
+ onChange={setSearchTerm}
+ placeholder="Search companies..."
+ />
<AddCompany
editCompany={editCompany}
reloadCompanies={reloadCompanies}
@@ -91,7 +113,7 @@ function CompaniesContainer() {
<Button
size="sm"
variant="outline"
- onClick={() => loadCompanies(page + 1)}
+ onClick={() => loadCompanies(page + 1, searchTerm || undefined)}
disabled={loading}
className="btn btn-primary"
>
diff --git a/src/components/admin/JobTitlesContainer.tsx b/src/components/admin/JobTitlesContainer.tsx
index 4d42f54..863d833 100644
--- a/src/components/admin/JobTitlesContainer.tsx
+++ b/src/components/admin/JobTitlesContainer.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import { Card, CardContent, CardTitle } from "../ui/card";
import { ResponsiveCardHeader } from "../ResponsiveCardHeader";
import { APP_CONSTANTS } from "@/lib/constants";
@@ -9,19 +9,23 @@ import { getJobTitleList } from "@/actions/jobtitle.actions";
import Loading from "../Loading";
import { Button } from "../ui/button";
import { RecordsCount } from "../RecordsCount";
+import { SearchInput } from "../SearchInput";
function JobTitlesContainer() {
const [titles, setTitles] = useState<JobTitle[]>([]);
const [totalJobTitles, setTotalJobTitles] = useState<number>(0);
const [page, setPage] = useState<number>(1);
const [loading, setLoading] = useState<boolean>(false);
+ const [searchTerm, setSearchTerm] = useState("");
+ const hasSearched = useRef(false);
const loadJobTitles = useCallback(
- async (page: number) => {
+ async (page: number, search?: string) => {
setLoading(true);
const { data, total } = await getJobTitleList(
page,
APP_CONSTANTS.RECORDS_PER_PAGE,
- "applied"
+ "applied",
+ search
);
if (data) {
setTitles((prev) => (page === 1 ? data : [...prev, ...data]));
@@ -34,13 +38,26 @@ function JobTitlesContainer() {
);
const reloadJobTitles = useCallback(async () => {
- await loadJobTitles(1);
- }, [loadJobTitles]);
+ await loadJobTitles(1, searchTerm || undefined);
+ }, [loadJobTitles, searchTerm]);
useEffect(() => {
(async () => await loadJobTitles(1))();
}, [loadJobTitles]);
+ useEffect(() => {
+ if (searchTerm !== "") {
+ hasSearched.current = true;
+ }
+ if (searchTerm === "" && !hasSearched.current) return;
+
+ const timer = setTimeout(() => {
+ loadJobTitles(1, searchTerm || undefined);
+ }, 300);
+ return () => clearTimeout(timer);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [searchTerm]);
+
return (
<>
<div className="col-span-3">
@@ -53,6 +70,11 @@ function JobTitlesContainer() {
)}
</div>
<div className="flex flex-wrap items-center gap-2 sm:ml-auto">
+ <SearchInput
+ value={searchTerm}
+ onChange={setSearchTerm}
+ placeholder="Search job titles..."
+ />
{/* <AddCompany reloadCompanies={reloadJobTitles} /> */}
</div>
</ResponsiveCardHeader>
@@ -71,7 +93,7 @@ function JobTitlesContainer() {
<Button
size="sm"
variant="outline"
- onClick={() => loadJobTitles(page + 1)}
+ onClick={() => loadJobTitles(page + 1, searchTerm || undefined)}
disabled={loading}
className="btn btn-primary"
>
diff --git a/src/components/admin/TagsContainer.tsx b/src/components/admin/TagsContainer.tsx
index f9ac932..7276f43 100644
--- a/src/components/admin/TagsContainer.tsx
+++ b/src/components/admin/TagsContainer.tsx
@@ -1,5 +1,5 @@
"use client";
-import { useCallback, useEffect, useState } from "react";
+import { useCallback, useEffect, useRef, useState } from "react";
import { Card, CardContent, CardTitle } from "../ui/card";
import { ResponsiveCardHeader } from "../ResponsiveCardHeader";
import { Tag } from "@/models/job.model";
@@ -10,17 +10,24 @@ import { Button } from "../ui/button";
import { RecordsCount } from "../RecordsCount";
import TagsTable from "./TagsTable";
import AddTag from "./AddTag";
+import { SearchInput } from "../SearchInput";
function TagsContainer() {
const [tags, setTags] = useState<Tag[]>([]);
const [totalTags, setTotalTags] = useState<number>(0);
const [page, setPage] = useState<number>(1);
const [loading, setLoading] = useState<boolean>(false);
+ const [searchTerm, setSearchTerm] = useState("");
+ const hasSearched = useRef(false);
const loadTags = useCallback(
- async (page: number) => {
+ async (page: number, search?: string) => {
setLoading(true);
try {
- const { data, total } = await getTagList(page, APP_CONSTANTS.RECORDS_PER_PAGE);
+ const { data, total } = await getTagList(
+ page,
+ APP_CONSTANTS.RECORDS_PER_PAGE,
+ search,
+ );
if (data) {
setTags((prev) => (page === 1 ? data : [...prev, ...data]));
setTotalTags(total);
@@ -34,13 +41,26 @@ function TagsContainer() {
);
const reloadTags = useCallback(async () => {
- await loadTags(1);
- }, [loadTags]);
+ await loadTags(1, searchTerm || undefined);
+ }, [loadTags, searchTerm]);
useEffect(() => {
(async () => await loadTags(1))();
}, [loadTags]);
+ useEffect(() => {
+ if (searchTerm !== "") {
+ hasSearched.current = true;
+ }
+ if (searchTerm === "" && !hasSearched.current) return;
+
+ const timer = setTimeout(() => {
+ loadTags(1, searchTerm || undefined);
+ }, 300);
+ return () => clearTimeout(timer);
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [searchTerm]);
+
return (
<>
<div className="col-span-3">
@@ -53,6 +73,11 @@ function TagsContainer() {
)}
</div>
<div className="flex flex-wrap items-center gap-2 sm:ml-auto">
+ <SearchInput
+ value={searchTerm}
+ onChange={setSearchTerm}
+ placeholder="Search skills..."
+ />
<AddTag reloadTags={reloadTags} />
</div>
</ResponsiveCardHeader>
@@ -68,7 +93,7 @@ function TagsContainer() {
<Button
size="sm"
variant="outline"
- onClick={() => loadTags(page + 1)}
+ onClick={() => loadTags(page + 1, searchTerm || undefined)}
disabled={loading}
className="btn btn-primary"
>