From 8488612151333d608945d85ffee9f90f22134905 Mon Sep 17 00:00:00 2001 From: Peter Muriuki Date: Mon, 19 Aug 2024 14:00:14 +0300 Subject: [PATCH] Fix lint issues --- .../ViewDetails/DetailsTabs/Inventory.tsx | 4 +- .../DetailsTabs/tests/detailsTabs.test.tsx | 15 +++--- .../AsyncSelect/BaseAsyncSelect/index.tsx | 14 +++-- .../AsyncSelect/ValueSetAsyncSelect/index.tsx | 54 ++++++++++--------- .../ValueSetAsyncSelect/tests/index.test.tsx | 20 ++----- 5 files changed, 53 insertions(+), 54 deletions(-) diff --git a/packages/fhir-location-management/src/components/ViewDetails/DetailsTabs/Inventory.tsx b/packages/fhir-location-management/src/components/ViewDetails/DetailsTabs/Inventory.tsx index beb24ecca..993647a35 100644 --- a/packages/fhir-location-management/src/components/ViewDetails/DetailsTabs/Inventory.tsx +++ b/packages/fhir-location-management/src/components/ViewDetails/DetailsTabs/Inventory.tsx @@ -322,10 +322,10 @@ export const InventoryView = ({ fhirBaseUrl, locationId }: InventoryViewProps) =
- + - {t("Accountability status:")} + {t('Accountability status:')} { // check records shown in table. let tableData = [...inventoryTab.querySelectorAll('table tbody tr')].map((tr) => tr.textContent); - expect(tableData).toEqual(["Bed nets2/1/20242/1/2024HealthEdit", 'HealthEdit']); + expect(tableData).toEqual(['Bed nets2/1/20242/1/2024HealthEdit', 'HealthEdit']); // switch to inactive tab const inactiveRadio = screen.getByRole('radio', { name: /Inactive/i }); @@ -257,7 +257,7 @@ test('works correctly - physical location', async () => { // recheck data tableData = [...inventoryTab.querySelectorAll('table tbody tr')].map((tr) => tr.textContent); - expect(tableData).toEqual(["No data"]); + expect(tableData).toEqual(['No data']); checkedRadio = document.querySelector('.ant-radio-button-wrapper-checked'); expect(checkedRadio?.textContent).toEqual('Inactive'); @@ -265,11 +265,12 @@ test('works correctly - physical location', async () => { const activeRadio = screen.getByRole('radio', { name: /^active/i }); fireEvent.click(activeRadio); - const links = [...inventoryTab.querySelectorAll('a')].map(link => link.href); - expect(links).toEqual( - ["http://localhost/location/inventory/d9d7aa7b-7488-48e7-bae8-d8ac5bd09334/1277894c-91b5-49f6-a0ac-cdf3f72cc3d5", "http://localhost/location/inventory/d9d7aa7b-7488-48e7-bae8-d8ac5bd09334/e44e26d0-1f7a-41d6-aa57-99c5712ddd66", ""] - - ); + const links = [...inventoryTab.querySelectorAll('a')].map((link) => link.href); + expect(links).toEqual([ + 'http://localhost/location/inventory/d9d7aa7b-7488-48e7-bae8-d8ac5bd09334/1277894c-91b5-49f6-a0ac-cdf3f72cc3d5', + 'http://localhost/location/inventory/d9d7aa7b-7488-48e7-bae8-d8ac5bd09334/e44e26d0-1f7a-41d6-aa57-99c5712ddd66', + '', + ]); // validate search works. const childLocationSearch = inventoryTab.querySelector('[data-testid="search-form"]')!; diff --git a/packages/react-utils/src/components/AsyncSelect/BaseAsyncSelect/index.tsx b/packages/react-utils/src/components/AsyncSelect/BaseAsyncSelect/index.tsx index 064916946..fd6e2d5d4 100644 --- a/packages/react-utils/src/components/AsyncSelect/BaseAsyncSelect/index.tsx +++ b/packages/react-utils/src/components/AsyncSelect/BaseAsyncSelect/index.tsx @@ -30,7 +30,7 @@ function BaseAsyncSelect( const { data, isLoading, error } = useQuery(useQueryParams); const options = useMemo(() => (data ? optionsGetter(data) : undefined), [data, optionsGetter]); - const selectDropDownRender = dropDownFactory(t, data, error) + const selectDropDownRender = dropDownFactory(t, data, error); const singleSelectProps = { dropdownRender: selectDropDownRender, options, @@ -42,16 +42,22 @@ function BaseAsyncSelect( return ; @@ -121,22 +122,27 @@ export function getValueSetSelectOptions(data: IValueSet) { return options; } -/** valueset options are a json stringified representation of the codeable concept, - * the option.value thus can include the `display` property which we should not use when +/** + * valueset options are a json stringified representation of the codeable concept, + * the option.value thus can include the `display` property which we should not use when * testing for equality between a codeableConcept value and the options. + * * @param optionsByCodeAndSystem - lookup of options by the important parts, code and system * @param value - a provided or selected value. */ -export const useSanitizedValueSelectValue = (optionsByCodeAndSystem: Record, value?: RawValueType | null) => { +export const useSanitizedValueSelectValue = ( + optionsByCodeAndSystem: Record, + value?: RawValueType | null +) => { return useMemo(() => { try { if (value) { - const valueOb = JSON.parse((value ?? "") as string) - const key = `${valueOb.code}-${valueOb.system}` - return optionsByCodeAndSystem?.[key]?.value ?? value + const valueOb = JSON.parse((value) as string); + const key = `${valueOb.code}-${valueOb.system}`; + return optionsByCodeAndSystem[key].value ?? value; } } catch (_) { - return value + return value; } - }, [optionsByCodeAndSystem, value]) -} \ No newline at end of file + }, [optionsByCodeAndSystem, value]); +}; diff --git a/packages/react-utils/src/components/AsyncSelect/ValueSetAsyncSelect/tests/index.test.tsx b/packages/react-utils/src/components/AsyncSelect/ValueSetAsyncSelect/tests/index.test.tsx index b1577589a..036301bee 100644 --- a/packages/react-utils/src/components/AsyncSelect/ValueSetAsyncSelect/tests/index.test.tsx +++ b/packages/react-utils/src/components/AsyncSelect/ValueSetAsyncSelect/tests/index.test.tsx @@ -3,7 +3,7 @@ import React from 'react'; import { store } from '@opensrp/store'; import { authenticateUser } from '@onaio/session-reducer'; import nock from 'nock'; -import { cleanup, fireEvent, render, waitFor, screen, prettyDOM } from '@testing-library/react'; +import { cleanup, fireEvent, render, waitFor, screen } from '@testing-library/react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { ValueSetAsyncSelect, valueSetResourceType } from '..'; import { eusmServicePoint } from './fixtures'; @@ -204,14 +204,7 @@ test('display is of no consequence when matching value to option', async () => { }); let activeValue = document.querySelector('.ant-select-selection-item'); - expect(activeValue).toMatchInlineSnapshot(` - - NatCom Switzerland - - `); + expect(activeValue?.textContent).toEqual("NatCom Switzerland"); // When display is left out placeboValue = JSON.stringify({ @@ -229,14 +222,7 @@ test('display is of no consequence when matching value to option', async () => { }); activeValue = document.querySelector('.ant-select-selection-item'); - expect(activeValue).toMatchInlineSnapshot(` - - NatCom Switzerland - - `); + expect(activeValue?.textContent).toEqual("NatCom Switzerland"); expect(nock.isDone()).toBeTruthy(); });