test(metrics): target deltas by test id, not by glyph — #2495
test-web / test (push) Failing after 35s

Two CI failures, both in my own new tests, both informative.

settings: queryByText(/≈/) matched the LEGEND explaining the glyph rather
than a delta, so the "no delta" case failed on the explanation being
present. Delta spans now carry data-testid so a test can name what it
means instead of pattern-matching prose that sits next to it.

tuning: getByText("40%") found two elements. testing-library matches an
element and its OWN direct text nodes, so the skip cell still matches
"40%" despite the trailing play-count span — and discover late-week
completion is also 40%. Genuinely ambiguous now; assert the count.
This commit is contained in:
2026-08-06 21:14:53 -04:00
parent 481f906059
commit a094d5f8b0
3 changed files with 19 additions and 9 deletions
+9 -6
View File
@@ -269,16 +269,18 @@ describe('Settings page — Recommendation metrics card', () => {
render(SettingsPage);
await waitFor(() => expect(screen.getByText('Discover')).toBeInTheDocument());
// The indistinguishable skip delta is prefixed and explained on hover.
const skip = screen.getByText('≈-13');
expect(skip).toBeInTheDocument();
// Targeted by test id rather than text: the legend below the table also
// contains a "≈", so matching on the glyph finds the explanation instead of
// the delta. (It did, on the first attempt at this test.)
const skip = screen.getByTestId('skip-delta-discover');
expect(skip).toHaveTextContent('≈-13');
expect(skip).toHaveAttribute('title', expect.stringContaining('not distinguishable from zero'));
// It must NOT be coloured as a real regression/improvement.
expect(skip.className).toContain('opacity-60');
// The completion delta clears its margin, so it renders plainly.
const completion = screen.getByText('+28');
expect(completion).toBeInTheDocument();
const completion = screen.getByTestId('completion-delta-discover');
expect(completion).toHaveTextContent('+28');
expect(completion.className).not.toContain('opacity-60');
// And the legend explains the glyph rather than leaving it a mystery.
@@ -303,7 +305,8 @@ describe('Settings page — Recommendation metrics card', () => {
};
render(SettingsPage);
await waitFor(() => expect(screen.getByText('Radio')).toBeInTheDocument());
expect(screen.queryByText(/≈/)).not.toBeInTheDocument();
expect(screen.queryByTestId('skip-delta-radio')).not.toBeInTheDocument();
expect(screen.queryByTestId('completion-delta-radio')).not.toBeInTheDocument();
});
test('surfaces without a breakdown render no toggle and no sub-rows', async () => {