diff --git a/shell/components/form/NameNsDescription.vue b/shell/components/form/NameNsDescription.vue index 8bf73fe0205..96fdfdb377c 100644 --- a/shell/components/form/NameNsDescription.vue +++ b/shell/components/form/NameNsDescription.vue @@ -305,7 +305,7 @@ export default { namespace.value = toRef(props.forceNamespace); updateNamespace(namespace); } else if (props.namespaceKey) { - namespace.value = get(v, props.namespaceKey); + namespace.value = get(v.value, props.namespaceKey); } else { namespace.value = metadata?.namespace; } diff --git a/shell/components/form/__tests__/NameNsDescription.test.ts b/shell/components/form/__tests__/NameNsDescription.test.ts index 3f7d57a7daa..e19260e5d66 100644 --- a/shell/components/form/__tests__/NameNsDescription.test.ts +++ b/shell/components/form/__tests__/NameNsDescription.test.ts @@ -87,6 +87,48 @@ describe('component: NameNsDescription', () => { expect(wrapper.emitted().isNamespaceNew?.[0][0]).toBe(true); }); + it('should set the namespace using the namespaceKey prop', () => { + const namespaceName = 'custom-namespace'; + const store = createStore({ + getters: { + allowedNamespaces: () => () => ({ [namespaceName]: true }), + currentStore: () => () => 'cluster', + 'cluster/schemaFor': () => jest.fn() + } + }); + + const wrapper = mount(NameNsDescription, { + props: { + value: { + setAnnotation: jest.fn(), + metadata: {}, + value: { metadata: { namespace: namespaceName } } + }, + mode: 'create', + namespaceKey: 'value.metadata.namespace', + }, + global: { + provide: { store }, + mocks: { + $store: { + dispatch: jest.fn(), + getters: { + namespaces: jest.fn(), + 'customizations/getPreviewCluster': { + ready: true, + isLocal: false, + badge: {}, + }, + 'i18n/t': jest.fn(), + }, + }, + }, + }, + }); + + expect((wrapper.vm as any).namespace).toBe(namespaceName); + }); + it('renders the name input with the expected value', () => { const namespaceName = 'test'; const store = createStore({