@@ -11,6 +11,14 @@ describe("findComponent", () => {
1111 template : "<div>Create Workspace Component</div>" ,
1212 }
1313
14+ const MockListComponent = {
15+ template : "<div>List Component</div>" ,
16+ }
17+
18+ const MockAccountListComponent = {
19+ template : "<div>Account List Component</div>" ,
20+ }
21+
1422 it ( "should find exact component match for 'workspace'" , ( ) => {
1523 const components : ComponentMap = {
1624 "../../lib/live_vue/web/pages/workspace.vue" : MockComponent ,
@@ -69,7 +77,7 @@ describe("findComponent", () => {
6977 }
7078
7179 const result1 = findComponent ( components , "workspace" )
72- const result2 = findComponent ( components , "dashboard" )
80+ const result2 = findComponent ( components , "dashboard/index.vue " )
7381
7482 expect ( result1 ) . toBe ( MockComponent )
7583 expect ( result2 ) . toBe ( MockCreateWorkspaceComponent )
@@ -85,4 +93,118 @@ describe("findComponent", () => {
8593
8694 expect ( result ) . toBe ( MockComponent )
8795 } )
96+
97+ it ( "should find component by path suffix when filename is ambiguous" , ( ) => {
98+ const components : ComponentMap = {
99+ "../../lib/live_vue/web/components/workspaces/List.vue" : MockListComponent ,
100+ "../../lib/live_vue/web/components/accounts/List.vue" : MockAccountListComponent ,
101+ }
102+
103+ const result1 = findComponent ( components , "workspaces/List" )
104+ const result2 = findComponent ( components , "accounts/List" )
105+
106+ expect ( result1 ) . toBe ( MockListComponent )
107+ expect ( result2 ) . toBe ( MockAccountListComponent )
108+ } )
109+
110+ it ( "should throw ambiguous error when filename matches multiple components" , ( ) => {
111+ const components : ComponentMap = {
112+ "../../lib/live_vue/web/components/workspaces/List.vue" : MockListComponent ,
113+ "../../lib/live_vue/web/components/accounts/List.vue" : MockAccountListComponent ,
114+ }
115+
116+ expect ( ( ) => findComponent ( components , "List" ) ) . toThrow ( "Component 'List' is ambiguous" )
117+ } )
118+
119+ it ( "should match by shorter path suffix" , ( ) => {
120+ const components : ComponentMap = {
121+ "../../lib/live_vue/web/pages/admin/workspaces/List.vue" : MockListComponent ,
122+ }
123+
124+ const result = findComponent ( components , "workspaces/List" )
125+
126+ expect ( result ) . toBe ( MockListComponent )
127+ } )
128+
129+ it ( "should handle components with .vue extension in name" , ( ) => {
130+ const components : ComponentMap = {
131+ "../../lib/live_vue/web/components/workspaces/List.vue" : MockListComponent ,
132+ }
133+
134+ const result = findComponent ( components , "workspaces/List.vue" )
135+
136+ expect ( result ) . toBe ( MockListComponent )
137+ } )
138+
139+ it ( "should match longest unambiguous path suffix" , ( ) => {
140+ const components : ComponentMap = {
141+ "../../lib/live_vue/web/admin/accounts/settings/Form.vue" : MockComponent ,
142+ "../../lib/live_vue/web/public/accounts/settings/Form.vue" : MockListComponent ,
143+ }
144+
145+ const result = findComponent ( components , "admin/accounts/settings/Form" )
146+
147+ expect ( result ) . toBe ( MockComponent )
148+ } )
149+
150+ it ( "should handle deep nested index.vue files" , ( ) => {
151+ const components : ComponentMap = {
152+ "../../lib/live_vue/web/pages/admin/settings/profile/index.vue" : MockComponent ,
153+ }
154+
155+ const result1 = findComponent ( components , "profile" )
156+ const result2 = findComponent ( components , "settings/profile" )
157+ const result3 = findComponent ( components , "admin/settings/profile" )
158+
159+ expect ( result1 ) . toBe ( MockComponent )
160+ expect ( result2 ) . toBe ( MockComponent )
161+ expect ( result3 ) . toBe ( MockComponent )
162+ } )
163+
164+ it ( "should throw ambiguous error for multiple index.vue matches" , ( ) => {
165+ const components : ComponentMap = {
166+ "../../lib/live_vue/web/pages/admin/settings/index.vue" : MockComponent ,
167+ "../../lib/live_vue/web/pages/user/settings/index.vue" : MockListComponent ,
168+ }
169+
170+ expect ( ( ) => findComponent ( components , "settings" ) ) . toThrow ( "Component 'settings' is ambiguous" )
171+ } )
172+
173+ it ( "should handle mix of index.vue and regular .vue files" , ( ) => {
174+ const components : ComponentMap = {
175+ "../../lib/live_vue/web/pages/workspace/index.vue" : MockComponent ,
176+ "../../lib/live_vue/web/pages/workspace.vue" : MockListComponent ,
177+ }
178+
179+ expect ( ( ) => findComponent ( components , "workspace" ) ) . toThrow ( "Component 'workspace' is ambiguous" )
180+ } )
181+
182+ it ( "should handle empty component name gracefully" , ( ) => {
183+ const components : ComponentMap = {
184+ "../../lib/live_vue/web/pages/workspace.vue" : MockComponent ,
185+ }
186+
187+ expect ( ( ) => findComponent ( components , "" ) ) . toThrow ( "Component '' not found!" )
188+ } )
189+
190+ it ( "should handle names with multiple slashes" , ( ) => {
191+ const components : ComponentMap = {
192+ "../../lib/live_vue/web/pages/admin/users/settings/Form.vue" : MockComponent ,
193+ }
194+
195+ const result = findComponent ( components , "admin/users/settings/Form" )
196+
197+ expect ( result ) . toBe ( MockComponent )
198+ } )
199+
200+ it ( "should not match partial directory names" , ( ) => {
201+ const components : ComponentMap = {
202+ "../../lib/live_vue/web/components/workspace-list/Item.vue" : MockComponent ,
203+ "../../lib/live_vue/web/components/workspace/Item.vue" : MockListComponent ,
204+ }
205+
206+ const result = findComponent ( components , "workspace/Item" )
207+
208+ expect ( result ) . toBe ( MockListComponent )
209+ } )
88210} )
0 commit comments