[APM]fixing custom link unit tests (#64045)

This commit is contained in:
Cauê Marcondes 2020-04-22 06:34:40 +01:00 committed by GitHub
parent edac6669f7
commit aecd00f3d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -35,7 +35,7 @@ const data = [
];
describe('CustomLink', () => {
let callApmApiSpy: Function;
let callApmApiSpy: jasmine.Spy;
beforeAll(() => {
callApmApiSpy = spyOn(apmApi, 'callApmApi').and.returnValue({});
});
@ -101,7 +101,7 @@ describe('CustomLink', () => {
]);
});
it('checks if create custom link button is available and working', () => {
it('checks if create custom link button is available and working', async () => {
const { queryByText, getByText } = render(
<LicenseContext.Provider value={goldLicense}>
<MockApmPluginContextWrapper>
@ -113,6 +113,7 @@ describe('CustomLink', () => {
act(() => {
fireEvent.click(getByText('Create custom link'));
});
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
expect(queryByText('Create link')).toBeInTheDocument();
});
});
@ -144,8 +145,10 @@ describe('CustomLink', () => {
act(() => {
fireEvent.click(component.getByText('Create custom link'));
});
await wait(() => component.queryByText('Create link'));
expect(component.queryByText('Create link')).toBeInTheDocument();
await wait(() =>
expect(component.queryByText('Create link')).toBeInTheDocument()
);
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
return component;
};

View file

@ -5,7 +5,7 @@
*/
import React from 'react';
import { render, fireEvent, act } from '@testing-library/react';
import { render, fireEvent, act, wait } from '@testing-library/react';
import { TransactionActionMenu } from '../TransactionActionMenu';
import { Transaction } from '../../../../../../../../plugins/apm/typings/es_schemas/ui/transaction';
import * as Transactions from './mockData';
@ -143,8 +143,9 @@ describe('TransactionActionMenu component', () => {
});
describe('Custom links', () => {
let callApmApiSpy: jasmine.Spy;
beforeAll(() => {
spyOn(apmApi, 'callApmApi').and.returnValue({});
callApmApiSpy = spyOn(apmApi, 'callApmApi').and.returnValue({});
});
afterAll(() => {
jest.resetAllMocks();
@ -257,7 +258,7 @@ describe('TransactionActionMenu component', () => {
});
expectTextsInDocument(component, ['Custom Links']);
});
it('opens flyout with filters prefilled', () => {
it('opens flyout with filters prefilled', async () => {
const license = new License({
signature: 'test signature',
license: {
@ -287,6 +288,7 @@ describe('TransactionActionMenu component', () => {
fireEvent.click(component.getByText('Create custom link'));
});
expectTextsInDocument(component, ['Create link']);
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
const getFilterKeyValue = (key: string) => {
return {
[(component.getAllByText(key)[0] as HTMLOptionElement)