test: mock fontStore and update FontStore type signatures
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
* const successState = createMockQueryState({ status: 'success', data: mockFonts });
|
||||
*
|
||||
* // Use preset stores
|
||||
* const mockFontStore = MOCK_STORES.unifiedFontStore();
|
||||
* const mockFontStore = createMockFontStore();
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -459,6 +459,117 @@ export const MOCK_STORES = {
|
||||
resetFilters: () => {},
|
||||
};
|
||||
},
|
||||
/**
|
||||
* Create a mock FontStore object
|
||||
* Matches FontStore's public API for Storybook use
|
||||
*/
|
||||
fontStore: (config: {
|
||||
fonts?: UnifiedFont[];
|
||||
total?: number;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
isLoading?: boolean;
|
||||
isFetching?: boolean;
|
||||
isError?: boolean;
|
||||
error?: Error | null;
|
||||
hasMore?: boolean;
|
||||
page?: number;
|
||||
} = {}) => {
|
||||
const {
|
||||
fonts: mockFonts = Object.values(UNIFIED_FONTS).slice(0, 5),
|
||||
total: mockTotal = mockFonts.length,
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
isLoading = false,
|
||||
isFetching = false,
|
||||
isError = false,
|
||||
error = null,
|
||||
hasMore = false,
|
||||
page = 1,
|
||||
} = config;
|
||||
|
||||
const totalPages = Math.ceil(mockTotal / limit);
|
||||
const state = {
|
||||
params: { limit },
|
||||
};
|
||||
|
||||
return {
|
||||
// State getters
|
||||
get params() {
|
||||
return state.params;
|
||||
},
|
||||
get fonts() {
|
||||
return mockFonts;
|
||||
},
|
||||
get isLoading() {
|
||||
return isLoading;
|
||||
},
|
||||
get isFetching() {
|
||||
return isFetching;
|
||||
},
|
||||
get isError() {
|
||||
return isError;
|
||||
},
|
||||
get error() {
|
||||
return error;
|
||||
},
|
||||
get isEmpty() {
|
||||
return !isLoading && !isFetching && mockFonts.length === 0;
|
||||
},
|
||||
get pagination() {
|
||||
return {
|
||||
total: mockTotal,
|
||||
limit,
|
||||
offset,
|
||||
hasMore,
|
||||
page,
|
||||
totalPages,
|
||||
};
|
||||
},
|
||||
// Category getters
|
||||
get sansSerifFonts() {
|
||||
return mockFonts.filter(f => f.category === 'sans-serif');
|
||||
},
|
||||
get serifFonts() {
|
||||
return mockFonts.filter(f => f.category === 'serif');
|
||||
},
|
||||
get displayFonts() {
|
||||
return mockFonts.filter(f => f.category === 'display');
|
||||
},
|
||||
get handwritingFonts() {
|
||||
return mockFonts.filter(f => f.category === 'handwriting');
|
||||
},
|
||||
get monospaceFonts() {
|
||||
return mockFonts.filter(f => f.category === 'monospace');
|
||||
},
|
||||
// Lifecycle
|
||||
destroy() {},
|
||||
// Param management
|
||||
setParams(_updates: Record<string, unknown>) {},
|
||||
invalidate() {},
|
||||
// Async operations (no-op for Storybook)
|
||||
refetch() {},
|
||||
prefetch() {},
|
||||
cancel() {},
|
||||
getCachedData() {
|
||||
return mockFonts.length > 0 ? mockFonts : undefined;
|
||||
},
|
||||
setQueryData() {},
|
||||
// Filter shortcuts
|
||||
setProviders() {},
|
||||
setCategories() {},
|
||||
setSubsets() {},
|
||||
setSearch() {},
|
||||
setSort() {},
|
||||
// Pagination navigation
|
||||
nextPage() {},
|
||||
prevPage() {},
|
||||
goToPage() {},
|
||||
setLimit(_limit: number) {
|
||||
state.params.limit = _limit;
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
// REACTIVE STATE MOCKS
|
||||
|
||||
Reference in New Issue
Block a user