From a13e57e59d827b770d2a002316acba82bed090e5 Mon Sep 17 00:00:00 2001 From: David Sanchez Soler Date: Tue, 1 Jun 2021 14:16:52 +0200 Subject: [PATCH] Adds some syntax and readibility nits comming from pr comments --- .../fleet_event_filters_card.test.tsx | 18 +++++++++--------- .../components/fleet_event_filters_card.tsx | 4 +++- .../fleet_trusted_apps_card.test.tsx | 18 +++++++++--------- .../components/fleet_trusted_apps_card.tsx | 4 +++- 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.test.tsx index 676633878dcdf..55e844df2afae 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.test.tsx @@ -76,13 +76,6 @@ describe('Fleet event filters card', () => { } return component; }; - afterEach(() => { - EventFiltersHttpServiceMock.mockReset(); - }); - beforeEach(() => { - promise = Promise.resolve(summary); - addDanger = jest.fn(); - }); beforeAll(() => { useToastsMock.mockImplementation(() => { return { @@ -90,7 +83,14 @@ describe('Fleet event filters card', () => { }; }); }); - it('should renders correctly', async () => { + beforeEach(() => { + promise = Promise.resolve(summary); + addDanger = jest.fn(); + }); + afterEach(() => { + EventFiltersHttpServiceMock.mockReset(); + }); + it('should render correctly', async () => { EventFiltersHttpServiceMock.mockImplementationOnce(() => { return { getSummary: () => jest.fn(() => promise), @@ -100,7 +100,7 @@ describe('Fleet event filters card', () => { expect(component.getByText('Event Filters')).not.toBeNull(); expect(component.getByText('Manage event filters')).not.toBeNull(); }); - it('should renders an error when api call fails', async () => { + it('should render an error toast when api call fails', async () => { expect(addDanger).toBeCalledTimes(0); promise = Promise.reject(new Error('error test')); EventFiltersHttpServiceMock.mockImplementationOnce(() => { diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.tsx index d65c896a10955..40d10004788e4 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_event_filters_card.tsx @@ -43,7 +43,9 @@ export const FleetEventFiltersCard = memo( const fetchStats = async () => { try { const summary = await eventFiltersApi.getSummary(); - if (isMounted.current) setStats(summary); + if (isMounted.current) { + setStats(summary); + } } catch (error) { toasts.addDanger( i18n.translate( diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx index b646acb8e4396..22a7072caea02 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.test.tsx @@ -77,13 +77,6 @@ describe('Fleet trusted apps card', () => { return component; }; - afterEach(() => { - TrustedAppsHttpServiceMock.mockReset(); - }); - beforeEach(() => { - promise = Promise.resolve(summary); - addDanger = jest.fn(); - }); beforeAll(() => { useToastsMock.mockImplementation(() => { return { @@ -91,7 +84,14 @@ describe('Fleet trusted apps card', () => { }; }); }); - it('should renders correctly', async () => { + beforeEach(() => { + promise = Promise.resolve(summary); + addDanger = jest.fn(); + }); + afterEach(() => { + TrustedAppsHttpServiceMock.mockReset(); + }); + it('should render correctly', async () => { TrustedAppsHttpServiceMock.mockImplementationOnce(() => { return { getTrustedAppsSummary: () => jest.fn(() => promise), @@ -101,7 +101,7 @@ describe('Fleet trusted apps card', () => { expect(component.getByText('Trusted Applications')).not.toBeNull(); expect(component.getByText('Manage trusted applications')).not.toBeNull(); }); - it('should renders an error when api call fails', async () => { + it('should render an error toast when api call fails', async () => { expect(addDanger).toBeCalledTimes(0); promise = Promise.reject(new Error('error test')); TrustedAppsHttpServiceMock.mockImplementationOnce(() => { diff --git a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.tsx b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.tsx index fcbda9dbf163b..b1464d23e00fb 100644 --- a/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.tsx +++ b/x-pack/plugins/security_solution/public/management/pages/policy/view/ingest_manager_integration/endpoint_package_custom_extension/components/fleet_trusted_apps_card.tsx @@ -45,7 +45,9 @@ export const FleetTrustedAppsCard = memo(( const fetchStats = async () => { try { const response = await trustedAppsApi.getTrustedAppsSummary(); - if (isMounted) setStats(response); + if (isMounted) { + setStats(response); + } } catch (error) { toasts.addDanger( i18n.translate(