|
| 1 | +import { test, expect, type Page } from '@playwright/test'; |
| 2 | +import { |
| 3 | + waitForLoadingDone, |
| 4 | + openTableOption, |
| 5 | + openTable, |
| 6 | + gotoPage, |
| 7 | +} from './utils'; |
| 8 | + |
| 9 | +// Scroll the table by scrolling the mouse wheel, whilst moving the mouse up and down to test hovering functionality |
| 10 | +async function scrollTableWhileMovingMouse(page: Page) { |
| 11 | + const gridCanvas = page.locator('.iris-grid .grid-wrapper'); |
| 12 | + const box = await gridCanvas.boundingBox(); |
| 13 | + if (!box) throw new Error('No bounding box found for grid canvas'); |
| 14 | + |
| 15 | + let mouseY = box.y + 120; |
| 16 | + const mouseX = box.x + 20; |
| 17 | + const mouseStep = 40; |
| 18 | + |
| 19 | + const scrollDeltas = [ |
| 20 | + 1000, -600, 1600, -1200, 2000, -2000, 1000, -400, 1400, -1000, |
| 21 | + ]; |
| 22 | + |
| 23 | + for (let i = 0; i < scrollDeltas.length; i += 1) { |
| 24 | + mouseY += i % 2 === 0 ? -mouseStep : mouseStep; |
| 25 | + // eslint-disable-next-line no-await-in-loop |
| 26 | + await page.mouse.move(mouseX, mouseY); |
| 27 | + |
| 28 | + let remaining = Math.abs(scrollDeltas[i]); |
| 29 | + const direction = Math.sign(scrollDeltas[i]); |
| 30 | + const scrollStep = 100; |
| 31 | + |
| 32 | + while (remaining > 0) { |
| 33 | + const step = Math.min(scrollStep, remaining); |
| 34 | + // eslint-disable-next-line no-await-in-loop |
| 35 | + await page.mouse.wheel(0, step * direction); |
| 36 | + remaining -= step; |
| 37 | + } |
| 38 | + } |
| 39 | +} |
| 40 | + |
| 41 | +test.beforeEach(async ({ page }) => { |
| 42 | + await gotoPage(page, ''); |
| 43 | + |
| 44 | + // Fail quickly if console errors are detected |
| 45 | + page.on('console', msg => { |
| 46 | + if (msg.type() === 'error') { |
| 47 | + throw new Error(msg.text()); |
| 48 | + } |
| 49 | + }); |
| 50 | + page.on('pageerror', error => { |
| 51 | + throw error; |
| 52 | + }); |
| 53 | +}); |
| 54 | + |
| 55 | +test('scroll with keyboard shortcuts', async ({ page }) => { |
| 56 | + // Use simple_table for its scrollable number of rows |
| 57 | + await openTable(page, 'simple_table'); |
| 58 | + |
| 59 | + const gridCanvas = page.locator('.iris-grid .grid-wrapper'); |
| 60 | + await gridCanvas.click({ position: { x: 10, y: 80 } }); |
| 61 | + await waitForLoadingDone(page); |
| 62 | + |
| 63 | + // Down |
| 64 | + await page.keyboard.press('ArrowDown'); |
| 65 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 66 | + |
| 67 | + // Up |
| 68 | + await page.keyboard.press('ArrowUp'); |
| 69 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 70 | + |
| 71 | + // Page Down |
| 72 | + await page.keyboard.press('PageDown'); |
| 73 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 74 | + |
| 75 | + // Page Up |
| 76 | + await page.keyboard.press('PageUp'); |
| 77 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 78 | + |
| 79 | + // End |
| 80 | + await page.keyboard.press('ControlOrMeta+ArrowDown'); |
| 81 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 82 | + |
| 83 | + // Home |
| 84 | + await page.keyboard.press('ControlOrMeta+ArrowUp'); |
| 85 | + await expect(page.locator('.iris-grid-column')).toHaveScreenshot(); |
| 86 | +}); |
| 87 | + |
| 88 | +test('scroll while moving mouse over rows', async ({ page }) => { |
| 89 | + // Use simple_table for its scrollable number of rows |
| 90 | + await openTable(page, 'simple_table'); |
| 91 | + |
| 92 | + const gridCanvas = page.locator('.iris-grid .grid-wrapper'); |
| 93 | + await gridCanvas.click({ position: { x: 10, y: 80 } }); |
| 94 | + await waitForLoadingDone(page); |
| 95 | + |
| 96 | + await scrollTableWhileMovingMouse(page); |
| 97 | +}); |
| 98 | + |
| 99 | +test('scroll expanded rollup while moving mouse over rows', async ({ |
| 100 | + page, |
| 101 | +}) => { |
| 102 | + // Use simple_table for its scrollable number of rows |
| 103 | + await openTable(page, 'simple_table'); |
| 104 | + |
| 105 | + await test.step('Open Rollup Rows option', async () => { |
| 106 | + const tableOperationsMenu = page.locator( |
| 107 | + 'data-testid=btn-iris-grid-settings-button-table' |
| 108 | + ); |
| 109 | + await tableOperationsMenu.click(); |
| 110 | + // Wait for Table Options menu to show |
| 111 | + await expect(page.locator('.table-sidebar')).toHaveCount(1); |
| 112 | + await openTableOption(page, 'Rollup Rows'); |
| 113 | + |
| 114 | + await test.step('Rollup column', async () => { |
| 115 | + const xColumn = page.getByRole('button', { name: 'y' }); |
| 116 | + expect(xColumn).toBeTruthy(); |
| 117 | + await xColumn.dblclick(); |
| 118 | + await waitForLoadingDone(page); |
| 119 | + }); |
| 120 | + |
| 121 | + await test.step('Expand constituent with non-aggregated columns visible', async () => { |
| 122 | + const gridCanvas = page.locator('.iris-grid .grid-wrapper'); |
| 123 | + await gridCanvas.click({ position: { x: 10, y: 80 } }); |
| 124 | + await waitForLoadingDone(page); |
| 125 | + }); |
| 126 | + |
| 127 | + await test.step('Scroll while moving mouse over rows', async () => { |
| 128 | + await scrollTableWhileMovingMouse(page); |
| 129 | + }); |
| 130 | + }); |
| 131 | +}); |
0 commit comments