aboutsummaryrefslogtreecommitdiffstats
path: root/test_llamachat.py
diff options
context:
space:
mode:
Diffstat (limited to 'test_llamachat.py')
-rwxr-xr-xtest_llamachat.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/test_llamachat.py b/test_llamachat.py
index 7a84608..407c5dc 100755
--- a/test_llamachat.py
+++ b/test_llamachat.py
@@ -501,6 +501,10 @@ def test_code_block_copy_links():
fragment = _markdown_to_fragment(markdown, 3)
assert _re.findall(r"x-llamachat-copy:([0-9.]+)", fragment) == ["3.0", "3.1"]
+ # Icon only, and under its block: Qt cannot float it over the tint.
+ assert "⧉" in fragment and "copy<" not in fragment
+ assert fragment.rindex("⧉") > fragment.rindex("</pre>")
+
# The indices the links carry must select the blocks the parser found.
blocks = _code_blocks(_close_fences(markdown))
assert blocks == ["AAA", "BBB"], blocks
@@ -518,6 +522,49 @@ def test_code_block_copy_links():
print("ok code block copy links")
+def test_code_block_copy_states():
+ """The copy link dims, lights on hover, and ticks once used."""
+ import os
+
+ os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
+ from PySide6.QtWidgets import QApplication
+
+ from llamachat.ui import _PRE_SPACER, _markdown_to_fragment
+
+ app = QApplication.instance() or QApplication([])
+ assert app is not None
+
+ markdown = "```py\nAAA\n```\n"
+
+ def link_style(fragment: str, glyph: str) -> str:
+ return fragment.split(glyph)[0].rsplit("<a", 1)[1]
+
+ # Grey by default, so a transcript full of code is not a wall of
+ # buttons. The pill is what makes it read as a control at all.
+ plain = _markdown_to_fragment(markdown, 0)
+ assert "rgba(127,127,127,0.28)" in link_style(plain, "⧉")
+
+ # Qt rich text has no :hover, so hovering is a re-render with the
+ # highlighted anchor passed back in.
+ hovered = _markdown_to_fragment(markdown, 0, hovered="0.0")
+ assert "palette(highlight)" in link_style(hovered, "⧉")
+
+ # A different link being hovered must not light this one.
+ other = _markdown_to_fragment(markdown, 0, hovered="0.1")
+ assert "rgba(127,127,127,0.28)" in link_style(other, "⧉")
+
+ # After copying, the icon becomes a tick on green, so the confirmation
+ # is visible without a status message.
+ copied = _markdown_to_fragment(markdown, 0, copied="0.0")
+ assert "✓" in copied and "⧉" not in copied
+ assert "#2e9e4f" in link_style(copied, "✓")
+
+ # Qt draws no padding on <pre>, so a tinted spacer stands in above and
+ # below; without it the tint sits flush against the code.
+ assert plain.count(_PRE_SPACER) == 2
+ print("ok code block copy states")
+
+
def test_system_qt_theme_guard():
"""The plugin path is only borrowed when the Qt versions agree."""
import os
@@ -3339,4 +3386,5 @@ if __name__ == "__main__":
test_title_prompt()
test_code_block_wrapping()
test_code_block_copy_links()
+ test_code_block_copy_states()
print("\nall checks passed")