|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | + |
| 3 | +import { getStorybookFrameLocator } from '../utils'; |
| 4 | + |
| 5 | +const STORY_PATH = '/?path=/story/admiral-2-1-input-textinput--text-input-with-icon'; |
| 6 | + |
| 7 | +test.describe('TextInput icons spacing', () => { |
| 8 | + test('reserves space for nested icons and keeps them accessible', async ({ page }) => { |
| 9 | + await page.goto(STORY_PATH); |
| 10 | + const frame = getStorybookFrameLocator(page); |
| 11 | + |
| 12 | + // Третий инпут в истории — с тремя иконками + крестик |
| 13 | + const targetInput = frame.locator('.text-input-native-input').nth(2); |
| 14 | + await targetInput.click(); |
| 15 | + await targetInput.fill( |
| 16 | + 'Очень-очень-очень длинный текст для проверки того, что иконки точно-точно-точно не перекрывают содержимое инпута', |
| 17 | + ); |
| 18 | + |
| 19 | + const container = targetInput.locator('xpath=..'); |
| 20 | + const iconPanel = container.locator('[data-role="icon-pane-after"]'); |
| 21 | + await expect(iconPanel).toHaveCount(1); |
| 22 | + |
| 23 | + // 3 пользовательские иконки + иконка очистки |
| 24 | + const iconButtons = iconPanel.locator(':scope > *'); |
| 25 | + await expect(iconButtons).toHaveCount(4); |
| 26 | + |
| 27 | + const paddingRight = await targetInput.evaluate((el) => |
| 28 | + parseFloat(window.getComputedStyle(el).paddingRight || '0'), |
| 29 | + ); |
| 30 | + expect(paddingRight).toBeGreaterThanOrEqual(140); // 16 + (24 + 8) * 4 = 144px |
| 31 | + |
| 32 | + const [inputBox, panelBox] = await Promise.all([targetInput.boundingBox(), iconPanel.boundingBox()]); |
| 33 | + expect(inputBox && panelBox).toBeTruthy(); |
| 34 | + |
| 35 | + if (inputBox && panelBox) { |
| 36 | + const safeTextAreaEnd = inputBox.x + inputBox.width - paddingRight; |
| 37 | + expect(panelBox.x).toBeGreaterThanOrEqual(safeTextAreaEnd - 1); |
| 38 | + } |
| 39 | + }); |
| 40 | +}); |
0 commit comments