Skip to content

Commit

Permalink
[APM]fixing custom link unit tests (#64045)
Browse files Browse the repository at this point in the history
  • Loading branch information
cauemarcondes authored Apr 22, 2020
1 parent edac666 commit aecd00f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const data = [
];

describe('CustomLink', () => {
let callApmApiSpy: Function;
let callApmApiSpy: jasmine.Spy;
beforeAll(() => {
callApmApiSpy = spyOn(apmApi, 'callApmApi').and.returnValue({});
});
Expand Down Expand Up @@ -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>
Expand All @@ -113,6 +113,7 @@ describe('CustomLink', () => {
act(() => {
fireEvent.click(getByText('Create custom link'));
});
await wait(() => expect(callApmApiSpy).toHaveBeenCalled());
expect(queryByText('Create link')).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit aecd00f

Please sign in to comment.