All files / src/pages/admin projects.test-utils.ts

100% Statements 15/15
100% Branches 6/6
100% Functions 7/7
100% Lines 12/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164        5x                             5x     5x   45x                                                                 10x                                                                                                                                 13x                                         5x                 12x 12x 42x 42x       90x        
import { vi } from "vitest";
import type { Project, Pro } from "../../lib/api";
 
// Mock router state helper
export const mockRouterState = {
	location: {
		pathname: "/admin/projects",
		search: "",
		hash: "",
		href: "/admin/projects",
		state: {},
	},
	matches: [],
	status: "idle" as const,
	isLoading: false,
	isTransitioning: false,
};
 
// Mock navigate function
export const mockNavigate = vi.fn();
 
// Project factory
export const createMockProject = (
	overrides: Partial<Project> = {},
): Project => ({
	id: "p1",
	proId: "v1",
	title: "Modern Living Room Design",
	description: "A beautiful modern living room",
	status: "draft",
	sort: 1,
	isFeatured: false,
	dateCreated: "2024-01-15T00:00:00Z",
	dateUpdated: "2024-01-15T00:00:00Z",
	coverImage: null,
	scope: null,
	workedAreaIds: null,
	localityId: null,
	propertyType: null,
	propertySize: null,
	projectAreaSqft: null,
	budgetRange: null,
	duration: null,
	materialTagIds: null,
	isBeforeAfter: false,
	clientTestimonial: null,
	yearCompleted: null,
	metaTitle: null,
	metaDescription: null,
	ogImage: null,
	useRooms: false,
	defaultRoomId: null,
	styleTagIds: null,
	...overrides,
});
 
// Pro factory - used by getDefaultMockPros
const createMockPro = (overrides: Partial<Pro> = {}): Pro => ({
	id: "v1",
	businessName: "Interior Design Studio",
	slug: "interior-design-studio",
	status: "published",
	whatsapp: null,
	description: null,
	profileImage: null,
	isFeatured: false,
	businessTypeId: null,
	businessTypesSecondary: null,
	timelineCapabilities: null,
	customerSegmentId: null,
	customerSegmentsSecondary: null,
	projectScaleIds: null,
	serviceCategoryIds: null,
	materialTagIds: null,
	brandsWorkWith: null,
	brandsOfficialPartner: null,
	serviceAreaIds: null,
	cityId: null,
	phoneAlternate: null,
	email: null,
	businessAddress: null,
	yearsInBusiness: null,
	teamSize: null,
	languagesSpoken: null,
	coverImage: null,
	profileFields: null,
	acceptsRushOrders: false,
	rushOrderPremium: null,
	viewCount: 0,
	lastViewedAt: null,
	metaTitle: null,
	metaDescription: null,
	ogImage: null,
	addressLine1: null,
	addressLine2: null,
	addressCity: null,
	addressState: null,
	addressPincode: null,
	priceRangeMin: null,
	priceRangeMax: null,
	minProjectValue: null,
	logoUrl: null,
	brandColorPrimary: null,
	brandColorSecondary: null,
	tagline: null,
	about: null,
	processDescription: null,
	instagramHandle: null,
	facebookUrl: null,
	youtubeUrl: null,
	googleBusinessUrl: null,
	websiteUrl: null,
	linkedinUrl: null,
	twitterUrl: null,
	pinterestUrl: null,
	whatsappBusinessNumber: null,
	dateCreated: "2024-01-01T00:00:00Z",
	dateUpdated: "2024-01-01T00:00:00Z",
	...overrides,
});
 
// Default test data
export const getDefaultMockProjects = (): Project[] => [
	createMockProject({
		id: "p1",
		proId: "v1",
		title: "Modern Kitchen Renovation",
		status: "published",
	}),
	createMockProject({
		id: "p2",
		proId: "v2",
		title: "Bedroom Makeover",
		status: "draft",
	}),
	createMockProject({
		id: "p3",
		proId: "v1",
		title: "Bathroom Redesign",
		status: "archived",
	}),
];
 
export const getDefaultMockPros = (): Pro[] => [
	createMockPro({ id: "v1", businessName: "Design Studio Alpha" }),
	createMockPro({ id: "v2", businessName: "Interior Experts Beta" }),
];
 
// Helper to find project status dropdowns in the table
export function findProjectStatusDropdowns(screen: {
	getAllByRole: (role: string) => HTMLElement[];
}) {
	const allDropdowns = screen.getAllByRole("combobox");
	return allDropdowns.filter((select) => {
		const options = Array.from(select.querySelectorAll("option"));
		return (
			options.length === 3 &&
			options.some((opt) => opt.value === "draft") &&
			options.some((opt) => opt.value === "published") &&
			options.some((opt) => opt.value === "archived")
		);
	});
}