Skip to content

Commit

Permalink
Update inventory edit link
Browse files Browse the repository at this point in the history
  • Loading branch information
ciremusyoka committed Apr 4, 2024
1 parent 81d3bcd commit a0d4750
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,6 @@ function dataTransformer(bundleResponse: IBundle) {
};
}
}
if (productReference) {
tableDataByProductRef[productReference] = {
...tableDataByProductRef[productReference],
id: resource.id,
};
}
}
return Object.values(tableDataByProductRef as Record<string, TableData>);
}
Expand Down Expand Up @@ -266,7 +260,10 @@ export const InventoryView = ({ fhirBaseUrl, locationId }: InventoryViewProps) =
<span className="d-flex align-items-center">
<RbacCheck permissions={['Group.update']}>
<>
<Link to={`${baseInventoryPath}/${id}`} className="m-0 p-1">
<Link
to={`${baseInventoryPath}/${id}`}
className={`m-0 p-1 ${id === undefined ? 'disabled-link' : ''}`}
>
{t('Edit')}
</Link>
<Divider type="vertical" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ afterAll(() => {
_.debounce = actualDebounce;
});

const centralBuildingLocation = {
...centralProvince,
extension: undefined,
physicalType: {
coding: [
{
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type',
code: 'bu',
display: 'Building',
},
],
},
};

test('works correctly - jurisdiction location', async () => {
const history = createMemoryHistory();
history.push(`profile/${centralProvince.id}`);
Expand Down Expand Up @@ -173,25 +187,12 @@ test('works correctly - jurisdiction location', async () => {
});

test('works correctly - physical location', async () => {
const centralBiuldingLocation = {
...centralProvince,
extension: undefined,
physicalType: {
coding: [
{
system: 'http://terminology.hl7.org/CodeSystem/location-physical-type',
code: 'bu',
display: 'Biulding',
},
],
},
};
const history = createMemoryHistory();
history.push(`profile/${centralBiuldingLocation.id}`);
history.push(`profile/${centralBuildingLocation.id}`);

const thisProps = {
...props,
location: centralBiuldingLocation,
location: centralBuildingLocation,
};

nock(props.fhirBaseUrl)
Expand Down Expand Up @@ -230,6 +231,7 @@ test('works correctly - physical location', async () => {
// 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']);
expect(inventoryTab.querySelector('.disabled-link')).toBeNull();

// validate search works.
const childLocationSearch = inventoryTab.querySelector('[data-testid="search-form"]')!;
Expand All @@ -254,3 +256,50 @@ test('works correctly - physical location', async () => {

expect(nock.isDone()).toBeTruthy();
});

test('Disables edit button when no id', async () => {
const history = createMemoryHistory();
history.push(`profile/${centralBuildingLocation.id}`);

const thisProps = {
...props,
location: centralBuildingLocation,
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
centralInventory.entry[1].resource.id = undefined as any;

nock(props.fhirBaseUrl)
.get(`/${listResourceType}/_search`)
.query({
subject: 'd9d7aa7b-7488-48e7-bae8-d8ac5bd09334',
_include: 'List:item',
'_include:recurse': 'Group:member',
_summary: 'count',
})
.reply(200, { total: 1 })
.persist();

nock(props.fhirBaseUrl)
.get(`/${listResourceType}/_search`)
.query({
subject: 'd9d7aa7b-7488-48e7-bae8-d8ac5bd09334',
_include: 'List:item',
'_include:recurse': 'Group:member',
_count: '1',
})
.reply(200, centralInventory)
.persist();

render(
<Router history={history}>
<AppWrapper {...thisProps}></AppWrapper>
</Router>
);

await waitForElementToBeRemoved(document.querySelector('.ant-spin'));
screen.getByText(/Add Inventory/i);
const inventoryTab = document.querySelector('[data-testid="inventory-tab"]')!;
const disabledBtn = inventoryTab.querySelector('.disabled-link');
expect(disabledBtn).toBeInTheDocument();
expect(disabledBtn?.textContent).toEqual('Edit');
});

0 comments on commit a0d4750

Please sign in to comment.