chore: get rid of unnecessary - adjust unit tests

This commit is contained in:
maciek
2023-07-04 15:05:07 +02:00
parent c1e57f99a4
commit 7c99f8c19d
4 changed files with 14 additions and 17 deletions
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { VegaWalletContext } from '@vegaprotocol/wallet';
import { act, render, screen } from '@testing-library/react';
import { act, render, renderHook, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { generateMarket, generateMarketData } from '../../test-helpers';
import { DealTicket } from './deal-ticket';
@@ -29,10 +29,10 @@ function generateJsx() {
);
}
// eslint-disable-next-line react-hooks/rules-of-hooks
const useOrderStore = useCreateOrderStore();
describe('DealTicket', () => {
const { result } = renderHook(() => useCreateOrderStore());
const useOrderStore = result.current;
beforeEach(() => {
localStorage.clear();
});
@@ -141,7 +141,6 @@ describe('DealTicket', () => {
reduceOnly: true,
postOnly: false,
};
useOrderStore.setState({
orders: {
[expectedOrder.marketId]: expectedOrder,
@@ -5,14 +5,13 @@ import { useOrderForm } from './use-order-form';
jest.mock('zustand');
// eslint-disable-next-line react-hooks/rules-of-hooks
const useOrderStore = useCreateOrderStore();
describe('useOrderForm', () => {
const marketId = 'market-id';
const setup = (marketId: string) => {
return renderHook(() => useOrderForm(marketId));
};
const { result } = renderHook(() => useCreateOrderStore());
const useOrderStore = result.current;
it('updates form fields when the order changes', async () => {
const order = getDefaultOrder(marketId);
@@ -11,10 +11,8 @@ jest.mock('zustand');
describe('useCreateOrderStore', () => {
const setup = () => {
const { result: useOrderStoreRef } = renderHook(() =>
useCreateOrderStore()
);
return { result: useOrderStoreRef.current() };
const { result } = renderHook(() => useCreateOrderStore());
return renderHook(() => result.current());
};
afterEach(() => {
@@ -23,7 +21,7 @@ describe('useCreateOrderStore', () => {
it('has a empty default state', async () => {
const { result } = setup();
expect(result).toEqual({
expect(result.current).toEqual({
orders: {},
update: expect.any(Function),
});
@@ -38,10 +36,10 @@ describe('useCreateOrderStore', () => {
};
const { result } = setup();
act(() => {
result.update(marketId, { type: OrderType.TYPE_LIMIT });
result.current.update(marketId, { type: OrderType.TYPE_LIMIT });
});
// order should be stored in memory
expect(result.orders).toEqual({
expect(result.current.orders).toEqual({
[marketId]: expectedOrder,
});
// order SHOULD also be in localStorage
@@ -64,10 +62,10 @@ describe('useCreateOrderStore', () => {
};
const { result } = setup();
act(() => {
result.update(marketId, { type: OrderType.TYPE_LIMIT }, false);
result.current.update(marketId, { type: OrderType.TYPE_LIMIT }, false);
});
// order should be stored in memory
expect(result.orders).toEqual({
expect(result.current.orders).toEqual({
[marketId]: expectedOrder,
});
// order should NOT be in localStorage
@@ -84,6 +84,7 @@ const getOrderStore = () => {
};
export const useCreateOrderStore = () => {
// console.log('getOrderStore()', getOrderStore())
const useOrderStoreRef = useRef(getOrderStore());
return useOrderStoreRef.current;
};