Commit Graph

36 Commits

Author SHA1 Message Date
Isaiah Odhner
81ea6867c0 Add snapshot test for loading a PNG file
This regressed previously. Never again!
2024-11-05 11:08:20 -05:00
Isaiah Odhner
dcfb05c58a Use a separate folder for ANSI art for tests; add more gallery tests 2024-11-05 09:07:40 -05:00
Isaiah Odhner
0a0d509cd2 Update test snapshots
I added another ANSI art sample, which now shows up in the gallery app's
snapshot, invalidating the test. Maybe I should stop adding sample art.
Or better yet, I should create a separate folder with just two files
so that I can add sample art freely without breaking the tests:
  - one file that's small and centered
  - one file that's large with scrollbars

`pytest --snapshot-update`
2024-11-05 07:27:52 -05:00
Isaiah Odhner
f85e161e9e Test fill tool on a spiral 2023-09-22 13:16:16 -04:00
Isaiah Odhner
fae2c216f0 Optimize Color and Style construction in Canvas
This does not change anything visually, but the snapshots are changed
because the IDs use a hash which includes color names, and the color
names changed from rgb() style to hex.
2023-09-21 20:36:09 -04:00
Isaiah Odhner
cd3137a737 Use new Collapsible widget for error details 2023-09-18 23:43:59 -04:00
Isaiah Odhner
35a6845ab5 Update textual to 0.33.0
I had to fix the layout of a few dialogs where elements decided they
wanted to start expanding a lot more than before.
I'm guessing this has to do with the changelog entry:
    "Fixed relative units not always expanding auto containers"
    https://github.com/Textualize/textual/pull/3059

The snapshot changes are basically bogus. The before and after are
visually identical, with the difference view showing all black.

Since there were a lot of switches to toggle and I had to wait for the
snapshot tests to run (slow!), I wrote a little automation to toggle
"Show difference" for all the results:

    document.querySelectorAll("#flexSwitchCheckDefault").forEach((element)=> element.click())

