更新
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Qt 悬浮监听条的布局与交互回归测试。"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest import TestCase, main, skipUnless
|
||||
from unittest import TestCase, main, mock, skipUnless
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
@@ -13,6 +16,7 @@ try:
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication,
|
||||
QMainWindow,
|
||||
QMessageBox,
|
||||
QStackedWidget,
|
||||
QVBoxLayout,
|
||||
QWidget,
|
||||
@@ -20,7 +24,7 @@ try:
|
||||
except ImportError:
|
||||
QApplication = None
|
||||
else:
|
||||
from wechat_gui_qt import APP_QSS, CapsuleWindow, MainWindow
|
||||
from wechat_gui_qt import APP_QSS, CapsuleWindow, MainWindow, QueuePage
|
||||
|
||||
|
||||
@skipUnless(QApplication is not None, "当前测试环境未安装 PySide6")
|
||||
@@ -45,7 +49,6 @@ class CapsuleWindowTest(TestCase):
|
||||
|
||||
widgets = (
|
||||
self.capsule.status_group,
|
||||
self.capsule.progress,
|
||||
self.capsule.divider,
|
||||
self.capsule.stop_button,
|
||||
self.capsule.expand_button,
|
||||
@@ -57,6 +60,14 @@ class CapsuleWindowTest(TestCase):
|
||||
for previous, current in zip(bounds, bounds[1:]):
|
||||
self.assertLess(previous[1], current[0])
|
||||
|
||||
# 当前进程独占底部整行,不再被压在计时器下面的 150px 小区域里。
|
||||
self.assertGreaterEqual(self.capsule.progress.width(), 340)
|
||||
self.assertLess(
|
||||
self.capsule.status_group.mapTo(self.capsule.panel, QPoint(0, 0)).y()
|
||||
+ self.capsule.status_group.height(),
|
||||
self.capsule.progress.mapTo(self.capsule.panel, QPoint(0, 0)).y() + 1,
|
||||
)
|
||||
|
||||
def test_timer_and_longest_copy_fit_their_widgets(self):
|
||||
timer_width = QFontMetrics(self.capsule.timer.font()).horizontalAdvance("00:00:00")
|
||||
self.assertLessEqual(timer_width, self.capsule.timer.contentsRect().width())
|
||||
@@ -90,8 +101,8 @@ class CapsuleWindowTest(TestCase):
|
||||
)
|
||||
self.assertLessEqual(timer_width, self.capsule.timer.contentsRect().width())
|
||||
|
||||
def test_the_timer_sits_directly_above_the_progress_line(self):
|
||||
# 缩成胶囊后只剩状态点和时长,看不出机器人此刻在忙什么
|
||||
def test_the_timer_sits_above_the_full_width_progress_line(self):
|
||||
# 缩成胶囊后仍能同时看到时长和完整的当前执行步骤。
|
||||
timer_top = self.capsule.timer.mapTo(self.capsule.panel, QPoint(0, 0)).y()
|
||||
progress_top = self.capsule.progress.mapTo(self.capsule.panel, QPoint(0, 0)).y()
|
||||
self.assertLess(timer_top + self.capsule.timer.height(), progress_top + 1)
|
||||
@@ -99,7 +110,12 @@ class CapsuleWindowTest(TestCase):
|
||||
def test_the_progress_line_says_who_is_being_answered(self):
|
||||
self.capsule.set_progress("正在回复 高瑞@微信")
|
||||
self.app.processEvents()
|
||||
self.assertEqual(self.capsule.progress.text(), "正在回复 高瑞@微信")
|
||||
self.assertEqual(self.capsule.progress.text(), "当前进程 · 正在回复 高瑞@微信")
|
||||
|
||||
def test_running_without_a_task_still_shows_a_real_process(self):
|
||||
self.capsule.set_status("running", "监听中")
|
||||
self.app.processEvents()
|
||||
self.assertEqual(self.capsule.progress.text(), "当前进程 · 等待新消息")
|
||||
|
||||
def test_a_long_nickname_is_shortened_instead_of_overflowing(self):
|
||||
long_name = "正在回复 甄养堂医疗助理-盛灵莉客户服务专员@微信"
|
||||
@@ -110,7 +126,7 @@ class CapsuleWindowTest(TestCase):
|
||||
width = QFontMetrics(self.capsule.progress.font()).horizontalAdvance(shown)
|
||||
self.assertLessEqual(width, self.capsule.progress.width())
|
||||
# 省略之后还得能查到全名,否则不知道回的是谁
|
||||
self.assertEqual(self.capsule.progress.toolTip(), long_name)
|
||||
self.assertEqual(self.capsule.progress.toolTip(), f"当前进程 · {long_name}")
|
||||
|
||||
def test_stopping_clears_a_stale_progress_line(self):
|
||||
# 停下来还挂着"正在回复 XXX"会让人以为它还在干活
|
||||
@@ -123,7 +139,9 @@ class CapsuleWindowTest(TestCase):
|
||||
self.capsule.set_progress("正在读取 高瑞@微信 的消息")
|
||||
self.capsule.set_status("running", "监听中")
|
||||
self.app.processEvents()
|
||||
self.assertEqual(self.capsule.progress.text(), "正在读取 高瑞@微信 的消息")
|
||||
self.assertEqual(
|
||||
self.capsule.progress.text(), "当前进程 · 正在读取 高瑞@微信 的消息"
|
||||
)
|
||||
|
||||
def test_status_copy_and_actions_remain_connected(self):
|
||||
self.capsule.set_status("waiting", "等待企业微信")
|
||||
@@ -162,6 +180,37 @@ class CapsuleWindowTest(TestCase):
|
||||
)
|
||||
|
||||
|
||||
@skipUnless(QApplication is not None, "当前测试环境未安装 PySide6")
|
||||
class QueuePageDeleteTest(TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.app = QApplication.instance() or QApplication([])
|
||||
cls.app.setStyleSheet(APP_QSS)
|
||||
|
||||
def test_delete_action_emits_the_full_untruncated_task_key(self):
|
||||
full_key = "d6904620be23fafcd8774af557daef1118b2b208ceb0655f62bb8d032dd8d0a072ca7bc26546f5e6"
|
||||
with tempfile.TemporaryDirectory() as folder:
|
||||
root = Path(folder)
|
||||
(root / "pending_replies.json").write_text(
|
||||
json.dumps({full_key: {"display_name": "一个小迷糊@微信", "created_at": 1}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
with mock.patch("wechat_gui_qt.SCRIPT_DIR", root):
|
||||
page = QueuePage()
|
||||
emitted = []
|
||||
page.deleteTasksRequested.connect(emitted.append)
|
||||
page.queue_table.selectRow(0)
|
||||
with mock.patch(
|
||||
"wechat_gui_qt.QMessageBox.question",
|
||||
return_value=QMessageBox.Yes,
|
||||
):
|
||||
page._request_delete_selected()
|
||||
page.deleteLater()
|
||||
self.app.processEvents()
|
||||
|
||||
self.assertEqual(emitted, [[full_key]])
|
||||
|
||||
|
||||
@skipUnless(QApplication is not None, "当前测试环境未安装 PySide6")
|
||||
class MainWindowMinimizeTest(TestCase):
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user