diff --git a/public/app/features/datasources/NewDataSourcePage.tsx b/public/app/features/datasources/NewDataSourcePage.tsx index dbf79c63186..fc56529ddba 100644 --- a/public/app/features/datasources/NewDataSourcePage.tsx +++ b/public/app/features/datasources/NewDataSourcePage.tsx @@ -152,7 +152,7 @@ const DataSourceTypeCard: FC = props => { ) } - className={isPhantom && 'add-data-source-item--phantom'} + className={isPhantom ? 'add-data-source-item--phantom' : ''} onClick={onClick} aria-label={selectors.pages.AddDataSource.dataSourcePlugins(plugin.name)} /> diff --git a/public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx b/public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx index 3e8f6299cf6..8837d65cda4 100644 --- a/public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx +++ b/public/app/plugins/datasource/elasticsearch/configuration/DataLinks.test.tsx @@ -3,6 +3,7 @@ import { mount } from 'enzyme'; import { DataLinks } from './DataLinks'; import { Button } from '@grafana/ui'; import { DataLink } from './DataLink'; +import { act } from 'react-dom/test-utils'; describe('DataLinks', () => { let originalGetSelection: typeof window.getSelection; @@ -15,31 +16,43 @@ describe('DataLinks', () => { window.getSelection = originalGetSelection; }); - it('renders correctly when no fields', () => { - const wrapper = mount( {}} />); + it('renders correctly when no fields', async () => { + let wrapper: any; + await act(async () => { + wrapper = await mount( {}} />); + }); expect(wrapper.find(Button).length).toBe(1); expect(wrapper.find(Button).contains('Add')).toBeTruthy(); expect(wrapper.find(DataLink).length).toBe(0); }); - it('renders correctly when there are fields', () => { - const wrapper = mount( {}} />); + it('renders correctly when there are fields', async () => { + let wrapper: any; + await act(async () => { + wrapper = await mount( {}} />); + }); - expect(wrapper.find(Button).filterWhere(button => button.contains('Add')).length).toBe(1); + expect(wrapper.find(Button).filterWhere((button: any) => button.contains('Add')).length).toBe(1); expect(wrapper.find(DataLink).length).toBe(2); }); - it('adds new field', () => { + it('adds new field', async () => { const onChangeMock = jest.fn(); - const wrapper = mount(); - const addButton = wrapper.find(Button).filterWhere(button => button.contains('Add')); + let wrapper: any; + await act(async () => { + wrapper = await mount(); + }); + const addButton = wrapper.find(Button).filterWhere((button: any) => button.contains('Add')); addButton.simulate('click'); expect(onChangeMock.mock.calls[0][0].length).toBe(1); }); - it('removes field', () => { + it('removes field', async () => { const onChangeMock = jest.fn(); - const wrapper = mount(); + let wrapper: any; + await act(async () => { + wrapper = await mount(); + }); const removeButton = wrapper .find(DataLink) .at(0) diff --git a/public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx b/public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx index 29c30d39473..02c4e418f4a 100644 --- a/public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx +++ b/public/app/plugins/datasource/loki/configuration/DerivedFields.test.tsx @@ -3,6 +3,7 @@ import { mount } from 'enzyme'; import { DerivedFields } from './DerivedFields'; import { Button } from '@grafana/ui'; import { DerivedField } from './DerivedField'; +import { act } from 'react-dom/test-utils'; describe('DerivedFields', () => { let originalGetSelection: typeof window.getSelection; @@ -15,32 +16,46 @@ describe('DerivedFields', () => { window.getSelection = originalGetSelection; }); - it('renders correctly when no fields', () => { - const wrapper = mount( {}} />); + it('renders correctly when no fields', async () => { + let wrapper: any; + await act(async () => { + wrapper = await mount( {}} />); + }); expect(wrapper.find(Button).length).toBe(1); expect(wrapper.find(Button).contains('Add')).toBeTruthy(); expect(wrapper.find(DerivedField).length).toBe(0); }); - it('renders correctly when there are fields', () => { - const wrapper = mount( {}} />); + it('renders correctly when there are fields', async () => { + let wrapper: any; + await act(async () => { + wrapper = await mount( {}} />); + }); - expect(wrapper.find(Button).filterWhere(button => button.contains('Add')).length).toBe(1); - expect(wrapper.find(Button).filterWhere(button => button.contains('Show example log message')).length).toBe(1); + expect(wrapper.find(Button).filterWhere((button: any) => button.contains('Add')).length).toBe(1); + expect(wrapper.find(Button).filterWhere((button: any) => button.contains('Show example log message')).length).toBe( + 1 + ); expect(wrapper.find(DerivedField).length).toBe(2); }); - it('adds new field', () => { + it('adds new field', async () => { const onChangeMock = jest.fn(); - const wrapper = mount(); - const addButton = wrapper.find(Button).filterWhere(button => button.contains('Add')); + let wrapper: any; + await act(async () => { + wrapper = await mount(); + }); + const addButton = wrapper.find(Button).filterWhere((button: any) => button.contains('Add')); addButton.simulate('click'); expect(onChangeMock.mock.calls[0][0].length).toBe(1); }); - it('removes field', () => { + it('removes field', async () => { const onChangeMock = jest.fn(); - const wrapper = mount(); + let wrapper: any; + await act(async () => { + wrapper = await mount(); + }); const removeButton = wrapper .find(DerivedField) .at(0)