-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fall back to sorting by transactions per minute if the health column is not available. Update the test for the component by moving it, removing snapshots, converting to React Testing Library, converting to TypeScript, and adding new cases for this sorting logic. Fixes #79827.
- Loading branch information
Showing
5 changed files
with
127 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 0 additions & 80 deletions
80
x-pack/plugins/apm/public/components/app/ServiceOverview/ServiceList/__test__/List.test.js
This file was deleted.
Oops, something went wrong.
153 changes: 0 additions & 153 deletions
153
...ublic/components/app/ServiceOverview/ServiceList/__test__/__snapshots__/List.test.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
x-pack/plugins/apm/public/components/app/ServiceOverview/ServiceList/service_list.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { ReactNode } from 'react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { ServiceHealthStatus } from '../../../../../common/service_health_status'; | ||
// eslint-disable-next-line @kbn/eslint/no-restricted-paths | ||
import { ServiceListAPIResponse } from '../../../../../server/lib/services/get_services'; | ||
import { MockApmPluginContextWrapper } from '../../../../context/ApmPluginContext/MockApmPluginContext'; | ||
import { mockMoment, renderWithTheme } from '../../../../utils/testHelpers'; | ||
import { ServiceList, SERVICE_COLUMNS } from './'; | ||
import props from './__fixtures__/props.json'; | ||
|
||
function Wrapper({ children }: { children?: ReactNode }) { | ||
return ( | ||
<MockApmPluginContextWrapper> | ||
<MemoryRouter>{children}</MemoryRouter> | ||
</MockApmPluginContextWrapper> | ||
); | ||
} | ||
|
||
describe('ServiceList', () => { | ||
beforeAll(() => { | ||
mockMoment(); | ||
}); | ||
|
||
it('renders empty state', () => { | ||
expect(() => | ||
renderWithTheme(<ServiceList items={[]} />, { wrapper: Wrapper }) | ||
).not.toThrowError(); | ||
}); | ||
|
||
it('renders with data', () => { | ||
expect(() => | ||
// Types of property 'avgResponseTime' are incompatible. | ||
// Type 'null' is not assignable to type '{ value: number | null; timeseries: { x: number; y: number | null; }[]; } | undefined'.ts(2322) | ||
renderWithTheme( | ||
<ServiceList items={props.items as ServiceListAPIResponse['items']} />, | ||
{ wrapper: Wrapper } | ||
) | ||
).not.toThrowError(); | ||
}); | ||
|
||
it('renders columns correctly', () => { | ||
const service: any = { | ||
serviceName: 'opbeans-python', | ||
agentName: 'python', | ||
transactionsPerMinute: { | ||
value: 86.93333333333334, | ||
timeseries: [], | ||
}, | ||
errorsPerMinute: { | ||
value: 12.6, | ||
timeseries: [], | ||
}, | ||
avgResponseTime: { | ||
value: 91535.42944785276, | ||
timeseries: [], | ||
}, | ||
environments: ['test'], | ||
}; | ||
const renderedColumns = SERVICE_COLUMNS.map((c) => | ||
c.render!(service[c.field!], service) | ||
); | ||
|
||
expect(renderedColumns[0]).toMatchInlineSnapshot(` | ||
<HealthBadge | ||
healthStatus="unknown" | ||
/> | ||
`); | ||
}); | ||
|
||
describe('without ML data', () => { | ||
it('does not render the health column', () => { | ||
const { queryByText } = renderWithTheme( | ||
<ServiceList items={props.items as ServiceListAPIResponse['items']} />, | ||
{ | ||
wrapper: Wrapper, | ||
} | ||
); | ||
const healthHeading = queryByText('Health'); | ||
|
||
expect(healthHeading).toBeNull(); | ||
}); | ||
|
||
it('sorts by transactions per minute', async () => { | ||
const { findByTitle } = renderWithTheme( | ||
<ServiceList items={props.items as ServiceListAPIResponse['items']} />, | ||
{ | ||
wrapper: Wrapper, | ||
} | ||
); | ||
|
||
expect( | ||
await findByTitle('Trans. per minute; Sorted in descending order') | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
describe('with ML data', () => { | ||
it('renders the health column', async () => { | ||
const { findByTitle } = renderWithTheme( | ||
<ServiceList | ||
items={(props.items as ServiceListAPIResponse['items']).map( | ||
(item) => ({ | ||
...item, | ||
healthStatus: ServiceHealthStatus.warning, | ||
}) | ||
)} | ||
/>, | ||
{ wrapper: Wrapper } | ||
); | ||
|
||
expect( | ||
await findByTitle('Health; Sorted in descending order') | ||
).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |