-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FloatingArrow): reexport (#7977)
h2. Описание Для возможности пользователям создавать свои всплывающие окна. h2. Release notes h2. Новые компоненты - Добавлен экспорт `FloatingArrow`, использующийся компонентами `Popover`, `Tooltip`, `Popper`
- Loading branch information
Showing
5 changed files
with
117 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
packages/vkui/src/components/FloatingArrow/FloatingArrow.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { render } from '@testing-library/react'; | ||
import type { Placement } from '../../lib/floating'; | ||
import { baselineComponent } from '../../testing/utils'; | ||
import { FloatingArrow, placementClassNames } from './FloatingArrow'; | ||
|
||
const PLACEMENT = ['top', 'right', 'bottom', 'left'] as const; | ||
const PLACEMENT_WITH_SIDE = PLACEMENT.reduce<Placement[]>((acc, placement) => { | ||
acc.push(placement, `${placement}-start`, `${placement}-end`); | ||
return acc; | ||
}, []); | ||
|
||
describe(FloatingArrow, () => { | ||
baselineComponent(FloatingArrow); | ||
|
||
test('props to icon', () => { | ||
const result = render( | ||
<FloatingArrow data-testid="host" iconClassName="icon" iconStyle={{ display: 'none' }} />, | ||
); | ||
|
||
const icon = result.getByTestId('host').querySelector('.icon'); | ||
expect(icon).toBeInTheDocument(); | ||
expect(icon).toHaveStyle({ display: 'none' }); | ||
}); | ||
|
||
test.each(PLACEMENT_WITH_SIDE)('arrow position for %s placement', (placement) => { | ||
const result = render(<FloatingArrow data-testid="host" placement={placement} />); | ||
|
||
if (placement.startsWith('top')) { | ||
expect(result.getByTestId('host')).toHaveClass(placementClassNames.bottom); | ||
} else if (placement.startsWith('right')) { | ||
expect(result.getByTestId('host')).toHaveClass(placementClassNames.left); | ||
} else if (placement.startsWith('bottom')) { | ||
expect(result.getByTestId('host')).not.toHaveClass(...Object.values(placementClassNames)); | ||
} else if (placement.startsWith('left')) { | ||
expect(result.getByTestId('host')).toHaveClass(placementClassNames.right); | ||
} | ||
}); | ||
|
||
test.each(PLACEMENT_WITH_SIDE)('arrow offset by %s placement', (placement) => { | ||
const result = render( | ||
<FloatingArrow data-testid="host" coords={{ x: 6, y: 8 }} offset={8} placement={placement} />, | ||
); | ||
|
||
if (placement.startsWith('top')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ top: '100%', left: '14px' }); | ||
} else if (placement.startsWith('right')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ left: '0px', top: '16px' }); | ||
} else if (placement.startsWith('bottom')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ bottom: '100%', left: '14px' }); | ||
} else if (placement.startsWith('left')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ right: '0px', top: '16px' }); | ||
} | ||
}); | ||
|
||
test.each(PLACEMENT_WITH_SIDE)('arrow static offset by %s placement', (placement) => { | ||
const result = render( | ||
<FloatingArrow | ||
data-testid="host" | ||
coords={{ x: 6, y: 8 }} | ||
isStaticOffset | ||
offset={8} | ||
placement={placement} | ||
/>, | ||
); | ||
|
||
if (placement.endsWith('end')) { | ||
if (placement.startsWith('top')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ top: '100%', right: '8px' }); | ||
} else if (placement.startsWith('right')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ left: '0px', bottom: '8px' }); | ||
} else if (placement.startsWith('bottom')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ bottom: '100%', right: '8px' }); | ||
} else if (placement.startsWith('left')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ right: '0px', bottom: '8px' }); | ||
} | ||
} else { | ||
if (placement.startsWith('top')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ top: '100%', left: '8px' }); | ||
} else if (placement.startsWith('right')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ left: '0px', top: '8px' }); | ||
} else if (placement.startsWith('bottom')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ bottom: '100%', left: '8px' }); | ||
} else if (placement.startsWith('left')) { | ||
expect(result.getByTestId('host')).toHaveStyle({ right: '0px', top: '8px' }); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters