diff --git a/packages/components/src/components/Popover/Popover.test.tsx b/packages/components/src/components/Popover/Popover.test.tsx index 3da2c874e..c0650323a 100644 --- a/packages/components/src/components/Popover/Popover.test.tsx +++ b/packages/components/src/components/Popover/Popover.test.tsx @@ -1,8 +1,8 @@ import { createRef } from 'react'; -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import { userEvent } from '@testing-library/user-event'; -import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { Button } from '../Button'; @@ -13,6 +13,10 @@ describe('Popover', () => { vi.clearAllMocks(); }); + afterEach(() => { + vi.restoreAllMocks(); + }); + const onOpenChange = vi.fn(); const baseProps = { 'data-testid': 'root', onOpenChange }; @@ -64,6 +68,98 @@ describe('Popover', () => { expect(getRoot()).not.toHaveAttribute('data-arrow'); }); + it('should align the arrow for a compound placement', async () => { + vi.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockImplementation( + function (this: HTMLElement) { + if (this.dataset.testid === 'root') { + return { + bottom: 64, + height: 64, + left: 0, + right: 200, + top: 0, + width: 200, + x: 0, + y: 0, + } as DOMRect; + } + + if (this.tagName === 'BUTTON') { + return { + bottom: 32, + height: 32, + left: 0, + right: 100, + top: 0, + width: 100, + x: 0, + y: 0, + } as DOMRect; + } + + return { + bottom: 0, + height: 0, + left: 0, + right: 0, + top: 0, + width: 0, + x: 0, + y: 0, + } as DOMRect; + } + ); + + const { rerender } = render( +