-
Notifications
You must be signed in to change notification settings - Fork 2
gui: Ask for cards, a record and marked look-alikes #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BenWestgate
wants to merge
6
commits into
bails-v1-pin
Choose a base branch
from
gui-before-you-start
base: bails-v1-pin
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7181c7b
gui: Ask for cards and a record before creating
claude 4d53a4a
gui: Guard old GTK and document the form launch
claude b91c007
gui: Let a launcher name a readable forms folder
claude c1863df
gui: Ask for marked look-alikes on cards
claude 4d65adc
docs: Record the GUI budget raise to 2,050
claude aaa0e67
test: Pin the GTK branch in form launch tests
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
File renamed without changes.
This file contains hidden or 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 hidden or 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,117 @@ | ||
| """The create flow asks for blank cards and a wallet record before the first card.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterator | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
|
|
||
| gi = pytest.importorskip("gi") | ||
| try: | ||
| gi.require_version("Gtk", "4.0") | ||
| gi.require_version("Adw", "1") | ||
| gi.require_version("Gdk", "4.0") | ||
| from gi.repository import Adw, Gdk, Gtk | ||
| except (ImportError, ValueError): | ||
| pytest.skip("GTK 4 and libadwaita are unavailable", allow_module_level=True) | ||
| if not Gtk.init_check() or Gdk.Display.get_default() is None: | ||
| pytest.skip("no display for GTK", allow_module_level=True) | ||
| Adw.init() | ||
|
|
||
| from codex32_gui import FORMS, pages | ||
|
|
||
|
|
||
| def _widgets(root: Gtk.Widget, kind: type) -> Iterator[Gtk.Widget]: | ||
| child = root.get_first_child() | ||
| while child is not None: | ||
| if isinstance(child, kind): | ||
| yield child | ||
| yield from _widgets(child, kind) | ||
| child = child.get_next_sibling() | ||
|
|
||
|
|
||
| def _button(page: Gtk.Widget, label: str) -> Gtk.Button: | ||
| return next(button for button in _widgets(page, Gtk.Button) if button.get_label() == label) | ||
|
|
||
|
|
||
| def _texts(page: Gtk.Widget) -> str: | ||
| return " ".join(label.get_label() for label in _widgets(page, Gtk.Label)) | ||
|
|
||
|
|
||
| def test_a_layout_choice_leads_to_the_checklist_not_to_a_card(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| began: list[tuple[Any, ...]] = [] | ||
| monkeypatch.setattr(pages, "_begin_cards", lambda *arguments: began.append(arguments)) | ||
| view = Adw.NavigationView() | ||
| core: Any = object() | ||
| view.push(pages._layout_page(view, core)) | ||
|
|
||
| _button(view.get_visible_page(), "Continue").emit("clicked") | ||
| ready = view.get_visible_page() | ||
| assert began == [] | ||
| assert "Have 3 blank recovery cards, a pen, and one wallet record ready." in _texts(ready) | ||
|
|
||
| _button(ready, "I have them ready").emit("clicked") | ||
| assert began == [(view, core, 2, 3, 16)] | ||
|
|
||
|
|
||
| def test_a_single_card_backup_asks_for_one_card() -> None: | ||
| view = Adw.NavigationView() | ||
| page = pages._ready_page(view, object(), 0, 1, 16) # type: ignore[arg-type] | ||
| assert "Have one blank recovery card, a pen, and one wallet record ready." in _texts(page) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("label", "name"), | ||
| [ | ||
| ("Open the recovery card form", "recovery-card.html"), | ||
| ("Open the wallet record form", "wallet-verification-record.html"), | ||
| ], | ||
| ) | ||
| def test_each_button_opens_its_shipped_form(monkeypatch: pytest.MonkeyPatch, label: str, name: str) -> None: | ||
| opened: list[str] = [] | ||
|
|
||
| class Launcher: | ||
| def __init__(self, file: Any) -> None: | ||
| self.path = file.get_path() | ||
|
|
||
| def launch(self, _parent: object, _cancellable: object, _callback: object) -> None: | ||
| opened.append(self.path) | ||
|
|
||
| monkeypatch.setattr(pages.Gtk, "FileLauncher", Launcher, raising=False) | ||
| monkeypatch.setattr(pages.Gtk, "check_version", lambda *_version: None) | ||
| view = Adw.NavigationView() | ||
| page = pages._ready_page(view, object(), 2, 3, 16) # type: ignore[arg-type] | ||
|
|
||
| _button(page, label).emit("clicked") | ||
| assert opened == [str(FORMS.joinpath(name))] | ||
| assert FORMS.joinpath(name).is_file() | ||
|
|
||
|
|
||
| def test_an_old_gtk_shows_where_the_form_is(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setattr(pages.Gtk, "check_version", lambda *_version: "GTK is older than 4.10") | ||
| view = Adw.NavigationView() | ||
| page = pages._ready_page(view, object(), 2, 3, 16) # type: ignore[arg-type] | ||
|
|
||
| _button(page, "Open the wallet record form").emit("clicked") | ||
| assert str(FORMS.joinpath("wallet-verification-record.html")) in _texts(page) | ||
|
|
||
|
|
||
| def test_a_launcher_can_point_the_buttons_at_a_readable_copy(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| opened: list[str] = [] | ||
|
|
||
| class Launcher: | ||
| def __init__(self, file: Any) -> None: | ||
| opened.append(file.get_path()) | ||
|
|
||
| def launch(self, _parent: object, _cancellable: object, _callback: object) -> None: | ||
| pass | ||
|
|
||
| monkeypatch.setattr(pages.Gtk, "FileLauncher", Launcher, raising=False) | ||
| monkeypatch.setattr(pages.Gtk, "check_version", lambda *_version: None) | ||
| monkeypatch.setenv("CODEX32_FORMS_DIR", "/home/amnesia/Tor Browser/codex32 forms") | ||
| view = Adw.NavigationView() | ||
| page = pages._ready_page(view, object(), 2, 3, 16) # type: ignore[arg-type] | ||
|
|
||
| _button(page, "Open the recovery card form").emit("clicked") | ||
| assert opened == ["/home/amnesia/Tor Browser/codex32 forms/recovery-card.html"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.