|
| 1 | +import { expect, test } from '@playwright/test'; |
| 2 | + |
| 3 | +test('Can navigate with Turbo Drive without full page reload', async ({ page }) => { |
| 4 | + await page.goto('/ux-turbo/drive'); |
| 5 | + |
| 6 | + // Check initial page content |
| 7 | + await expect(page.locator('h2')).toContainText('Turbo Drive Navigation - Page 1'); |
| 8 | + const initialTime = await page.locator('#page-load-time').textContent(); |
| 9 | + |
| 10 | + // Navigate to page 2 |
| 11 | + await page.click('#navigate-to-page-2'); |
| 12 | + |
| 13 | + // Wait for navigation to complete |
| 14 | + await expect(page.locator('h2')).toContainText('Turbo Drive Navigation - Page 2'); |
| 15 | + |
| 16 | + // The time on page 2 should be different (it's a new request) |
| 17 | + const page2Time = await page.locator('#page-load-time').textContent(); |
| 18 | + expect(page2Time).not.toBe(initialTime); |
| 19 | + |
| 20 | + // Navigate back to page 1 |
| 21 | + await page.click('#navigate-back'); |
| 22 | + await expect(page.locator('h2')).toContainText('Turbo Drive Navigation - Page 1'); |
| 23 | + |
| 24 | + // Verify Turbo Drive is working by checking if the page didn't do a full reload |
| 25 | + // We can verify this by checking that Turbo is present |
| 26 | + const hasTurbo = await page.evaluate(() => { |
| 27 | + return typeof (window as any).Turbo !== 'undefined'; |
| 28 | + }); |
| 29 | + expect(hasTurbo).toBe(true); |
| 30 | +}); |
| 31 | + |
| 32 | +test('Can navigate inside a Turbo Frame without affecting the rest of the page', async ({ page }) => { |
| 33 | + await page.goto('/ux-turbo/frame'); |
| 34 | + |
| 35 | + // Check initial state |
| 36 | + await expect(page.locator('#frame-initial-content')).toContainText('This is the initial frame content'); |
| 37 | + await expect(page.locator('#content-outside-frame')).toContainText('This content is outside the frame'); |
| 38 | + |
| 39 | + // Click link inside the frame |
| 40 | + await page.click('#load-frame-content'); |
| 41 | + |
| 42 | + // Wait for frame content to update |
| 43 | + await expect(page.locator('#frame-updated-content')).toContainText('The frame content has been updated'); |
| 44 | + |
| 45 | + // Verify content outside frame hasn't changed |
| 46 | + await expect(page.locator('#content-outside-frame')).toContainText('This content is outside the frame'); |
| 47 | + |
| 48 | + // Verify the frame initial content is no longer visible |
| 49 | + await expect(page.locator('#frame-initial-content')).not.toBeVisible(); |
| 50 | +}); |
| 51 | + |
| 52 | +test('Can update page content with Turbo Streams after form submission', async ({ page }) => { |
| 53 | + await page.goto('/ux-turbo/stream'); |
| 54 | + |
| 55 | + // Check initial state |
| 56 | + await expect(page.locator('#stream-target')).toContainText('Content before form submission'); |
| 57 | + await expect(page.locator('#form-container')).toBeVisible(); |
| 58 | + |
| 59 | + // Submit the form |
| 60 | + await page.click('#submit-turbo-stream'); |
| 61 | + |
| 62 | + // Wait for Turbo Stream to update the content |
| 63 | + await expect(page.locator('#updated-by-stream')).toContainText('This content was updated by a Turbo Stream'); |
| 64 | + |
| 65 | + // Verify the form was removed by the Turbo Stream |
| 66 | + await expect(page.locator('#form-container')).not.toBeVisible(); |
| 67 | + |
| 68 | + // Verify the target element still exists but with new content |
| 69 | + await expect(page.locator('#stream-target')).toBeVisible(); |
| 70 | + await expect(page.locator('#stream-target')).toHaveClass(/alert-success/); |
| 71 | +}); |
0 commit comments