woodshop/tests/test_inventory_window.py

38 lines
1.3 KiB
Python

"""Offscreen tests for the Inventory window (read-only management view)."""
import os
import pytest
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
pytest.importorskip("PySide6")
from PySide6.QtWidgets import QApplication # noqa: E402
from woodshop import inventory as I # noqa: E402
from woodshop.gui.inventory_window import InventoryWindow # noqa: E402
_app = QApplication.instance() or QApplication([])
def test_window_renders_ledger(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_DATA_HOME", str(tmp_path / "data"))
led = I.Ledger()
led.purchase("2x4", 5, price=3.98)
led.record_build("table", 2, consumed={"2x4": 2}, offcuts=[
{"stock": "2x4", "length_in": 30, "width_in": 3.5, "is_sheet": False}],
dispositions=["keep"])
led.save()
w = InventoryWindow()
assert "2x4" in w._tabs["On-hand"].toPlainText()
assert "OFFCUT" in w._tabs["Offcut bin"].toPlainText()
assert "table" in w._tabs["Build history"].toPlainText()
stats = w._tabs["Stats"].toPlainText()
assert "Units built" in stats and "2" in stats
def test_empty_ledger_renders(tmp_path, monkeypatch):
monkeypatch.setenv("XDG_DATA_HOME", str(tmp_path / "data"))
w = InventoryWindow()
assert "empty" in w._tabs["On-hand"].toPlainText().lower()
assert "no builds" in w._tabs["Build history"].toPlainText().lower()