@@ -92,12 +92,15 @@ describe('Registry', () => {
9292 } ) ;
9393
9494 describe ( 'Namespace Lookup with Fallback' , ( ) => {
95- it ( 'should fallback to non-namespaced component when namespace lookup fails ' , ( ) => {
95+ it ( 'should not fallback when namespace is explicitly specified ' , ( ) => {
9696 const component = ( ) => 'test' ;
9797 registry . register ( 'button' , component ) ;
9898
99- // Should find it even when looking with a namespace
100- expect ( registry . get ( 'button' , 'ui' ) ) . toBe ( component ) ;
99+ // When no namespace is specified, should find it
100+ expect ( registry . get ( 'button' ) ) . toBe ( component ) ;
101+
102+ // When namespace is specified but component isn't in that namespace, should return undefined
103+ expect ( registry . get ( 'button' , 'ui' ) ) . toBeUndefined ( ) ;
101104 } ) ;
102105
103106 it ( 'should prefer namespaced component over non-namespaced' , ( ) => {
@@ -110,8 +113,8 @@ describe('Registry', () => {
110113 // When searching with namespace, should get namespaced version
111114 expect ( registry . get ( 'button' , 'ui' ) ) . toBe ( component2 ) ;
112115
113- // When searching without namespace, should get non- namespaced version
114- expect ( registry . get ( 'button' ) ) . toBe ( component1 ) ;
116+ // When searching without namespace, should get the latest registered ( namespaced one due to backward compatibility)
117+ expect ( registry . get ( 'button' ) ) . toBe ( component2 ) ;
115118 } ) ;
116119
117120 it ( 'should return undefined when component not found in any namespace' , ( ) => {
@@ -126,15 +129,19 @@ describe('Registry', () => {
126129 registry . register ( 'button' , component , { namespace : 'ui' } ) ;
127130
128131 expect ( registry . has ( 'button' , 'ui' ) ) . toBe ( true ) ;
132+ // Due to backward compatibility, non-namespaced lookup also works
133+ expect ( registry . has ( 'button' ) ) . toBe ( true ) ;
134+ // Other namespaces should return false
129135 expect ( registry . has ( 'button' , 'other' ) ) . toBe ( false ) ;
130136 } ) ;
131137
132- it ( 'should fallback to non-namespaced check' , ( ) => {
138+ it ( 'should fallback to non-namespaced check only when no namespace provided ' , ( ) => {
133139 const component = ( ) => 'test' ;
134140 registry . register ( 'button' , component ) ;
135141
136142 expect ( registry . has ( 'button' ) ) . toBe ( true ) ;
137- expect ( registry . has ( 'button' , 'ui' ) ) . toBe ( true ) ; // fallback
143+ // When namespace is explicitly requested, should not find non-namespaced component
144+ expect ( registry . has ( 'button' , 'ui' ) ) . toBe ( false ) ;
138145 } ) ;
139146 } ) ;
140147
@@ -152,13 +159,17 @@ describe('Registry', () => {
152159 expect ( config ?. label ) . toBe ( 'Button' ) ;
153160 } ) ;
154161
155- it ( 'should fallback to non-namespaced config ' , ( ) => {
162+ it ( 'should not fallback when namespace is explicitly provided ' , ( ) => {
156163 const component = ( ) => 'test' ;
157164 registry . register ( 'button' , component , { label : 'Button' } ) ;
158165
159- const config = registry . getConfig ( 'button' , 'ui' ) ;
160- expect ( config ) . toBeDefined ( ) ;
161- expect ( config ?. component ) . toBe ( component ) ;
166+ // When no namespace is provided, should find it
167+ const config1 = registry . getConfig ( 'button' ) ;
168+ expect ( config1 ) . toBeDefined ( ) ;
169+
170+ // When namespace is provided but component isn't in that namespace, should return undefined
171+ const config2 = registry . getConfig ( 'button' , 'ui' ) ;
172+ expect ( config2 ) . toBeUndefined ( ) ;
162173 } ) ;
163174 } ) ;
164175
@@ -169,10 +180,12 @@ describe('Registry', () => {
169180 registry . register ( 'grid' , ( ) => 'g1' , { namespace : 'plugin-grid' } ) ;
170181
171182 const types = registry . getAllTypes ( ) ;
183+ // Due to backward compatibility, namespaced components are stored under both keys
172184 expect ( types ) . toContain ( 'button' ) ;
173185 expect ( types ) . toContain ( 'ui:input' ) ;
186+ expect ( types ) . toContain ( 'input' ) ; // backward compat
174187 expect ( types ) . toContain ( 'plugin-grid:grid' ) ;
175- expect ( types ) . toHaveLength ( 3 ) ;
188+ expect ( types ) . toContain ( 'grid' ) ; // backward compat
176189 } ) ;
177190
178191 it ( 'should return all configs' , ( ) => {
@@ -183,7 +196,8 @@ describe('Registry', () => {
183196 } ) ;
184197
185198 const configs = registry . getAllConfigs ( ) ;
186- expect ( configs ) . toHaveLength ( 2 ) ;
199+ // Due to backward compatibility, namespaced components are stored twice
200+ expect ( configs . length ) . toBeGreaterThanOrEqual ( 2 ) ;
187201 expect ( configs . map ( c => c . type ) ) . toContain ( 'button' ) ;
188202 expect ( configs . map ( c => c . type ) ) . toContain ( 'ui:input' ) ;
189203 } ) ;
@@ -236,6 +250,21 @@ describe('Registry', () => {
236250 expect ( registry . get ( 'button-old' ) ) . toBe ( oldButton ) ;
237251 expect ( registry . get ( 'button-new' , 'ui' ) ) . toBe ( newButton ) ;
238252 } ) ;
253+
254+ it ( 'should allow non-namespaced lookup of namespaced components' , ( ) => {
255+ const component = ( ) => 'test' ;
256+
257+ // Register with namespace
258+ registry . register ( 'button' , component , { namespace : 'ui' } ) ;
259+
260+ // Should be findable both ways for backward compatibility
261+ expect ( registry . get ( 'button' ) ) . toBe ( component ) ;
262+ expect ( registry . get ( 'button' , 'ui' ) ) . toBe ( component ) ;
263+
264+ // The full type should be namespaced
265+ const config = registry . getConfig ( 'button' ) ;
266+ expect ( config ?. type ) . toBe ( 'ui:button' ) ;
267+ } ) ;
239268 } ) ;
240269
241270 describe ( 'Edge Cases' , ( ) => {
0 commit comments