Skip to content

Commit 43d3905

Browse files
[APM]fixing custom link unit tests (#64045) (#64141)
1 parent e6ce3fc commit 43d3905

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

x-pack/legacy/plugins/apm/public/components/app/Settings/CustomizeUI/CustomLink/index.test.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const data = [
3535
];
3636

3737
describe('CustomLink', () => {
38-
let callApmApiSpy: Function;
38+
let callApmApiSpy: jasmine.Spy;
3939
beforeAll(() => {
4040
callApmApiSpy = spyOn(apmApi, 'callApmApi').and.returnValue({});
4141
});
@@ -101,7 +101,7 @@ describe('CustomLink', () => {
101101
]);
102102
});
103103

104-
it('checks if create custom link button is available and working', () => {
104+
it('checks if create custom link button is available and working', async () => {
105105
const { queryByText, getByText } = render(
106106
<LicenseContext.Provider value={goldLicense}>
107107
<MockApmPluginContextWrapper>
@@ -113,6 +113,7 @@ describe('CustomLink', () => {
113113
act(() => {
114114
fireEvent.click(getByText('Create custom link'));
115115
});
116+
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
116117
expect(queryByText('Create link')).toBeInTheDocument();
117118
});
118119
});
@@ -144,8 +145,10 @@ describe('CustomLink', () => {
144145
act(() => {
145146
fireEvent.click(component.getByText('Create custom link'));
146147
});
147-
await wait(() => component.queryByText('Create link'));
148-
expect(component.queryByText('Create link')).toBeInTheDocument();
148+
await wait(() =>
149+
expect(component.queryByText('Create link')).toBeInTheDocument()
150+
);
151+
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
149152
return component;
150153
};
151154

x-pack/legacy/plugins/apm/public/components/shared/TransactionActionMenu/__test__/TransactionActionMenu.test.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import React from 'react';
8-
import { render, fireEvent, act } from '@testing-library/react';
8+
import { render, fireEvent, act, wait } from '@testing-library/react';
99
import { TransactionActionMenu } from '../TransactionActionMenu';
1010
import { Transaction } from '../../../../../../../../plugins/apm/typings/es_schemas/ui/transaction';
1111
import * as Transactions from './mockData';
@@ -143,8 +143,9 @@ describe('TransactionActionMenu component', () => {
143143
});
144144

145145
describe('Custom links', () => {
146+
let callApmApiSpy: jasmine.Spy;
146147
beforeAll(() => {
147-
spyOn(apmApi, 'callApmApi').and.returnValue({});
148+
callApmApiSpy = spyOn(apmApi, 'callApmApi').and.returnValue({});
148149
});
149150
afterAll(() => {
150151
jest.resetAllMocks();
@@ -257,7 +258,7 @@ describe('TransactionActionMenu component', () => {
257258
});
258259
expectTextsInDocument(component, ['Custom Links']);
259260
});
260-
it('opens flyout with filters prefilled', () => {
261+
it('opens flyout with filters prefilled', async () => {
261262
const license = new License({
262263
signature: 'test signature',
263264
license: {
@@ -287,6 +288,7 @@ describe('TransactionActionMenu component', () => {
287288
fireEvent.click(component.getByText('Create custom link'));
288289
});
289290
expectTextsInDocument(component, ['Create link']);
291+
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
290292
const getFilterKeyValue = (key: string) => {
291293
return {
292294
[(component.getAllByText(key)[0] as HTMLOptionElement)

0 commit comments

Comments
 (0)