From 013022d24f80f248161241027bf6b47e4e599198 Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Mon, 19 Jun 2023 15:06:06 +0800 Subject: [PATCH] fix(console): direct to new created tenant and clear create modal on open (#4051) --- .../CreateTenantModal/index.tsx | 3 ++- .../Topbar/TenantSelector/index.tsx | 1 + .../src/tests/ui-cloud/smoke.test.ts | 21 +++---------------- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/packages/console/src/cloud/pages/Main/TenantLandingPage/TenantLandingPageContent/CreateTenantModal/index.tsx b/packages/console/src/cloud/pages/Main/TenantLandingPage/TenantLandingPageContent/CreateTenantModal/index.tsx index ab0e4750c..1f9573d40 100644 --- a/packages/console/src/cloud/pages/Main/TenantLandingPage/TenantLandingPageContent/CreateTenantModal/index.tsx +++ b/packages/console/src/cloud/pages/Main/TenantLandingPage/TenantLandingPageContent/CreateTenantModal/index.tsx @@ -46,6 +46,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) { defaultValues: { tag: TenantTag.Development }, }); const { + reset, control, handleSubmit, formState: { errors, isSubmitting }, @@ -58,7 +59,7 @@ function CreateTenantModal({ isOpen, onClose }: Props) { try { const { name, tag } = data; const newTenant = await cloudApi.post('/api/tenants', { body: { name, tag } }); - + reset(); onClose(newTenant); } catch (error: unknown) { toast.error(error instanceof Error ? error.message : String(error)); diff --git a/packages/console/src/containers/AppContent/components/Topbar/TenantSelector/index.tsx b/packages/console/src/containers/AppContent/components/Topbar/TenantSelector/index.tsx index 002dd76ef..bc53191d2 100644 --- a/packages/console/src/containers/AppContent/components/Topbar/TenantSelector/index.tsx +++ b/packages/console/src/containers/AppContent/components/Topbar/TenantSelector/index.tsx @@ -115,6 +115,7 @@ function TenantSelector() { if (tenant) { toast.success(t('tenants.tenant_created', { name: tenant.name })); void mutate(); + window.location.assign(new URL(`/${tenant.id}`, window.location.origin).toString()); } setShowCreateTenantModal(false); }} diff --git a/packages/integration-tests/src/tests/ui-cloud/smoke.test.ts b/packages/integration-tests/src/tests/ui-cloud/smoke.test.ts index c6bdaf278..d329d3228 100644 --- a/packages/integration-tests/src/tests/ui-cloud/smoke.test.ts +++ b/packages/integration-tests/src/tests/ui-cloud/smoke.test.ts @@ -154,10 +154,10 @@ describe('smoke testing for cloud', () => { 'div[class$=ReactModalPortal] div[class*=card][class$=medium] div[class$=footer] button[type=submit]' ); - expect(new URL(page.url()).pathname.endsWith(`${defaultTenantId}/get-started`)).toBeTruthy(); + expect(new URL(page.url()).pathname.endsWith(`/get-started`)).toBeTruthy(); }); - it('check current tenant list and switch to new tenant', async () => { + it('should navigate to the new tenant', async () => { // Wait for toast to disappear. await page.waitForTimeout(5000); @@ -165,25 +165,10 @@ describe('smoke testing for cloud', () => { const currentTenantCard = await page.waitForSelector( 'div[class$=topbar] > div[class$=currentTenantCard][role=button]:has(div[class$=name])' ); - await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: 'My Project' }); - await currentTenantCard.click(); - - const newTenant = await page.waitForSelector( - 'div[class$=ReactModalPortal] div[class$=dropdownContainer] div[class$=dropdownItem]:first-child' - ); - await expect(newTenant).toMatchElement('div[class$=dropdownName]', { text: createTenantName }); - await newTenant.click(); - - await page.waitForNavigation({ waitUntil: 'networkidle0' }); + await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: createTenantName }); }); it('can sign out of admin console', async () => { - // Check if the current tenant is switched to new tenant. - const currentTenantCard = await page.waitForSelector( - 'div[class$=topbar] > div[class$=currentTenantCard][role=button]:has(div[class$=name])' - ); - await expect(currentTenantCard).toMatchElement('div[class$=name]', { text: createTenantName }); - const userInfoButton = await page.waitForSelector('div[class$=topbar] > div[class$=container]'); await userInfoButton.click();