@@ -4,10 +4,7 @@ import yaml from "js-yaml";
44import { type ReactNode } from "react" ;
55import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
66
7- import type {
8- ComponentFolder ,
9- ComponentLibrary ,
10- } from "@/types/componentLibrary" ;
7+ import type { ComponentFolder } from "@/types/componentLibrary" ;
118import type {
129 ComponentReference ,
1310 ComponentSpec ,
@@ -43,30 +40,20 @@ vi.mock("./componentLibrary");
4340import * as componentLibraryUtils from "@/providers/ComponentLibraryProvider/componentLibrary" ;
4441import * as componentStore from "@/utils/componentStore" ;
4542import * as getComponentName from "@/utils/getComponentName" ;
46- import * as localforage from "@/utils/localforage" ;
4743
4844// Mock implementations
4945
50- const mockFetchUserComponents = vi . mocked (
51- componentLibraryUtils . fetchUserComponents ,
52- ) ;
5346const mockFetchUsedComponents = vi . mocked (
5447 componentLibraryUtils . fetchUsedComponents ,
5548) ;
56- const mockPopulateComponentRefs = vi . mocked (
57- componentLibraryUtils . populateComponentRefs ,
58- ) ;
5949const mockFlattenFolders = vi . mocked ( componentLibraryUtils . flattenFolders ) ;
6050const mockFilterToUniqueByDigest = vi . mocked (
6151 componentLibraryUtils . filterToUniqueByDigest ,
6252) ;
63- const mockImportComponent = vi . mocked ( componentStore . importComponent ) ;
6453const mockDeleteComponentFileFromList = vi . mocked (
6554 componentStore . deleteComponentFileFromList ,
6655) ;
67- const mockGetUserComponentByName = vi . mocked (
68- localforage . getUserComponentByName ,
69- ) ;
56+
7057const mockGetComponentName = vi . mocked ( getComponentName . getComponentName ) ;
7158
7259describe ( "ComponentLibraryProvider - Component Management" , ( ) => {
@@ -79,36 +66,6 @@ describe("ComponentLibraryProvider - Component Management", () => {
7966 } ,
8067 } ;
8168
82- const mockComponentLibrary : ComponentLibrary = {
83- folders : [
84- {
85- name : "Test Folder" ,
86- components : [
87- {
88- name : "test-component" ,
89- digest : "test-digest-1" ,
90- url : "https://example.com/component1.yaml" ,
91- spec : mockComponentSpec ,
92- } ,
93- ] ,
94- folders : [ ] ,
95- } ,
96- ] ,
97- } ;
98-
99- const mockUserComponentsFolder : ComponentFolder = {
100- name : "User Components" ,
101- components : [
102- {
103- name : "user-component" ,
104- digest : "user-digest-1" ,
105- spec : mockComponentSpec ,
106- text : "test yaml content" ,
107- } ,
108- ] ,
109- folders : [ ] ,
110- } ;
111-
11269 const createWrapper = ( { children } : { children : ReactNode } ) => {
11370 const queryClient = new QueryClient ( {
11471 defaultOptions : {
@@ -131,13 +88,12 @@ describe("ComponentLibraryProvider - Component Management", () => {
13188 componentDuplicateDialogProps . handleImportComponent = undefined ;
13289
13390 // Setup default mock implementations
134- mockFetchUserComponents . mockResolvedValue ( mockUserComponentsFolder ) ;
13591 mockFetchUsedComponents . mockReturnValue ( {
13692 name : "Used Components" ,
13793 components : [ ] ,
13894 folders : [ ] ,
13995 } ) ;
140- mockPopulateComponentRefs . mockImplementation ( ( lib ) => Promise . resolve ( lib ) ) ;
96+
14197 mockFlattenFolders . mockImplementation ( ( folder ) => {
14298 if ( "folders" in folder ) {
14399 return folder . folders ?. flatMap ( ( f ) => f . components || [ ] ) || [ ] ;
@@ -207,16 +163,11 @@ describe("ComponentLibraryProvider - Component Management", () => {
207163
208164 // Mock that there's an existing component with the same name
209165 mockFlattenFolders . mockReturnValue ( [ existingComponent ] ) ;
210- mockGetUserComponentByName . mockResolvedValue ( mockUserComponent ) ;
211166
212167 const { result } = renderHook ( ( ) => useComponentLibrary ( ) , {
213168 wrapper : createWrapper ,
214169 } ) ;
215170
216- await waitFor ( ( ) => {
217- expect ( result . current . isLoading ) . toBe ( false ) ;
218- } ) ;
219-
220171 await act ( async ( ) => {
221172 void result . current . addToComponentLibrary ( newComponent ) ;
222173 } ) ;
@@ -481,51 +432,4 @@ describe("ComponentLibraryProvider - Component Management", () => {
481432 consoleSpy . mockRestore ( ) ;
482433 } ) ;
483434 } ) ;
484-
485- describe ( "Component Checks" , ( ) => {
486- it ( "should correctly identify user components" , async ( ) => {
487- const userComponent : ComponentReference = {
488- name : "user-component" ,
489- digest : "user-digest-1" ,
490- spec : mockComponentSpec ,
491- } ;
492-
493- mockFlattenFolders . mockReturnValue ( [ userComponent ] ) ;
494- mockFilterToUniqueByDigest . mockReturnValue ( [ userComponent ] ) ;
495-
496- const { result } = renderHook ( ( ) => useComponentLibrary ( ) , {
497- wrapper : createWrapper ,
498- } ) ;
499-
500- await waitFor ( ( ) => {
501- expect ( result . current . isLoading ) . toBe ( false ) ;
502- } ) ;
503-
504- const isUserComponent =
505- result . current . checkIfUserComponent ( userComponent ) ;
506- expect ( isUserComponent ) . toBe ( true ) ;
507- } ) ;
508-
509- it ( "should correctly identify non-user components" , async ( ) => {
510- const standardComponent : ComponentReference = {
511- name : "standard-component" ,
512- digest : "standard-digest" ,
513- spec : mockComponentSpec ,
514- } ;
515-
516- mockFlattenFolders . mockReturnValue ( [ ] ) ; // No user components
517-
518- const { result } = renderHook ( ( ) => useComponentLibrary ( ) , {
519- wrapper : createWrapper ,
520- } ) ;
521-
522- await waitFor ( ( ) => {
523- expect ( result . current . isLoading ) . toBe ( false ) ;
524- } ) ;
525-
526- const isUserComponent =
527- result . current . checkIfUserComponent ( standardComponent ) ;
528- expect ( isUserComponent ) . toBe ( false ) ;
529- } ) ;
530- } ) ;
531435} ) ;
0 commit comments