Skip to content

Commit

Permalink
test: updated liquidated vaults tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frazarshad committed Sep 10, 2024
1 parent 11f2f04 commit 2b4d5aa
Show file tree
Hide file tree
Showing 3 changed files with 17,995 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/Liquidated.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import useSWR from 'swr';
import { render } from '@testing-library/react';
import { Liquidated } from '@/pages/Liquidated';
import {
LIQUIDATED_VAULTS_NEXT_PAGES_QUERY,
LIQUIDATIONS_DASHBOARD,
VAULT_STATE_DAILIES_QUERY,
} from '@/queries';
import { graphDataMock, dashboardDataMock } from './__mocks__/Liquidated';
import { graphDataMock, dashboardDataMock, nextPagesMock, liquidatedVaults100Mock } from './__mocks__/Liquidated';

jest.mock('swr', () => ({
default: jest.fn(),
Expand All @@ -33,9 +34,11 @@ jest.mock('recharts', () => {
describe('Liquidation Dashboard Snapshot tests', () => {
it('should match snapshot when data is loaded', async () => {
(useSWR as any).mockImplementation((query: string) => {
const pageCount = Math.ceil(dashboardDataMock.data.data.vaultLiquidations.totalCount / 100) - 1;
const mockData =
{
[LIQUIDATIONS_DASHBOARD]: dashboardDataMock,
[LIQUIDATED_VAULTS_NEXT_PAGES_QUERY(pageCount)]: nextPagesMock,
[VAULT_STATE_DAILIES_QUERY]: graphDataMock,
}[query];
return { data: mockData, error: null, isLoading: false };
Expand All @@ -51,4 +54,45 @@ describe('Liquidation Dashboard Snapshot tests', () => {
const { container } = render(<Liquidated />);
expect(container).toMatchSnapshot();
});

it('should match snapshot when liquidatedVaults are less than 100', async () => {
(useSWR as any).mockImplementation((query: string) => {
const modifiedDashboardDataMock: typeof dashboardDataMock = JSON.parse(JSON.stringify(dashboardDataMock));
modifiedDashboardDataMock.data.data.vaultLiquidations.nodes = modifiedDashboardDataMock.data.data.vaultLiquidations.nodes.slice(0, 99);
expect(modifiedDashboardDataMock.data.data.vaultLiquidations.nodes.length).toBeLessThanOrEqual(100);

const pageCount = Math.ceil(modifiedDashboardDataMock.data.data.vaultLiquidations.totalCount / 100) - 1;
expect(pageCount).toBe(0);
const mockData =
{
[LIQUIDATIONS_DASHBOARD]: dashboardDataMock,
[LIQUIDATED_VAULTS_NEXT_PAGES_QUERY(pageCount)]: nextPagesMock,
[VAULT_STATE_DAILIES_QUERY]: graphDataMock,
}[query];
return { data: mockData, error: null, isLoading: false };
});

const { container } = render(<Liquidated />);
expect(container).toMatchSnapshot();
});
it('should match snapshot when liquidatedVaults are greater than 100', async () => {
(useSWR as any).mockImplementation((query: string) => {
const modifiedDashboardDataMock: typeof dashboardDataMock = JSON.parse(JSON.stringify(dashboardDataMock));
modifiedDashboardDataMock.data.data.vaultLiquidations = liquidatedVaults100Mock;
expect(modifiedDashboardDataMock.data.data.vaultLiquidations.nodes.length).toEqual(100);

const pageCount = Math.ceil(modifiedDashboardDataMock.data.data.vaultLiquidations.totalCount / 100) - 1;
expect(pageCount).toBeGreaterThan(0);
const mockData =
{
[LIQUIDATIONS_DASHBOARD]: dashboardDataMock,
[LIQUIDATED_VAULTS_NEXT_PAGES_QUERY(pageCount)]: nextPagesMock,
[VAULT_STATE_DAILIES_QUERY]: graphDataMock,
}[query];
return { data: mockData, error: null, isLoading: false };
});

const { container } = render(<Liquidated />);
expect(container).toMatchSnapshot();
});
});
Loading

0 comments on commit 2b4d5aa

Please sign in to comment.