Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
kimlisa committed Aug 6, 2024
1 parent b91d041 commit 0380d1b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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(
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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 */
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0380d1b

Please sign in to comment.