Skip to content

Commit

Permalink
refactor: streamline test implementations by updating imports, enhanc…
Browse files Browse the repository at this point in the history
…ing element queries, and improving asynchronous handling across multiple test files
  • Loading branch information
hervedombya committed Jan 16, 2025
1 parent 061d5ef commit bf8dd7b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ describe('Policy Attachments', () => {
expect(screen.getByRole('tab', { name: /roles/i })).toBeInTheDocument();
});

it('should render the attached Users in Users Tab', async () => {
it.only('should render the attached Users in Users Tab', async () => {
// S
setupPolicyRender();
//E
Expand Down
12 changes: 2 additions & 10 deletions src/react/locations/__tests__/LocationEditor.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ describe('LocationEditor', () => {
it('should display storageOptions expect hidden options', async () => {
const {
component: { container },
} = reduxRender(
<MemoryRouter>
<LocationEditor />
</MemoryRouter>,
);
} = reduxRender(<LocationEditor />);

await waitForElementToBeRemoved(() =>
screen.getByText('Loading location...'),
Expand Down Expand Up @@ -117,11 +113,7 @@ describe('LocationEditor', () => {
});

it(`test if each location display correctly`, async () => {
reduxRender(
<MemoryRouter>
<LocationEditor />
</MemoryRouter>,
);
reduxRender(<LocationEditor />);

await waitForElementToBeRemoved(() =>
screen.getByText('Loading location...'),
Expand Down
5 changes: 2 additions & 3 deletions src/react/ui-elements/__tests__/Activity.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Activity, { DEFAULT_MESSAGE } from '../Activity';
import { List } from 'immutable';
import { reduxMount, renderWithRouterMatch } from '../../utils/testUtil';
import { render, screen } from '@testing-library/react';
import { screen } from '@testing-library/react';

describe('Activity', () => {
const TEST_MESSAGE = 'This is a test message';
Expand All @@ -26,8 +26,7 @@ describe('Activity', () => {
expect(screen.getByText(DEFAULT_MESSAGE)).toBeInTheDocument();
});
it('Activity should not render', () => {
render(<Activity />, {
// @ts-expect-error
reduxMount(<Activity />, {
networkActivity: {
counter: 0,
messages: List(),
Expand Down
15 changes: 14 additions & 1 deletion src/react/workflow/__tests__/ExpirationForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ import {
TEST_API_BASE_URL,
zenkoUITestConfig,
} from '../../utils/testUtil';
import { act, fireEvent, screen, waitFor } from '@testing-library/react';
import {
act,
fireEvent,
screen,
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react';
import React from 'react';
import ExpirationForm from '../ExpirationForm';
import { FormProvider, useForm } from 'react-hook-form';
Expand All @@ -28,6 +34,7 @@ import {
INSTANCE_ID,
waitForSelectOptionToBeEnabled,
} from '../../actions/__tests__/utils/testUtil';
import { debug } from 'jest-preview';

const instanceId = 'instanceId';
const accountName = 'pat';
Expand Down Expand Up @@ -124,6 +131,12 @@ describe('ExpirationForm', () => {
);

await waitFor(() => screen.getByText(/General/i));

await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
{ timeout: 8000 },
);

expect(screen.getByText(/State/i)).toBeInTheDocument();
expect(screen.getAllByText(/Source/i)[0]).toBeInTheDocument();
expect(screen.getByText(/Bucket Name/i)).toBeInTheDocument();
Expand Down
11 changes: 10 additions & 1 deletion src/react/workflow/__tests__/Workflows.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { screen, waitFor } from '@testing-library/react';
import {
screen,
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react';
import { rest } from 'msw';
import { setupServer } from 'msw/node';
import {
Expand Down Expand Up @@ -168,6 +172,11 @@ describe('Workflows', () => {
//E
await waitFor(() => screen.getByText(TEST_ACCOUNT));
await waitFor(() => screen.queryAllByText(/expiration/i));

await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
{ timeout: 8000 },
);
//V
expect(
screen.getByRole('checkbox', {
Expand Down

0 comments on commit bf8dd7b

Please sign in to comment.