fix: hide close button if openVolume is zero (#2768)

This commit is contained in:
Bartłomiej Głownia 2023-01-27 19:44:20 +01:00 committed by GitHub
parent 1e0e1c7859
commit b1280c8285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 8 deletions

View File

@ -172,3 +172,33 @@ it('displays realised and unrealised PNL', async () => {
expect(cells[9].textContent).toEqual('1.23');
expect(cells[10].textContent).toEqual('4.56');
});
it('displays close button', async () => {
await act(async () => {
render(
<PositionsTable
rowData={singleRowData}
onClose={() => {
return;
}}
/>
);
});
const cells = screen.getAllByRole('gridcell');
expect(cells[12].textContent).toEqual('Close');
});
it('do not display close button if openVolume is zero', async () => {
await act(async () => {
render(
<PositionsTable
rowData={[{ ...singleRow, openVolume: '0' }]}
onClose={() => {
return;
}}
/>
);
});
const cells = screen.getAllByRole('gridcell');
expect(cells[12].textContent).toEqual('');
});

View File

@ -381,14 +381,16 @@ export const PositionsTable = forwardRef<AgGridReact, Props>(
{onClose ? (
<AgGridColumn
type="rightAligned"
cellRenderer={({ data }: VegaICellRendererParams<Position>) => (
<ButtonLink
data-testid="close-position"
onClick={() => data && onClose(data)}
>
{t('Close')}
</ButtonLink>
)}
cellRenderer={({ data }: VegaICellRendererParams<Position>) =>
data?.openVolume && data?.openVolume !== '0' ? (
<ButtonLink
data-testid="close-position"
onClick={() => data && onClose(data)}
>
{t('Close')}
</ButtonLink>
) : null
}
/>
) : null}
</AgGrid>