From 0380d1be2b2a3dff96eaed7e70a9bcdf76827af7 Mon Sep 17 00:00:00 2001 From: Lisa Kim Date: Tue, 6 Aug 2024 16:20:58 -0700 Subject: [PATCH] Update test --- .../AutoDeploy/AutoDeploy.test.tsx | 11 ---- .../EnrollEKSCluster.test.tsx | 16 +++-- .../EnrollEc2Instance.test.tsx | 64 +++++++++---------- 3 files changed, 39 insertions(+), 52 deletions(-) diff --git a/web/packages/teleport/src/Discover/Database/DeployService/AutoDeploy/AutoDeploy.test.tsx b/web/packages/teleport/src/Discover/Database/DeployService/AutoDeploy/AutoDeploy.test.tsx index 8791e794fb45b..6f6df15755cb2 100644 --- a/web/packages/teleport/src/Discover/Database/DeployService/AutoDeploy/AutoDeploy.test.tsx +++ b/web/packages/teleport/src/Discover/Database/DeployService/AutoDeploy/AutoDeploy.test.tsx @@ -118,17 +118,6 @@ describe('test AutoDeploy.tsx', () => { await screen.findByText('subnet-id'); } - test('init: labels are rendered, command is not rendered yet', async () => { - const { teleCtx, discoverCtx } = getMockedContexts(); - - renderAutoDeploy(teleCtx, discoverCtx); - await waitForSubnetsAndSecurityGroups(); - - expect(screen.getByText(/env: prod/i)).toBeInTheDocument(); - expect(screen.queryByText(/copy\/paste/i)).not.toBeInTheDocument(); - expect(screen.queryByText(/curl/i)).not.toBeInTheDocument(); - }); - test('clicking button renders command', async () => { const { teleCtx, discoverCtx } = getMockedContexts(); diff --git a/web/packages/teleport/src/Discover/Kubernetes/EnrollEKSCluster/EnrollEKSCluster.test.tsx b/web/packages/teleport/src/Discover/Kubernetes/EnrollEKSCluster/EnrollEKSCluster.test.tsx index b5a5a2fdc412f..19a1d47f9df6c 100644 --- a/web/packages/teleport/src/Discover/Kubernetes/EnrollEKSCluster/EnrollEKSCluster.test.tsx +++ b/web/packages/teleport/src/Discover/Kubernetes/EnrollEKSCluster/EnrollEKSCluster.test.tsx @@ -115,8 +115,11 @@ describe('test EnrollEksCluster.tsx', () => { fireEvent.keyDown(selectEl, { key: 'ArrowDown', keyCode: 40 }); fireEvent.click(screen.getByText('us-east-2')); - // EKS results are rendered. await screen.findByText(/eks1/i); + + // Toggle on auto enroll. + act(() => screen.getByText(/auto-enroll all/i).click()); + // Cloud uses a default discovery group name. expect( screen.queryByText(/define a discovery group name/i) @@ -152,6 +155,12 @@ describe('test EnrollEksCluster.tsx', () => { fireEvent.keyDown(selectEl, { key: 'ArrowDown', keyCode: 40 }); fireEvent.click(screen.getByText('us-east-2')); + await screen.findByText(/eks1/i); + + // Toggle on auto enroll. + act(() => screen.getByText(/auto-enroll all/i).click()); + expect(screen.queryByText(/eks1/i)).not.toBeInTheDocument(); + // Only self-hosted need to define a discovery group name. await screen.findByText(/define a discovery group name/i); // There should be no table rendered. @@ -187,11 +196,6 @@ describe('test EnrollEksCluster.tsx', () => { await screen.findByText(/eks1/i); - // disable auto enroll - expect(screen.getByText('Next')).toBeEnabled(); - act(() => screen.getByText(/auto-enroll all/i).click()); - expect(screen.getByText('Enroll EKS Cluster')).toBeDisabled(); - act(() => screen.getByRole('radio').click()); act(() => screen.getByText('Enroll EKS Cluster').click()); diff --git a/web/packages/teleport/src/Discover/Server/EnrollEc2Instance/EnrollEc2Instance.test.tsx b/web/packages/teleport/src/Discover/Server/EnrollEc2Instance/EnrollEc2Instance.test.tsx index 920321be3e8c0..f1dc90188185d 100644 --- a/web/packages/teleport/src/Discover/Server/EnrollEc2Instance/EnrollEc2Instance.test.tsx +++ b/web/packages/teleport/src/Discover/Server/EnrollEc2Instance/EnrollEc2Instance.test.tsx @@ -120,11 +120,7 @@ describe('test EnrollEc2Instance.tsx', () => { .mockResolvedValue({ agents: mockFetchedNodes }); renderEc2Instances(ctx, discoverCtx); - await selectARegion({ waitForSelfHosted: true }); - - // toggle off auto enroll, to test the table. - await userEvent.click(screen.getByText(/auto-enroll all/i)); - await screen.findAllByText(/My EC2 Box 1/i); + await selectARegion({ waitForTable: true }); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledTimes(1); expect(ctx.nodeService.fetchNodes).toHaveBeenCalledTimes(1); @@ -154,11 +150,7 @@ describe('test EnrollEc2Instance.tsx', () => { .mockResolvedValue({ instances: mockEc2Instances }); renderEc2Instances(ctx, discoverCtx); - await selectARegion({ waitForSelfHosted: true }); - - // toggle off auto enroll - await userEvent.click(screen.getByText(/auto-enroll all/i)); - await screen.findAllByText(/My EC2 Box 1/i); + await selectARegion({ waitForTable: true }); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledTimes(1); expect(ctx.nodeService.fetchNodes).toHaveBeenCalledTimes(1); @@ -179,23 +171,18 @@ describe('test EnrollEc2Instance.tsx', () => { .mockResolvedValue({ instances: mockEc2Instances }); renderEc2Instances(ctx, discoverCtx); - await selectARegion({ waitForSelfHosted: true }); - - // default toggler should be checked. - expect(screen.getByTestId('toggle')).toBeChecked(); - expect(screen.queryByText(/My EC2 Box 1/i)).not.toBeInTheDocument(); - expect(screen.getByText(/next/i, { selector: 'button' })).toBeEnabled(); + await selectARegion({ waitForTable: true }); - // toggle off auto enroll, should render table. - await userEvent.click(screen.getByText(/auto-enroll all/i)); + // default toggler should not be checked. expect(screen.getByTestId('toggle')).not.toBeChecked(); expect(screen.getByText(/next/i, { selector: 'button' })).toBeDisabled(); - await screen.findAllByText(/My EC2 Box 1/i); - - // toggle it back on. + // toggle on auto enroll, should render table. await userEvent.click(screen.getByText(/auto-enroll all/i)); expect(screen.getByTestId('toggle')).toBeChecked(); + expect(screen.getByText(/next/i, { selector: 'button' })).toBeEnabled(); + expect(screen.queryByText(/My EC2 Box 1/i)).not.toBeInTheDocument(); + expect(screen.getByText(/create a join token/i)).toBeInTheDocument(); }); test('cloud, auto discover toggling', async () => { @@ -210,20 +197,12 @@ describe('test EnrollEc2Instance.tsx', () => { renderEc2Instances(ctx, discoverCtx); await selectARegion({ waitForTable: true }); - // default toggler should be checked. - expect(screen.queryByText(/create a join token/i)).not.toBeInTheDocument(); - expect(screen.getByTestId('toggle')).toBeChecked(); - expect(screen.getByText(/next/i, { selector: 'button' })).toBeEnabled(); - - // toggle off auto enroll - await userEvent.click(screen.getByText(/auto-enroll all/i)); - await screen.findAllByText(/My EC2 Box 1/i); + // default toggler should be off. expect(screen.getByTestId('toggle')).not.toBeChecked(); - expect(screen.getByText(/next/i, { selector: 'button' })).toBeDisabled(); - // toggle it back on. await userEvent.click(screen.getByText(/auto-enroll all/i)); - expect(screen.getByTestId('toggle')).toBeChecked(); + expect(screen.getByText(/next/i, { selector: 'button' })).toBeEnabled(); + expect(screen.queryByText(/create a join token/i)).not.toBeInTheDocument(); }); test('self-hosted, auto discover without existing endpoints', async () => { @@ -246,7 +225,10 @@ describe('test EnrollEc2Instance.tsx', () => { }); renderEc2Instances(ctx, discoverCtx); - await selectARegion({ waitForSelfHosted: true }); + await selectARegion({ waitForTable: true }); + + // Toggle on. + await userEvent.click(screen.getByText(/auto-enroll all/i)); await userEvent.click(screen.getByText(/next/i, { selector: 'button' })); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledWith( @@ -278,7 +260,10 @@ describe('test EnrollEc2Instance.tsx', () => { }); renderEc2Instances(ctx, discoverCtx); - await selectARegion({ waitForSelfHosted: true }); + await selectARegion({ waitForTable: true }); + + // Toggle on. + await userEvent.click(screen.getByText(/auto-enroll all/i)); await userEvent.click(screen.getByText(/next/i, { selector: 'button' })); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledTimes(1); @@ -322,6 +307,9 @@ describe('test EnrollEc2Instance.tsx', () => { renderEc2Instances(ctx, discoverCtx); await selectARegion({ waitForTable: true }); + // Toggle on. + await userEvent.click(screen.getByText(/auto-enroll all/i)); + await userEvent.click(screen.getByText(/next/i, { selector: 'button' })); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledWith( discoverCtx.agentMeta.awsIntegration.name, @@ -388,6 +376,9 @@ describe('test EnrollEc2Instance.tsx', () => { renderEc2Instances(ctx, discoverCtx); await selectARegion({ waitForTable: true }); + // Toggle on. + await userEvent.click(screen.getByText(/auto-enroll all/i)); + await userEvent.click(screen.getByText(/next/i, { selector: 'button' })); expect(integrationService.fetchAwsEc2Instances).toHaveBeenCalledWith( discoverCtx.agentMeta.awsIntegration.name, @@ -409,7 +400,6 @@ describe('test EnrollEc2Instance.tsx', () => { test('cloud, with partially created endpoints, with already set discovery config', async () => { cfg.isCloud = true; - jest.useFakeTimers(); const { ctx, discoverCtx } = getMockedContexts( true /* withAutoDiscovery */ @@ -469,7 +459,11 @@ describe('test EnrollEc2Instance.tsx', () => { renderEc2Instances(ctx, discoverCtx); await selectARegion({ waitForTable: true }); + await userEvent.click(screen.getByText(/auto-enroll all/i)); + expect(screen.getByTestId('toggle')).toBeChecked(); + // Test it's polling. + jest.useFakeTimers(); fireEvent.click(screen.getByText(/next/i, { selector: 'button' })); await screen.findByText(/this may take a few minutes/i);