Skip to content

Commit

Permalink
test: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgadewoll committed Jul 23, 2024
1 parent eea8d95 commit 6fd8082
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ describe('helpers', () => {
</TestProviders>
);

expect(screen.getByTestId('incompatibleStat')).toHaveTextContent('-- --'); // the euiScreenReaderOnly content renders an additional set of --
expect(screen.getByTestId('incompatibleStat')).toHaveTextContent('--');
});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import * as fetcherHook from '@kbn/observability-shared-plugin/public/hooks/use_fetcher';
import { screen } from '@elastic/eui/lib/test/rtl';
import { render, data as dataMock } from '../../../../../utils/test_helper';
import { CoreStart } from '@kbn/core/public';
import { ConfigSchema, ObservabilityPublicPluginsStart } from '../../../../../plugin';
Expand All @@ -31,6 +32,14 @@ jest.mock('react-router-dom', () => ({
const { ObservabilityAIAssistantContextualInsight } =
observabilityAIAssistantPluginMock.createStartContract();

const assertServiceStat = (description: string, stat: string) => {
const serviceStat = screen.getByTestSubject('apmServiceStat');

expect(serviceStat).toBeInTheDocument();
expect(serviceStat!.children[0]).toHaveTextContent(description);
expect(serviceStat!.children[1]).toHaveTextContent(stat);
};

describe('APMSection', () => {
const bucketSize = { intervalString: '60s', bucketSize: 60, dateFormat: 'YYYY-MM-DD HH:mm' };

Expand Down Expand Up @@ -90,7 +99,7 @@ describe('APMSection', () => {

expect(getByRole('heading')).toHaveTextContent('Services');
expect(getByText('Show service inventory')).toBeInTheDocument();
expect(getByText('Services 11')).toBeInTheDocument();
assertServiceStat('Services', '11');
expect(getByText('900.0 tpm')).toBeInTheDocument();
expect(queryAllByTestId('loading')).toEqual([]);
});
Expand All @@ -107,7 +116,7 @@ describe('APMSection', () => {

expect(getByRole('heading')).toHaveTextContent('Services');
expect(getByText('Show service inventory')).toBeInTheDocument();
expect(getByText('Services 11')).toBeInTheDocument();
assertServiceStat('Services', '11');
expect(getByText('312.00k tpm')).toBeInTheDocument();
expect(queryAllByTestId('loading')).toEqual([]);
});
Expand All @@ -117,14 +126,14 @@ describe('APMSection', () => {
status: fetcherHook.FETCH_STATUS.LOADING,
refetch: jest.fn(),
});
const { getByRole, queryAllByText, getByTestId } = render(
const { getByRole, queryAllByText, getByTestId, getAllByLabelText } = render(
<APMSection bucketSize={bucketSize} />
);

expect(getByRole('heading')).toHaveTextContent('Services');
expect(getByTestId('loading')).toBeInTheDocument();
expect(queryAllByText('Show service inventory')).toEqual([]);
expect(queryAllByText('Services 11')).toEqual([]);
expect(getAllByLabelText('Statistic is loading').length).toEqual(2);
expect(queryAllByText('312.00k tpm')).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function APMSection({ bucketSize }: Props) {
defaultMessage: 'Services',
})}
isLoading={isLoading}
data-test-subj="apmServiceStat"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ describe('RulesListTableStatusCell', () => {
});

it('should render loading indicator for new rules', async () => {
const { getByText } = render(
const { getByLabelText } = render(
<ComponentWithLocale
rule={
{
Expand All @@ -137,7 +137,7 @@ describe('RulesListTableStatusCell', () => {
/>
);

expect(getByText('Statistic is loading')).not.toBe(null);
expect(getByLabelText('Statistic is loading')).not.toBe(null);
});

it('should render rule with no last run', async () => {
Expand Down

0 comments on commit 6fd8082

Please sign in to comment.