|
/** |
|
* @jest-environment jsdom |
|
*/ |
|
|
|
import { ApolloProvider } from '@apollo/client' |
|
import { RenderResult } from '@testing-library/react' |
|
import { act } from '@testing-library/react' |
|
import { render } from '@testing-library/react' |
|
import { screen } from '@testing-library/react' |
|
import { fireEvent } from '@testing-library/react' |
|
|
|
import React from 'react' |
|
import { IntlProvider } from 'react-intl' |
|
|
|
import { ExchangeCurrenciesProvider } from '@stores/exchange-currencies' |
|
import { OperationStatus } from '@stores/operation-status' |
|
import { OperationStatusProvider } from '@stores/operation-status' |
|
import { ThemeProvider } from '@ui/theme' |
|
import { getClient } from '@globals/data' |
|
|
|
import { SwapDetailsButton } from '../details-button.component' |
|
|
|
type CustomRender = (element: React.ReactNode | React.ReactNode[]) => RenderResult |
|
|
|
global.ResizeObserver = jest.fn().mockImplementation(() => ({ |
|
observe: jest.fn(), |
|
unobserve: jest.fn(), |
|
disconnect: jest.fn(), |
|
})) |
|
|
|
const customRender: CustomRender = (element) => { |
|
const client = getClient() |
|
|
|
return render( |
|
<ApolloProvider client={client}> |
|
{/* eslint-disable-next-line @typescript-eslint/no-empty-function */} |
|
<IntlProvider locale='ru' onError={() => {}}> |
|
<ThemeProvider> |
|
<ExchangeCurrenciesProvider>{element}</ExchangeCurrenciesProvider> |
|
</ThemeProvider> |
|
</IntlProvider> |
|
</ApolloProvider> |
|
) |
|
} |
|
|
|
/** |
|
* @jest-environment jsdom |
|
*/ |
|
|
|
describe('Swap operation button fragment', () => { |
|
const hiddenDetailsButtonStatuses: OperationStatus[] = [ |
|
'disabled', |
|
'initial', |
|
'approve', |
|
'loading-wallet', |
|
'approve', |
|
] |
|
|
|
hiddenDetailsButtonStatuses.forEach((status) => { |
|
it(`should not be rendered if status ${status}`, () => { |
|
customRender( |
|
<OperationStatusProvider state={{ status }}> |
|
<SwapDetailsButton /> |
|
</OperationStatusProvider> |
|
) |
|
|
|
const button = screen.queryByText('details_button.details') |
|
|
|
expect(!!button).toBeFalsy() |
|
}) |
|
}) |
|
|
|
it('should be rendered if status confirming transaction', () => { |
|
customRender( |
|
<OperationStatusProvider state={{ status: 'confirming-transaction' }}> |
|
<SwapDetailsButton /> |
|
</OperationStatusProvider> |
|
) |
|
|
|
const button = screen.getByText('details_button.details') |
|
|
|
expect(!!button).toBeTruthy() |
|
}) |
|
|
|
it('should be expanded on click with loading status', () => { |
|
customRender( |
|
<OperationStatusProvider state={{ status: 'confirming-transaction' }}> |
|
<SwapDetailsButton /> |
|
</OperationStatusProvider> |
|
) |
|
|
|
const button = screen.getByText('details_button.details') |
|
act(() => fireEvent.click(button!)) |
|
|
|
const loadingStatus = screen.getByText('details_button.confirming_transaction') |
|
|
|
expect(!!loadingStatus).toBeTruthy() |
|
}) |
|
|
|
it('should be expanded on click with status success', () => { |
|
customRender( |
|
<OperationStatusProvider state={{ status: 'done' }}> |
|
<SwapDetailsButton /> |
|
</OperationStatusProvider> |
|
) |
|
|
|
const button = screen.getByText('details_button.details') |
|
act(() => fireEvent.click(button!)) |
|
|
|
const successStatus = screen.getByText('details_button.success') |
|
|
|
expect(!!successStatus).toBeTruthy() |
|
}) |
|
}) |