|
1 | 1 | import { test, expect } from "../fixtures" |
2 | | -import { openSidebar, withSession } from "../actions" |
| 2 | +import { defocus, openSidebar, withSession } from "../actions" |
3 | 3 | import { promptSelector } from "../selectors" |
| 4 | +import { modKey } from "../utils" |
4 | 5 |
|
5 | 6 | test("titlebar back/forward navigates between sessions", async ({ page, slug, sdk, gotoSession }) => { |
6 | 7 | await page.setViewportSize({ width: 1400, height: 800 }) |
@@ -40,3 +41,84 @@ test("titlebar back/forward navigates between sessions", async ({ page, slug, sd |
40 | 41 | }) |
41 | 42 | }) |
42 | 43 | }) |
| 44 | + |
| 45 | +test("titlebar forward is cleared after branching history from sidebar", async ({ page, slug, sdk, gotoSession }) => { |
| 46 | + await page.setViewportSize({ width: 1400, height: 800 }) |
| 47 | + |
| 48 | + const stamp = Date.now() |
| 49 | + |
| 50 | + await withSession(sdk, `e2e titlebar history a ${stamp}`, async (a) => { |
| 51 | + await withSession(sdk, `e2e titlebar history b ${stamp}`, async (b) => { |
| 52 | + await withSession(sdk, `e2e titlebar history c ${stamp}`, async (c) => { |
| 53 | + await gotoSession(a.id) |
| 54 | + |
| 55 | + await openSidebar(page) |
| 56 | + |
| 57 | + const second = page.locator(`[data-session-id="${b.id}"] a`).first() |
| 58 | + await expect(second).toBeVisible() |
| 59 | + await second.scrollIntoViewIfNeeded() |
| 60 | + await second.click() |
| 61 | + |
| 62 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${b.id}(?:\\?|#|$)`)) |
| 63 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 64 | + |
| 65 | + const back = page.getByRole("button", { name: "Back" }) |
| 66 | + const forward = page.getByRole("button", { name: "Forward" }) |
| 67 | + |
| 68 | + await expect(back).toBeVisible() |
| 69 | + await expect(back).toBeEnabled() |
| 70 | + await back.click() |
| 71 | + |
| 72 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${a.id}(?:\\?|#|$)`)) |
| 73 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 74 | + |
| 75 | + await openSidebar(page) |
| 76 | + |
| 77 | + const third = page.locator(`[data-session-id="${c.id}"] a`).first() |
| 78 | + await expect(third).toBeVisible() |
| 79 | + await third.scrollIntoViewIfNeeded() |
| 80 | + await third.click() |
| 81 | + |
| 82 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${c.id}(?:\\?|#|$)`)) |
| 83 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 84 | + |
| 85 | + await expect(forward).toBeVisible() |
| 86 | + await expect(forward).toBeDisabled() |
| 87 | + }) |
| 88 | + }) |
| 89 | + }) |
| 90 | +}) |
| 91 | + |
| 92 | +test("keyboard shortcuts navigate titlebar history", async ({ page, slug, sdk, gotoSession }) => { |
| 93 | + await page.setViewportSize({ width: 1400, height: 800 }) |
| 94 | + |
| 95 | + const stamp = Date.now() |
| 96 | + |
| 97 | + await withSession(sdk, `e2e titlebar shortcuts 1 ${stamp}`, async (one) => { |
| 98 | + await withSession(sdk, `e2e titlebar shortcuts 2 ${stamp}`, async (two) => { |
| 99 | + await gotoSession(one.id) |
| 100 | + |
| 101 | + await openSidebar(page) |
| 102 | + |
| 103 | + const link = page.locator(`[data-session-id="${two.id}"] a`).first() |
| 104 | + await expect(link).toBeVisible() |
| 105 | + await link.scrollIntoViewIfNeeded() |
| 106 | + await link.click() |
| 107 | + |
| 108 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${two.id}(?:\\?|#|$)`)) |
| 109 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 110 | + |
| 111 | + await defocus(page) |
| 112 | + await page.keyboard.press(`${modKey}+[`) |
| 113 | + |
| 114 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${one.id}(?:\\?|#|$)`)) |
| 115 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 116 | + |
| 117 | + await defocus(page) |
| 118 | + await page.keyboard.press(`${modKey}+]`) |
| 119 | + |
| 120 | + await expect(page).toHaveURL(new RegExp(`/${slug}/session/${two.id}(?:\\?|#|$)`)) |
| 121 | + await expect(page.locator(promptSelector)).toBeVisible() |
| 122 | + }) |
| 123 | + }) |
| 124 | +}) |
0 commit comments