Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
hardingjam committed Dec 3, 2024
1 parent fee7265 commit 580dc31
Show file tree
Hide file tree
Showing 4 changed files with 310 additions and 309 deletions.
164 changes: 82 additions & 82 deletions packages/ui-components/src/__tests__/OrderVaultsVolTable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,101 +8,101 @@ import { QueryClient } from '@tanstack/svelte-query';

// Mock the getOrderVaultsVolume function
vi.mock('@rainlanguage/orderbook/js_api', () => ({
getOrderVaultsVolume: vi.fn(() => Promise.resolve(mockVaultsVol)),
getOrderVaultsVolume: vi.fn(() => Promise.resolve(mockVaultsVol))
}));

const mockVaultsVol: VaultVolume[] = [
{
id: '1',
token: {
id: 'output_token',
address: 'output_token',
name: 'output_token',
symbol: 'output_token',
decimals: '0',
},
totalIn: '1',
totalOut: '2',
totalVol: '3',
netVol: '-1',
},
{
id: '2',
token: {
id: 'output_token',
address: 'output_token',
name: 'output_token',
symbol: 'output_token',
decimals: '0',
},
totalIn: '2',
totalOut: '5',
totalVol: '7',
netVol: '-3',
},
{
id: '1',
token: {
id: 'output_token',
address: 'output_token',
name: 'output_token',
symbol: 'output_token',
decimals: '0'
},
totalIn: '1',
totalOut: '2',
totalVol: '3',
netVol: '-1'
},
{
id: '2',
token: {
id: 'output_token',
address: 'output_token',
name: 'output_token',
symbol: 'output_token',
decimals: '0'
},
totalIn: '2',
totalOut: '5',
totalVol: '7',
netVol: '-3'
}
];

test('renders table with correct data', async () => {
const queryClient = new QueryClient();
const queryClient = new QueryClient();

render(OrderVaultsVolTable, {
context: new Map([['$$_queryClient', queryClient]]),
props: { id: '1', subgraphUrl: 'https://example.com' },
});
render(OrderVaultsVolTable, {
context: new Map([['$$_queryClient', queryClient]]),
props: { id: '1', subgraphUrl: 'https://example.com' }
});

await waitFor(async () => {
// get total ins
const rows = screen.getAllByTestId('total-in');
await waitFor(async () => {
// get total ins
const rows = screen.getAllByTestId('total-in');

// checking the total ins
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalIn),
Number(mockVaultsVol[i].token.decimals),
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});
// checking the total ins
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalIn),
Number(mockVaultsVol[i].token.decimals)
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});

await waitFor(async () => {
// get total outs
const rows = screen.getAllByTestId('total-out');
await waitFor(async () => {
// get total outs
const rows = screen.getAllByTestId('total-out');

// checking the total outs
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalOut),
Number(mockVaultsVol[i].token.decimals),
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});
// checking the total outs
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalOut),
Number(mockVaultsVol[i].token.decimals)
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});

await waitFor(async () => {
// get net vols
const rows = screen.getAllByTestId('net-vol');
await waitFor(async () => {
// get net vols
const rows = screen.getAllByTestId('net-vol');

// checking the net vols
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].netVol),
Number(mockVaultsVol[i].token.decimals),
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});
// checking the net vols
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].netVol),
Number(mockVaultsVol[i].token.decimals)
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});

await waitFor(async () => {
// get total vols
const rows = screen.getAllByTestId('total-vol');
await waitFor(async () => {
// get total vols
const rows = screen.getAllByTestId('total-vol');

// checking the total vols
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalVol),
Number(mockVaultsVol[i].token.decimals),
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});
// checking the total vols
for (let i = 0; i < mockVaultsVol.length; i++) {
const display = formatUnits(
BigInt(mockVaultsVol[i].totalVol),
Number(mockVaultsVol[i].token.decimals)
);
expect(rows[i]).toHaveTextContent(display.toString());
}
});
});
Loading

0 comments on commit 580dc31

Please sign in to comment.