Skip to content

Commit

Permalink
trivial. Add TDropHolder test code
Browse files Browse the repository at this point in the history
  • Loading branch information
kkusaeng committed Feb 9, 2024
1 parent 182e4e7 commit 7bacde9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
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();

});
});

});

0 comments on commit 7bacde9

Please sign in to comment.