2023-02-07 19:06:37 +01:00
|
|
|
import { fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
|
|
|
import { renderWithProvider } from '../../../../test/lib/render-helpers';
|
2023-02-16 20:23:29 +01:00
|
|
|
import NftOptions from './nft-options';
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
describe('NFT Options Component', () => {
|
2023-02-07 19:06:37 +01:00
|
|
|
const props = {
|
|
|
|
onRemove: jest.fn(),
|
|
|
|
onViewOnOpensea: jest.fn(),
|
|
|
|
};
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
it('should expand NFT options menu`', async () => {
|
|
|
|
const { queryByTestId } = renderWithProvider(<NftOptions {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(queryByTestId('nft-item-remove')).not.toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
|
|
|
await waitFor(() => {
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(queryByTestId('nft-item-remove')).toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should expand and close menu options when clicked`', async () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(<NftOptions {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const closeOptionMenuButton = queryByTestId('close-nft-options-menu');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(closeOptionMenuButton);
|
|
|
|
|
|
|
|
expect(closeOptionMenuButton).not.toBeInTheDocument();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should click onRemove handler and close option menu', () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(<NftOptions {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const removeNftButton = queryByTestId('nft-item-remove');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
fireEvent.click(removeNftButton);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
expect(props.onRemove).toHaveBeenCalled();
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(removeNftButton).not.toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should click onViewOnOpensea handler and close option menu', () => {
|
2023-02-16 20:23:29 +01:00
|
|
|
const { queryByTestId } = renderWithProvider(<NftOptions {...props} />);
|
2023-02-07 19:06:37 +01:00
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOptionMenuButton = queryByTestId('nft-options__button');
|
|
|
|
const removeNftButton = queryByTestId('nft-item-remove');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(openOptionMenuButton);
|
|
|
|
|
2023-02-16 20:23:29 +01:00
|
|
|
const openOpenSea = queryByTestId('nft-options__view-on-opensea');
|
2023-02-07 19:06:37 +01:00
|
|
|
|
|
|
|
fireEvent.click(openOpenSea);
|
|
|
|
|
|
|
|
expect(props.onViewOnOpensea).toHaveBeenCalled();
|
2023-02-16 20:23:29 +01:00
|
|
|
expect(removeNftButton).not.toBeInTheDocument();
|
2023-02-07 19:06:37 +01:00
|
|
|
});
|
|
|
|
});
|