Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature. Add TDropHolder test code #52

Merged
merged 2 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/components/data-container/drop-holder/TDropHolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ const TDropHolder = forwardRef((props: TDropHolderProps, ref: ForwardedRef<TDrop
</div>
) : (
<div className={'t-drop-holder__items t-drop-holder__items--custom'} style={itemsStyle}>
{
props.customItem
}
{props.customItem}
</div>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,13 @@ describe('TDropHolder', () => {
expect(root).not.toHaveClass('t-drop-holder--open');

// Act
await act(async () => {
await user.click(root);
});
await act(async () => { await user.click(root); });

// Assert
expect(root).toHaveClass('t-drop-holder--open');

// Act
await act(async () => {
await user.click(root);
});
await act(async () => { await user.click(root); });

// Assert
expect(root).not.toHaveClass('t-drop-holder--open');
Expand All @@ -131,17 +127,13 @@ describe('TDropHolder', () => {
document.body.appendChild(outsideElement);

// Act
await act(async () => {
await user.click(root);
});
await act(async () => { await user.click(root); });

// Assert
expect(root).toHaveClass('t-drop-holder--open');

// Act
await act(async () => {
await user.click(outsideElement);
});
await act(async () => { await user.click(outsideElement); });

// Assert
expect(root).not.toHaveClass('t-drop-holder--open');
Expand All @@ -155,9 +147,7 @@ describe('TDropHolder', () => {
const root = screen.getByTestId('drop-holder-root');

// Act
await act(async () => {
await user.click(root);
});
await act(async () => { await user.click(root); });

// Assert
baseProps.items.forEach((item) => {
Expand All @@ -173,7 +163,6 @@ describe('TDropHolder', () => {
render(<TDropHolder {...baseProps} >Test DropHolder</TDropHolder>);
const root = screen.getByTestId('drop-holder-root');


// Act
// eslint-disable-next-line no-restricted-syntax
for (const item of baseProps.items) {
Expand All @@ -186,14 +175,31 @@ describe('TDropHolder', () => {
const itemElement = screen.getByText(item.text);

// eslint-disable-next-line no-await-in-loop
await act(async () => {
await userEvent.click(itemElement);
});
await act(async () => { await userEvent.click(itemElement); });
}

// Assert
expect(mockOnClickItem).toHaveBeenCalledTimes(baseProps.items.length);
});

it('When user clicks and opens TDropHolder, custom item elements are displayed', async () => {

// Arrange
const user = userEvent.setup();
const customTestId = 'test-custom-element';
const CustomElement = () => (<div data-testid={customTestId}>👻</div>);

render(<TDropHolder alignment={'top-center'} customItem={<CustomElement/>}>Test DropHolder</TDropHolder>);
const root = screen.getByTestId('drop-holder-root');

// Act
await act(async () => { await user.click(root); });

// Assert
const customItemRoot = screen.getByTestId(customTestId);
expect(customItemRoot).toBeInTheDocument();

});
});

});
Loading