ECOSYSTEM / DESKTOP

Testing dialogs

Answer dialogs in headless tests, without real windows.

Ecosystem package janelkit-desktop System services: native file and message dialogs, and the clipboard. It adds no interface controls. pip install janelkit-desktop
DESKTOP · PAGE 4 / 4~1 min read
Alpha / 0.2 — These pages document JanelKit 0.2 and its packages. Each series (0.1, 0.2…) may change the public API, always with migration notes: see Changes and migration. The website uses Svelte; the desktop examples use Python and JanelKit, not JavaScript.

Answer the dialog the user would see

Importing janelkit-desktop adds two methods to the MountedApp of janelkit.inspect, so tests can answer dialogs without real windows. Your application imports the package, so the methods are there in its tests. This test targets the example in Overview.

MethodWhat it does
app.dialogs()Open dialogs, oldest first.
app.answer_dialog(result)Answers the most recent dialog: a path for file and folder dialogs, True to accept or False to cancel.
python
from janelkit import inspect

def test_cancel_keeps_the_text():
    with inspect.mount("src/App.janel") as app:
        app.find("textarea").type("Hello")
        app.find(text="Open…").click()
        app.answer_dialog(False)                 # the user cancels
        assert app.find("textarea").value == "Hello"
Copy

How it works

  1. The click opens a real dialog object, without showing a native window in a headless test.
  2. answer_dialog(False) cancels it, so open_file returns None and the text stays.

Which dialog is open

dialogs.pending() lists the dialogs open now, and dialogs.kind(d) says the type of one: "MessageDialog", "FileDialog" or "FolderDialog". Use them to check that the right dialog opened before answering it.

Examples

In the JanelKit repository, apps/examples/files chooses a folder, apps/challenges/gestor asks for confirmations, and apps/challenges/hoja opens and saves CSV files and uses the clipboard.

English documentation based on the JanelKit source. For additional details, browse the source docs ↗.