Test that multiple tabs can link to and share state. Args: linked_state: harness for LinkedStateApp. tab_factory: factory to create WebDriver instances.
(
linked_state: AppHarness,
tab_factory: Callable[[], WebDriver],
)
| 319 | |
| 320 | |
| 321 | def test_linked_state( |
| 322 | linked_state: AppHarness, |
| 323 | tab_factory: Callable[[], WebDriver], |
| 324 | ): |
| 325 | """Test that multiple tabs can link to and share state. |
| 326 | |
| 327 | Args: |
| 328 | linked_state: harness for LinkedStateApp. |
| 329 | tab_factory: factory to create WebDriver instances. |
| 330 | |
| 331 | """ |
| 332 | assert linked_state.app_instance is not None |
| 333 | |
| 334 | tab1 = tab_factory() |
| 335 | tab2 = tab_factory() |
| 336 | ss = utils.SessionStorage(tab1) |
| 337 | assert AppHarness._poll_for(lambda: ss.get("token") is not None), "token not found" |
| 338 | n_changes_1 = tab1.find_element(By.ID, "n-changes") |
| 339 | greeting_1 = tab1.find_element(By.ID, "greeting") |
| 340 | ss = utils.SessionStorage(tab2) |
| 341 | assert AppHarness._poll_for(lambda: ss.get("token") is not None), "token not found" |
| 342 | n_changes_2 = tab2.find_element(By.ID, "n-changes") |
| 343 | greeting_2 = tab2.find_element(By.ID, "greeting") |
| 344 | |
| 345 | # Initial state |
| 346 | assert n_changes_1.text == "0" |
| 347 | assert greeting_1.text == "Hello, world!" |
| 348 | assert n_changes_2.text == "0" |
| 349 | assert greeting_2.text == "Hello, world!" |
| 350 | |
| 351 | # Change state in tab 1 |
| 352 | tab1.find_element(By.ID, "who-input").send_keys("Alice", Keys.ENTER) |
| 353 | assert linked_state.poll_for_content(n_changes_1, exp_not_equal="0") == "1" |
| 354 | assert ( |
| 355 | linked_state.poll_for_content(greeting_1, exp_not_equal="Hello, world!") |
| 356 | == "Hello, Alice!" |
| 357 | ) |
| 358 | |
| 359 | # Change state in tab 2 |
| 360 | tab2.find_element(By.ID, "who-input").send_keys("Bob", Keys.ENTER) |
| 361 | assert linked_state.poll_for_content(n_changes_2, exp_not_equal="0") == "1" |
| 362 | assert ( |
| 363 | linked_state.poll_for_content(greeting_2, exp_not_equal="Hello, world!") |
| 364 | == "Hello, Bob!" |
| 365 | ) |
| 366 | |
| 367 | # Link both tabs to the same token, "shared-foo" |
| 368 | shared_token = f"shared-foo-{uuid.uuid4()}" |
| 369 | for tab in (tab1, tab2): |
| 370 | tab.find_element(By.ID, "token-input").send_keys(shared_token, Keys.ENTER) |
| 371 | assert linked_state.poll_for_content(n_changes_1, exp_not_equal="1") == "0" |
| 372 | assert ( |
| 373 | linked_state.poll_for_content(greeting_1, exp_not_equal="Hello, Alice!") |
| 374 | == "Hello, world!" |
| 375 | ) |
| 376 | assert linked_state.poll_for_content(n_changes_2, exp_not_equal="1") == "0" |
| 377 | assert ( |
| 378 | linked_state.poll_for_content(greeting_2, exp_not_equal="Hello, Bob!") |
nothing calls this directly
no test coverage detected