|
| 1 | +import { describe, expect, test } from "vitest"; |
| 2 | +import type { DashboardProject } from "@webstudio-is/dashboard"; |
| 3 | +import { searchProjects } from "./search-results"; |
| 4 | + |
| 5 | +const createProject = ( |
| 6 | + overrides: Partial<DashboardProject> |
| 7 | +): DashboardProject => |
| 8 | + ({ |
| 9 | + id: "project-1", |
| 10 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 11 | + title: "Default Site", |
| 12 | + domain: "default", |
| 13 | + userId: "user-1", |
| 14 | + isDeleted: false, |
| 15 | + isPublished: false, |
| 16 | + latestBuild: null, |
| 17 | + previewImageAsset: null, |
| 18 | + previewImageAssetId: null, |
| 19 | + latestBuildVirtual: null, |
| 20 | + marketplaceApprovalStatus: "UNLISTED", |
| 21 | + tags: [], |
| 22 | + domainsVirtual: [], |
| 23 | + workspaceId: null, |
| 24 | + ...overrides, |
| 25 | + }) as DashboardProject; |
| 26 | + |
| 27 | +describe("searchProjects", () => { |
| 28 | + test.each([ |
| 29 | + ["id", "83e97c09dcce", { id: "d845c167-ea07-4875-b08d-83e97c09dcce" }], |
| 30 | + ["title", "Marketing", { title: "Marketing Site" }], |
| 31 | + ["domain", "docs", { domain: "docs" }], |
| 32 | + [ |
| 33 | + "custom domain", |
| 34 | + "client.example.com", |
| 35 | + { |
| 36 | + domainsVirtual: [ |
| 37 | + { domain: "client.example.com", status: "ACTIVE", verified: true }, |
| 38 | + ], |
| 39 | + }, |
| 40 | + ], |
| 41 | + [ |
| 42 | + "latest build id", |
| 43 | + "aca9e9574587", |
| 44 | + { |
| 45 | + latestBuildVirtual: { |
| 46 | + buildId: "f565d527-32e7-4731-bc71-aca9e9574587", |
| 47 | + projectId: "project-1", |
| 48 | + domainsVirtualId: "", |
| 49 | + domain: "fixture", |
| 50 | + createdAt: "2024-01-01T00:00:00.000Z", |
| 51 | + updatedAt: "2024-01-01T00:00:00.000Z", |
| 52 | + publishStatus: "PUBLISHED", |
| 53 | + }, |
| 54 | + }, |
| 55 | + ], |
| 56 | + ] satisfies Array<[string, string, Partial<DashboardProject>]>)( |
| 57 | + "matches projects by %s", |
| 58 | + (_field, search, overrides) => { |
| 59 | + const projects = [ |
| 60 | + createProject(overrides), |
| 61 | + createProject({ id: "project-other", title: "Other Project" }), |
| 62 | + ]; |
| 63 | + |
| 64 | + expect(searchProjects(projects, search)).toEqual([projects[0]]); |
| 65 | + } |
| 66 | + ); |
| 67 | + |
| 68 | + test("does not return projects without matching fields", () => { |
| 69 | + const projects = [ |
| 70 | + createProject({ title: "Marketing Site" }), |
| 71 | + createProject({ title: "Other Project" }), |
| 72 | + ]; |
| 73 | + |
| 74 | + expect(searchProjects(projects, "missing")).toEqual([]); |
| 75 | + }); |
| 76 | +}); |
0 commit comments