It would be good to have this ability in the snapshot report UI itself,
maybe even replacing the individual toggles, although I'm not sure about
that, especially since it might be laggy toggling the blend modes with
a lot of test results. (I suppose if that was really an issue, it could
toggle all the visible test results and then toggle others as they come
into view, though that's a bit more complex.)

As for understanding the structural changes to the snapshots, I tried
making a visualization using hue, coloring according to the position
of a rect within the list of rects:

    const richTerminals = document.querySelectorAll(".rich-terminal");
    
    richTerminals.forEach(function(terminal) {
        const rectElements = terminal.querySelectorAll("rect");
        
        rectElements.forEach(function(rect, index) {
            const fraction = index / (rectElements.length - 1);
            const cycles = 40;
            const hue = fraction * cycles * 360;
            rect.style.fill = `hsl(${hue}, 100%, 50%)`;
        });
    });

This shows some difference, but it isn't very elucidating, since the
structural changes only show as gradual shifts in the hue, and affect
other rects even if said rects are identical, so it's subtle and messy.

Coloring based on a hash proves to actually highlight differences:

    const richTerminals = document.querySelectorAll(".rich-terminal");
    
    richTerminals.forEach(function(terminal) {
        const rectElements = terminal.querySelectorAll("rect");
        
        rectElements.forEach(function(rect, index) {
            const hash = hash(rect.outerHTML);
            const hue = (hash % 360 + 360) % 360;
            rect.style.fill = `hsl(${hue}, 100%, 50%)`;
        });
    });
    
    function hash(s) {
        let hash = 0;
        for (let i = 0; i < s.length; i++) {
            const char = s.charCodeAt(i);
            hash = (hash << 5) - hash + char;
        }
        return hash;
    }

As for analyzing the differences now visible, eh, "maybe later."
2023-09-18 01:08:22 -04:00
Isaiah Odhner
28d9a2ff04 Update textual to 0.29.0
This only slightly affects the exact lightness of the grayed out radio button labels, at least as far as the tests cover.
2023-09-17 00:56:21 -04:00
Isaiah Odhner
0f617dd8c4 Dynamically theme message box icons 2023-09-15 22:03:34 -04:00
Isaiah Odhner
7a13659d48 Fix "Show Details" not changing to "Hide Details" when expanding error 2023-09-15 20:44:40 -04:00
Isaiah Odhner
40291f29fd Add fake folders to mask OS differences in snapshot tests
Now the tests pass on macOS, not just Ubuntu. Not sure about Windows.
2023-09-15 17:08:13 -04:00
Isaiah Odhner
ad39f34084 Add Polygon test with dragging 2023-09-14 16:58:47 -04:00
Isaiah Odhner
5a7ba995c0 Accept super trivial change to About dialog snapshots
The scrollbar handle is slightly taller now because I removed the `--recode-samples` option.
2023-09-13 02:37:37 -04:00
Isaiah Odhner
1f1bf577f2 Disable tool icon swaps when running in pytest 2023-09-12 21:08:24 -04:00
Isaiah Odhner
96fe28269d Accept changes to file dialog snapshots
...but NOT the Free-Form Select test! I'm noticing that when marked
as skipped, running with --snapshot-update deletes the snapshot.
So neither xfail or skip (or xfail with run=False) is a good solution.
It's almost as if people don't normally do TDD with snapshots.

Anyways, HOPEFULLY I can move on now, to actually fixing things,
like the Polygon tool, and new bugs I've found while adding tests.
2023-09-12 19:45:41 -04:00
Isaiah Odhner
bb8e968f6c Test Free-Form Select off-screen melding bug 2023-09-12 19:45:41 -04:00
Isaiah Odhner
48b15319da Test Select tool 2023-09-11 22:42:10 -04:00
Isaiah Odhner
2206df20bd Test Free-Form Select tool 2023-09-11 22:37:30 -04:00
Isaiah Odhner
ec774c264a Test Polygon tool! 2023-09-11 22:11:02 -04:00
Isaiah Odhner
7f379103a6 Accept new Text tool test snapshots 2023-09-11 19:35:04 -04:00
Isaiah Odhner
3b76ba0997 Accept mysterious ID changes to file dialog snapshots
WITHOUT accepting new WIP Polygon and Text tool tests
2023-09-11 18:45:21 -04:00
Isaiah Odhner
2e89e73f37 Fix About Paint dialog test failing due to version string changes
Make version info static when running in pytest.

I also tried adding in test_snapshots.py:

    import textual_paint
    textual_paint.__version__ = "snapshot test edition 1"

    import textual_paint.__init__ as init
    init.__version__ = "snapshot test edition 2"

which seemed to have no effect.

Since I already have special case logic for __version__ in __init__.py,
I'm reasonably happy with this solution.
2023-09-09 00:19:39 -04:00
Isaiah Odhner
3cc70b6e4d Test About Paint dialog 2023-09-08 22:46:52 -04:00
Isaiah Odhner
ea5ca0c90f Fix flaky test due to pressed style of Show Details button 2023-09-08 22:40:49 -04:00
Isaiah Odhner
c5353f4e7b Test custom zoom dialog 2023-09-08 22:32:53 -04:00
Isaiah Odhner
628170d213 Test error dialog
It's pretty ridiculous in the expanded state, but better to show it.
Also, the button text isn't switching to "Hide Details".
2023-09-08 22:32:53 -04:00
Isaiah Odhner
faa9cefe85 Test expand canvas dialog 2023-09-08 21:40:29 -04:00
Isaiah Odhner
ed679ab721 Accept snapshots for new tests 2023-09-08 21:29:54 -04:00
Isaiah Odhner
18c38fd3e0 Merge snapshot results for ASCII-only and Unicode UI tests
I'm basically doing TDD to snapshot testing!
I'm creating tests that don't pass yet, setting up an expectation
that the app match the given screenshots, which is funny in a nice
"improper hierarchy" sort of way, but it's possible because I do
actually have the app rendering how I want, just only in isolation.
If I run the ascii_only tests by themselves, I can get good results
from them, but running them interwoven with default Unicode-using UI
tests doesn't work yet, since the ASCII-only mode permanently changes
how certain widgets render, for the life of the process, so that's
what I'm applying TDD to: making it toggleable at runtime.

I commented out the Unicode tests, and uncommented the ASCII-only tests,
renamed test_snapshots.ambr to test_snapshots_ascii.ambr,
reverted the changes to test_snapshots.ambr to get the Unicode version,
ran my new merge_ambr.py script to join the sets of snapshots,
then replaced test_snapshots.ambr with test_snapshots_merged.ambr
Finally, I uncommented both sets of tests, and I'm ready to do TDD!
2023-09-08 14:44:56 -04:00
Isaiah Odhner
8a4ca8d380 Fix toggling light/dark mode not affecting file/folder icons in tree
I already fixed my first bug caught by the snapshot testing!
These variables were intended as constants, but were being mutated.
I recall writing it as `prefix = (...).stylize_before(...)` and then
moving it to a new line when I realized it was mutation-style method,
not so much the chaining-style factory that I wanted, but I conceived
of it too much as a stylistic distinction in the moment, looking back.
Mutation style means mutation!

Side note: tests also showed a spurious change of a cursor blinking.
I don't really know whether that's in this changeset or not, because
the workflow involves re-running the tests to update the baseline, and
the nice visual diffs provided in the snapshot report aren't available
when viewing the commit diff.
1. If the SVGs were separate files, I could see the diffs on GitHub
   or in GitHub Desktop, and maybe some other Git clients.
   It would also make it a lot easier to simply view the baselines,
   which is useful in general.
2. It would be nice if built-in components didn't cause spurious diffs,
   including the Input's cursor blinking and the Header's clock ticking.
   I already removed the clock from my gallery app, because it's a sort
   of trivial decision, but Inputs I'll have to reckon with.
2023-09-08 02:31:54 -04:00
Isaiah Odhner
f09f5fbf55 Test light and dark theme variations with a pytest fixture
First I tried setting PYTEST_TEXTUAL_PAINT_ARGS as an environment variable, to be interpreted by args.py, but it turns out args.py is only executed once, not once per test. It's not using subprocesses, only importing and reimporting the app code, and instantiating new App instances, so parts of the code that are at the top level of modules is only evaluated once.

So I found a new strategy, of importing the `args` object in the test fixture and modifying it directly.

I also realized the --ascii-only option permanently modifies Textual's widgets and borders, and my own widgets, for the life of the process, so I'm holding off on that one. I should be able to make --ascii-only mode more dynamic, and could even target it as a runtime toggle, as a goal, since that's basically what I'll need to achieve to get it working for the tests, but thinking of it as a feature is more fun.
2023-09-08 02:18:48 -04:00
Isaiah Odhner
11939b6603 Resize screenshots for some tests 2023-09-07 17:46:48 -04:00
Isaiah Odhner
7d88cbe44f Rename test to match 2023-09-07 17:23:35 -04:00
Isaiah Odhner
f8f2d5ea01 Add snapshot tests for more keyboard-accessible dialogs 2023-09-07 17:22:34 -04:00
Isaiah Odhner
ca23a7712c Remove clock from gallery app
I don't feel like trying to figure out how to spoof the time for snapshot testing.
2023-09-07 16:53:31 -04:00
Isaiah Odhner
bcfddbe2fa Add first baseline for visual regression testing
It works!
2023-09-07 16:41:59 -04:00