From 7ffbfa0e2459f6636df75b20a65bff29d051d8af Mon Sep 17 00:00:00 2001 From: James Kerr Date: Tue, 2 Apr 2024 08:57:00 -0700 Subject: [PATCH] Replace the tab entries on first load --- apps/zui/src/models/browser-tab.ts | 11 +++++++++++ packages/zui-player/tests/queries.spec.ts | 5 +++++ 2 files changed, 16 insertions(+) diff --git a/apps/zui/src/models/browser-tab.ts b/apps/zui/src/models/browser-tab.ts index bb0b0af1c..5be77fd1d 100644 --- a/apps/zui/src/models/browser-tab.ts +++ b/apps/zui/src/models/browser-tab.ts @@ -38,7 +38,18 @@ export class BrowserTab extends DomainModel { if (this.history.location.pathname === pathname) { this.history.replace(pathname) } else { + // Whenever a tab is created it constructs itself with a root entry "/". + // This can mess up the tab history back button, allowing the user to + // get back to this "root" url which does not contain forward/back buttons. + // Instead, this if statement resets the entries and index for this tab + // if the only url in the entries array is "/", making it the + // first entry in the history the first pathname given to browerTab.load() + if (this.history.length == 1 && this.history.location.pathname === "/") { + this.history.entries = [] + this.history.index = -1 + } this.history.push(pathname) + console.log(this.history) } } diff --git a/packages/zui-player/tests/queries.spec.ts b/packages/zui-player/tests/queries.spec.ts index 75159eaa0..3f9fb7e40 100644 --- a/packages/zui-player/tests/queries.spec.ts +++ b/packages/zui-player/tests/queries.spec.ts @@ -15,6 +15,11 @@ test.describe('Query tests', () => { await app.shutdown(); }); + test('session initializes with the back button disabled', async () => { + const backButton = app.locate('button', 'Go Back'); + await expect(backButton).toBeDisabled(); + }); + test('session queries are the default and ordered properly in history', async () => { await app.query('1'); await app.query('2');