feat: 优化界面并补充网格成交分析
This commit is contained in:
@@ -17,7 +17,7 @@ def test_formatters_render_money_percent_and_empty_values():
|
||||
def test_main_window_can_be_constructed_offscreen(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from PySide6.QtWidgets import QApplication, QPushButton
|
||||
from PySide6.QtWidgets import QApplication, QLabel, QPushButton
|
||||
|
||||
from grid_trading.services.trading_service import TradingService
|
||||
from grid_trading.ui.main_window import MainWindow
|
||||
@@ -29,6 +29,9 @@ def test_main_window_can_be_constructed_offscreen(tmp_path, monkeypatch):
|
||||
assert window.windowTitle() == "Grid Trading Manager"
|
||||
assert window.holdings_table.columnCount() > 0
|
||||
assert any(button.text() == "刷新行情" for button in window.findChildren(QPushButton))
|
||||
summary_titles = [label.text() for label in window.findChildren(QLabel)]
|
||||
assert "账户权益" in summary_titles
|
||||
assert "总资产" not in summary_titles
|
||||
|
||||
window.close()
|
||||
service.close()
|
||||
@@ -49,7 +52,7 @@ def test_main_window_contains_grid_level_table(tmp_path, monkeypatch):
|
||||
|
||||
assert window.grid_levels_table.columnCount() == 7
|
||||
tab_titles = _tab_titles(window.details_tabs)
|
||||
assert tab_titles == ["网格档位", "待卖网格", "最近成交"]
|
||||
assert tab_titles == ["网格档位", "待卖网格", "配对明细", "最近成交"]
|
||||
assert isinstance(window.details_tabs, QTabWidget)
|
||||
|
||||
window.close()
|
||||
@@ -71,6 +74,82 @@ def test_main_window_contains_open_grid_lots_table(tmp_path, monkeypatch):
|
||||
|
||||
assert window.open_grid_lots_table.columnCount() == 8
|
||||
assert "待卖网格" in _tab_titles(window.details_tabs)
|
||||
assert window.grid_matches_table.columnCount() == 9
|
||||
assert "配对明细" in _tab_titles(window.details_tabs)
|
||||
|
||||
window.close()
|
||||
service.close()
|
||||
app.processEvents()
|
||||
|
||||
|
||||
def test_main_window_applies_light_theme(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from grid_trading.services.trading_service import TradingService
|
||||
from grid_trading.ui.main_window import MainWindow
|
||||
|
||||
app = QApplication.instance() or QApplication([])
|
||||
service = TradingService(tmp_path / "grid.db")
|
||||
window = MainWindow(service)
|
||||
|
||||
assert window.centralWidget().objectName() == "appRoot"
|
||||
assert window.holdings_table.alternatingRowColors()
|
||||
assert "QMainWindow" in window.styleSheet()
|
||||
|
||||
window.close()
|
||||
service.close()
|
||||
app.processEvents()
|
||||
|
||||
|
||||
def test_profit_and_loss_cells_use_a_share_colors(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
from PySide6.QtGui import QColor
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
from grid_trading.domain.models import PositionSummary
|
||||
from grid_trading.services.trading_service import TradingService
|
||||
from grid_trading.ui.main_window import MainWindow
|
||||
|
||||
app = QApplication.instance() or QApplication([])
|
||||
service = TradingService(tmp_path / "grid.db")
|
||||
window = MainWindow(service)
|
||||
window._positions = [
|
||||
PositionSummary(
|
||||
instrument_id=1,
|
||||
code="510300",
|
||||
name="沪深300ETF",
|
||||
market="ETF",
|
||||
current_price=Decimal("10.50"),
|
||||
price_source="quote",
|
||||
total_quantity=100,
|
||||
available_quantity=100,
|
||||
base_quantity=0,
|
||||
grid_quantity=100,
|
||||
other_quantity=0,
|
||||
remaining_cost=Decimal("1000"),
|
||||
cost_price=Decimal("10"),
|
||||
position_breakeven_price=Decimal("10"),
|
||||
account_breakeven_price=Decimal("10"),
|
||||
realized_pnl=Decimal("12.34"),
|
||||
grid_profit=Decimal("-5.67"),
|
||||
floating_pnl=Decimal("50"),
|
||||
market_value=Decimal("1050"),
|
||||
)
|
||||
]
|
||||
|
||||
window.holdings_table.blockSignals(True)
|
||||
window._fill_holdings_table()
|
||||
window.holdings_table.blockSignals(False)
|
||||
|
||||
profit_item = window.holdings_table.item(0, 10)
|
||||
loss_item = window.holdings_table.item(0, 11)
|
||||
assert profit_item.foreground().color() == QColor("#c62828")
|
||||
assert profit_item.font().bold()
|
||||
assert loss_item.foreground().color() == QColor("#2e7d32")
|
||||
assert loss_item.font().bold()
|
||||
|
||||
window.close()
|
||||
service.close()
|
||||
|
||||
Reference in New Issue
Block a user