-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Runs onload handler for browser navigations (backwards and forwards) (#…
- Loading branch information
1 parent
38edea8
commit 04995df
Showing
7 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import mesop as me | ||
|
||
|
||
@me.stateclass | ||
class State: | ||
page_1_onload_counter: int | ||
page_2_onload_counter: int | ||
|
||
|
||
def page_1_on_load(e: me.LoadEvent): | ||
me.state(State).page_1_onload_counter += 1 | ||
|
||
|
||
@me.page(path="/browser_navigation_on_load/page1", on_load=page_1_on_load) | ||
def page1(): | ||
me.text("page1") | ||
me.text(f"onload ran {me.state(State).page_1_onload_counter} times") | ||
me.button("navigate", on_click=navigate) | ||
|
||
|
||
def navigate(e: me.ClickEvent): | ||
me.navigate("/browser_navigation_on_load/page2") | ||
|
||
|
||
def page_2_on_load(e: me.LoadEvent): | ||
me.state(State).page_2_onload_counter += 1 | ||
|
||
|
||
@me.page(path="/browser_navigation_on_load/page2", on_load=page_2_on_load) | ||
def page2(): | ||
me.text("page2") | ||
me.text(f"onload ran {me.state(State).page_2_onload_counter} times") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {test, expect} from '@playwright/test'; | ||
|
||
test('browser navigation - back and forward (triggers onload)', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/browser_navigation_on_load/page1'); | ||
await expect(page.getByText('page1')).toBeVisible(); | ||
await expect(page.getByText('onload ran 1 times')).toBeVisible(); | ||
|
||
// Trigger a navigation. | ||
await page.getByRole('button', {name: 'navigate'}).click(); | ||
|
||
await expect(page.getByText('page2')).toBeVisible(); | ||
await expect(page.getByText('onload ran 1 times')).toBeVisible(); | ||
|
||
// Go back to page 1 | ||
await page.goBack(); | ||
await expect(page.getByText('page1')).toBeVisible(); | ||
await expect(page.getByText('onload ran 2 times')).toBeVisible(); | ||
|
||
// Go forward to page 2 | ||
await page.goForward(); | ||
await expect(page.getByText('page2')).toBeVisible(); | ||
await expect(page.getByText('onload ran 2 times')).toBeVisible(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters