|
| 1 | +/** |
| 2 | + * Copyright 2026 Google LLC |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +import {test, expect} from '@playwright/test'; |
| 18 | + |
| 19 | +test.beforeEach(async ({page}) => { |
| 20 | + page.on('pageerror', err => { |
| 21 | + console.error(`Unhandled page error: ${err.message}`); |
| 22 | + }); |
| 23 | +}); |
| 24 | + |
| 25 | +test.describe('Whole-UI Window Scrollbar Prevention', () => { |
| 26 | + test('verifies body, html, and shell layout containers apply overflow hidden styling', async ({ |
| 27 | + page, |
| 28 | + }) => { |
| 29 | + await page.goto('/'); |
| 30 | + await expect(page.locator('a2ui-composer-shell')).toBeVisible(); |
| 31 | + |
| 32 | + const styles = await page.evaluate(() => { |
| 33 | + const bodyStyle = window.getComputedStyle(document.body); |
| 34 | + const shellEl = document.querySelector('a2ui-composer-shell'); |
| 35 | + const shellStyle = shellEl ? window.getComputedStyle(shellEl) : null; |
| 36 | + const workspaceEl = document.querySelector('a2ui-composer-workspace'); |
| 37 | + const workspaceStyle = workspaceEl ? window.getComputedStyle(workspaceEl) : null; |
| 38 | + |
| 39 | + return { |
| 40 | + bodyOverflow: bodyStyle.overflow, |
| 41 | + bodyOverflowY: bodyStyle.overflowY, |
| 42 | + shellOverflow: shellStyle ? shellStyle.overflow : null, |
| 43 | + workspaceOverflow: workspaceStyle ? workspaceStyle.overflow : null, |
| 44 | + }; |
| 45 | + }); |
| 46 | + |
| 47 | + expect(styles.bodyOverflow === 'hidden' || styles.bodyOverflowY === 'hidden').toBe(true); |
| 48 | + expect(styles.shellOverflow).toBe('hidden'); |
| 49 | + expect(styles.workspaceOverflow).toBe('hidden'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('prevents window-level scrolling even when tall content is dynamically present', async ({ |
| 53 | + page, |
| 54 | + }) => { |
| 55 | + await page.goto('/'); |
| 56 | + await expect(page.locator('a2ui-composer-shell')).toBeVisible(); |
| 57 | + |
| 58 | + // Inject an oversized container to force overflow conditions |
| 59 | + await page.evaluate(() => { |
| 60 | + const spacer = document.createElement('div'); |
| 61 | + spacer.id = 'e2e-overflow-spacer'; |
| 62 | + spacer.style.height = '5000px'; |
| 63 | + spacer.style.width = '100%'; |
| 64 | + document.body.appendChild(spacer); |
| 65 | + }); |
| 66 | + |
| 67 | + // Attempt to scroll the main document window |
| 68 | + await page.evaluate(() => { |
| 69 | + window.scrollTo(0, 1000); |
| 70 | + }); |
| 71 | + |
| 72 | + const scrollY = await page.evaluate(() => window.scrollY); |
| 73 | + const scrollTop = await page.evaluate( |
| 74 | + () => document.documentElement.scrollTop || document.body.scrollTop, |
| 75 | + ); |
| 76 | + |
| 77 | + expect(scrollY).toBe(0); |
| 78 | + expect(scrollTop).toBe(0); |
| 79 | + |
| 80 | + // Clean up injected spacer element |
| 81 | + await page.evaluate(() => { |
| 82 | + document.getElementById('e2e-overflow-spacer')?.remove(); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + test('allows internal vertical scrolling in settings view while preventing whole-window scrollbars', async ({ |
| 87 | + page, |
| 88 | + }) => { |
| 89 | + await page.goto('/settings'); |
| 90 | + await page.waitForURL('**/settings'); |
| 91 | + await expect(page.locator('.settings-container')).toBeVisible(); |
| 92 | + |
| 93 | + const bodyOverflow = await page.evaluate(() => window.getComputedStyle(document.body).overflow); |
| 94 | + expect(bodyOverflow === 'hidden' || bodyOverflow === 'clip').toBe(true); |
| 95 | + |
| 96 | + const settingsHostOverflowY = await page.evaluate(() => { |
| 97 | + const settingsEl = document.querySelector('a2ui-composer-settings'); |
| 98 | + return settingsEl ? window.getComputedStyle(settingsEl).overflowY : null; |
| 99 | + }); |
| 100 | + |
| 101 | + expect(settingsHostOverflowY).toBe('auto'); |
| 102 | + |
| 103 | + // Verify main window scroll is 0 |
| 104 | + await page.evaluate(() => window.scrollTo(0, 500)); |
| 105 | + const windowScrollY = await page.evaluate(() => window.scrollY); |
| 106 | + expect(windowScrollY).toBe(0); |
| 107 | + }); |
| 108 | + |
| 109 | + test('preserves window scrollbar prevention in components gallery view', async ({page}) => { |
| 110 | + await page.goto('/gallery'); |
| 111 | + await page.waitForURL('**/gallery'); |
| 112 | + await expect(page.locator('.gallery-container')).toBeVisible(); |
| 113 | + |
| 114 | + const bodyOverflow = await page.evaluate(() => window.getComputedStyle(document.body).overflow); |
| 115 | + expect(bodyOverflow === 'hidden' || bodyOverflow === 'clip').toBe(true); |
| 116 | + |
| 117 | + await page.evaluate(() => window.scrollTo(0, 500)); |
| 118 | + const windowScrollY = await page.evaluate(() => window.scrollY); |
| 119 | + expect(windowScrollY).toBe(0); |
| 120 | + }); |
| 121 | +}); |
0 commit comments