mirror of
https://git.zavage.net/Zavage-Software/wabot.git
synced 2026-07-21 13:06:08 -06:00
test: assert field pacing wiring; simplify NullField
This commit is contained in:
parent
807b91e902
commit
9e825ffd80
@ -1370,6 +1370,50 @@ class TestNullField:
|
|||||||
el = NullField(name="missing")
|
el = NullField(name="missing")
|
||||||
if el:
|
if el:
|
||||||
pytest.fail("NullField must be falsy")
|
pytest.fail("NullField must be falsy")
|
||||||
|
|
||||||
|
|
||||||
|
class TestPacingWiring:
|
||||||
|
def _spy_page(self, page):
|
||||||
|
page.pacing = MagicMock()
|
||||||
|
page.pacing.delay.return_value = 0.0
|
||||||
|
return page
|
||||||
|
|
||||||
|
def test_text_set_value_paces_text(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
TextField(page, accessors=ACCESSORS, name="username").set_value("x")
|
||||||
|
page.pacing.delay.assert_called_once_with("text")
|
||||||
|
|
||||||
|
def test_select_set_value_paces_select(self, page, monkeypatch):
|
||||||
|
import wabot.fields as fields_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(fields_mod, "Select", MagicMock())
|
||||||
|
self._spy_page(page)
|
||||||
|
SelectField(page, accessors=("id", "state"), name="state").set_value(value="CO")
|
||||||
|
page.pacing.delay.assert_called_once_with("select")
|
||||||
|
|
||||||
|
def test_select_by_index_paces_select(self, page, monkeypatch):
|
||||||
|
import wabot.fields as fields_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(fields_mod, "Select", MagicMock())
|
||||||
|
self._spy_page(page)
|
||||||
|
SelectField(page, accessors=("id", "state"), name="state").select_by_index(2)
|
||||||
|
page.pacing.delay.assert_called_once_with("select")
|
||||||
|
|
||||||
|
def test_set_checked_paces_checkbox(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
CheckField(page, accessors=("id", "agree"), name="agree").set_checked(True)
|
||||||
|
page.pacing.delay.assert_called_once_with("checkbox")
|
||||||
|
|
||||||
|
def test_click_and_go_paces_navigate(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
PageObject(page, accessors=ACCESSORS, name="username").click_and_go()
|
||||||
|
page.pacing.delay.assert_called_once_with("navigate")
|
||||||
|
|
||||||
|
|
||||||
|
class TestTruthiness:
|
||||||
|
def test_real_field_is_truthy(self, page):
|
||||||
|
# locks the other end of the `if el:` guard contract (NullField is falsy)
|
||||||
|
assert bool(TextField(page, accessors=ACCESSORS, name="username")) is True
|
||||||
```
|
```
|
||||||
|
|
||||||
- [ ] **Step 2: Run tests to verify they fail**
|
- [ ] **Step 2: Run tests to verify they fail**
|
||||||
@ -1478,8 +1522,7 @@ class NullField:
|
|||||||
"""Falsy placeholder for an element that was not found."""
|
"""Falsy placeholder for an element that was not found."""
|
||||||
|
|
||||||
def __init__(self, name=None):
|
def __init__(self, name=None):
|
||||||
# bypass __getattr__ tricks: plain attribute set
|
self.name = name
|
||||||
object.__setattr__(self, "name", name)
|
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return False
|
return False
|
||||||
@ -1493,7 +1536,7 @@ class NullField:
|
|||||||
- [ ] **Step 4: Run tests to verify they pass**
|
- [ ] **Step 4: Run tests to verify they pass**
|
||||||
|
|
||||||
Run: `uv run pytest tests/unit/test_fields.py -v`
|
Run: `uv run pytest tests/unit/test_fields.py -v`
|
||||||
Expected: 11 passed
|
Expected: 17 passed
|
||||||
|
|
||||||
- [ ] **Step 5: Commit**
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
@ -2787,7 +2830,7 @@ Run: `uv run pytest tests/unit/test_api.py -v`
|
|||||||
Expected: 11 passed
|
Expected: 11 passed
|
||||||
|
|
||||||
Run: `uv run pytest`
|
Run: `uv run pytest`
|
||||||
Expected: full unit suite passes (107 tests: pacing 7, sessions 14, hosts 19, reattach 6, fields 11, page 23, screenshot 3, browser 13, api 11)
|
Expected: full unit suite passes (113 tests: pacing 7, sessions 14, hosts 19, reattach 6, fields 17, page 23, screenshot 3, browser 13, api 11)
|
||||||
|
|
||||||
- [ ] **Step 5: Commit**
|
- [ ] **Step 5: Commit**
|
||||||
|
|
||||||
|
|||||||
@ -94,8 +94,7 @@ class NullField:
|
|||||||
"""Falsy placeholder for an element that was not found."""
|
"""Falsy placeholder for an element that was not found."""
|
||||||
|
|
||||||
def __init__(self, name=None):
|
def __init__(self, name=None):
|
||||||
# bypass __getattr__ tricks: plain attribute set
|
self.name = name
|
||||||
object.__setattr__(self, "name", name)
|
|
||||||
|
|
||||||
def __bool__(self):
|
def __bool__(self):
|
||||||
return False
|
return False
|
||||||
|
|||||||
@ -85,3 +85,47 @@ class TestNullField:
|
|||||||
el = NullField(name="missing")
|
el = NullField(name="missing")
|
||||||
if el:
|
if el:
|
||||||
pytest.fail("NullField must be falsy")
|
pytest.fail("NullField must be falsy")
|
||||||
|
|
||||||
|
|
||||||
|
class TestPacingWiring:
|
||||||
|
def _spy_page(self, page):
|
||||||
|
page.pacing = MagicMock()
|
||||||
|
page.pacing.delay.return_value = 0.0
|
||||||
|
return page
|
||||||
|
|
||||||
|
def test_text_set_value_paces_text(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
TextField(page, accessors=ACCESSORS, name="username").set_value("x")
|
||||||
|
page.pacing.delay.assert_called_once_with("text")
|
||||||
|
|
||||||
|
def test_select_set_value_paces_select(self, page, monkeypatch):
|
||||||
|
import wabot.fields as fields_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(fields_mod, "Select", MagicMock())
|
||||||
|
self._spy_page(page)
|
||||||
|
SelectField(page, accessors=("id", "state"), name="state").set_value(value="CO")
|
||||||
|
page.pacing.delay.assert_called_once_with("select")
|
||||||
|
|
||||||
|
def test_select_by_index_paces_select(self, page, monkeypatch):
|
||||||
|
import wabot.fields as fields_mod
|
||||||
|
|
||||||
|
monkeypatch.setattr(fields_mod, "Select", MagicMock())
|
||||||
|
self._spy_page(page)
|
||||||
|
SelectField(page, accessors=("id", "state"), name="state").select_by_index(2)
|
||||||
|
page.pacing.delay.assert_called_once_with("select")
|
||||||
|
|
||||||
|
def test_set_checked_paces_checkbox(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
CheckField(page, accessors=("id", "agree"), name="agree").set_checked(True)
|
||||||
|
page.pacing.delay.assert_called_once_with("checkbox")
|
||||||
|
|
||||||
|
def test_click_and_go_paces_navigate(self, page):
|
||||||
|
self._spy_page(page)
|
||||||
|
PageObject(page, accessors=ACCESSORS, name="username").click_and_go()
|
||||||
|
page.pacing.delay.assert_called_once_with("navigate")
|
||||||
|
|
||||||
|
|
||||||
|
class TestTruthiness:
|
||||||
|
def test_real_field_is_truthy(self, page):
|
||||||
|
# locks the other end of the `if el:` guard contract (NullField is falsy)
|
||||||
|
assert bool(TextField(page, accessors=ACCESSORS, name="username")) is True
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user