mirror of
https://github.com/1j01/textual-paint.git
synced 2024-12-22 06:11:37 +03:00
WIP: Add more tests
This commit is contained in:
parent
79d63b0291
commit
278490f7d5
@ -66,6 +66,8 @@ from textual_paint.windows import (CharacterSelectorDialogWindow, DialogWindow,
|
||||
|
||||
MAX_FILE_SIZE = 500000 # 500 KB
|
||||
|
||||
DOUBLE_CLICK_TIME = 0.8 # seconds; overridden in tests to avoid flakiness
|
||||
|
||||
# Most arguments are handled at the end of the file,
|
||||
# but it may be important to do this one early.
|
||||
load_language(args.language)
|
||||
@ -397,7 +399,7 @@ class CharInput(Input, inherit_bindings=False):
|
||||
if event.ctrl or event.button == 3: # right click
|
||||
self.app.action_swap_colors()
|
||||
return
|
||||
if event.time - self.last_click_time < 0.8:
|
||||
if event.time - self.last_click_time < DOUBLE_CLICK_TIME:
|
||||
self.app.action_open_character_selector()
|
||||
self.last_click_time = event.time
|
||||
|
||||
@ -446,7 +448,7 @@ class ColorsBox(Container):
|
||||
secondary = event.ctrl or event.button == 3
|
||||
self.post_message(self.ColorSelected(self.color_by_button[button], secondary))
|
||||
# Detect double click and open Edit Colors dialog.
|
||||
if event.time - self.last_click_time < 0.8 and button == self.last_click_button:
|
||||
if event.time - self.last_click_time < DOUBLE_CLICK_TIME and button == self.last_click_button:
|
||||
assert isinstance(self.app, PaintApp)
|
||||
self.app.action_edit_colors(self.query(".color_button").nodes.index(button), secondary)
|
||||
self.last_click_time = event.time
|
||||
|
@ -1,8 +1,11 @@
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from textual.pilot import Pilot
|
||||
from textual.widgets import Input
|
||||
|
||||
from textual_paint import paint
|
||||
|
||||
# These paths are treated as relative to this file.
|
||||
APPS_DIR = Path("../src/textual_paint")
|
||||
PAINT = APPS_DIR / "paint.py"
|
||||
@ -10,9 +13,12 @@ GALLERY = APPS_DIR / "gallery.py"
|
||||
|
||||
LARGER = (81, 38)
|
||||
"""Large enough to show the entire paint app."""
|
||||
LARGEST = (107, 42)
|
||||
"""Large enough to show the Edit Colors dialog, which is a bit oversized."""
|
||||
|
||||
# Prevent flaky tests due to cursor blinking
|
||||
# Prevent flaky tests due to timing issues.
|
||||
Input.cursor_blink = False
|
||||
paint.DOUBLE_CLICK_TIME = 2.0
|
||||
|
||||
@pytest.fixture(params=[
|
||||
{"theme": "light", "ascii_only": False},
|
||||
@ -61,6 +67,27 @@ def test_paint_view_bitmap(snap_compare):
|
||||
def test_paint_invert_and_exit(snap_compare, each_theme):
|
||||
assert snap_compare(PAINT, press=["ctrl+i", "ctrl+q"])
|
||||
|
||||
def test_swap_selected_colors(snap_compare):
|
||||
async def swap_selected_colors(pilot: Pilot):
|
||||
await pilot.click("CharInput", control=True)
|
||||
|
||||
assert snap_compare(PAINT, run_before=swap_selected_colors)
|
||||
|
||||
def test_paint_character_picker_dialog(snap_compare, each_theme):
|
||||
async def open_character_picker(pilot: Pilot):
|
||||
await pilot.click("CharInput")
|
||||
await pilot.click("CharInput")
|
||||
|
||||
assert snap_compare(PAINT, run_before=open_character_picker, terminal_size=LARGER)
|
||||
|
||||
def test_paint_edit_colors_dialog(snap_compare, each_theme):
|
||||
async def open_edit_colors(pilot: Pilot):
|
||||
pilot.app.query("ColorsBox Button")[0].id = "a_color_button"
|
||||
await pilot.click("#a_color_button")
|
||||
await pilot.click("#a_color_button")
|
||||
|
||||
assert snap_compare(PAINT, run_before=open_edit_colors, terminal_size=LARGEST)
|
||||
|
||||
def test_gallery_app(snap_compare):
|
||||
assert snap_compare(GALLERY)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user