-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_alert.py
More file actions
68 lines (54 loc) · 1.96 KB
/
test_alert.py
File metadata and controls
68 lines (54 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Unit tests for the imperative Alert API."""
from __future__ import annotations
from typing import Generator
import pytest
from pythonnative.alerts import Alert
from pythonnative.platform import _set_platform_for_test
@pytest.fixture(autouse=True)
def _reset() -> Generator[None, None, None]:
Alert._test_log.clear()
yield
Alert._test_log.clear()
_set_platform_for_test(None)
def test_show_records_to_test_log() -> None:
Alert.show(title="Hello", message="World")
assert len(Alert._test_log) == 1
entry = Alert._test_log[0]
assert entry["title"] == "Hello"
assert entry["message"] == "World"
assert entry["style"] == "alert"
assert entry["buttons"] == []
def test_show_with_buttons_and_action_sheet_style() -> None:
Alert.show(
title="Pick",
buttons=[
{"label": "A", "on_press": lambda: None},
{"label": "B", "style": "destructive"},
],
style="action_sheet",
)
entry = Alert._test_log[0]
assert entry["style"] == "action_sheet"
assert len(entry["buttons"]) == 2
assert entry["buttons"][0]["label"] == "A"
assert entry["buttons"][1]["style"] == "destructive"
def test_confirm_creates_two_buttons() -> None:
Alert.confirm(title="Sure?", on_confirm=lambda: None)
entry = Alert._test_log[0]
assert len(entry["buttons"]) == 2
assert entry["buttons"][0]["label"] == "Cancel"
assert entry["buttons"][0]["style"] == "cancel"
assert entry["buttons"][1]["label"] == "OK"
assert entry["buttons"][1]["style"] == "default"
def test_confirm_custom_labels() -> None:
Alert.confirm(
title="Quit?",
message="Unsaved changes will be lost.",
confirm_label="Quit",
cancel_label="Stay",
)
entry = Alert._test_log[0]
assert entry["title"] == "Quit?"
assert entry["message"] == "Unsaved changes will be lost."
assert entry["buttons"][0]["label"] == "Stay"
assert entry["buttons"][1]["label"] == "Quit"