Skip to content

Commit 26a3f40

Browse files
committed
Add MorphemeBox coverage for non-first form cell clicks
Prior tests only exercised the first (button) form cell; the span cells' click and mousedown-bubbling behavior had no coverage.
1 parent 6dcb77a commit 26a3f40

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

src/__tests__/components/MorphemeBox.test.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/// <reference types="@testing-library/jest-dom" />
44

55
import { useLocalizedStrings } from '@papi/frontend/react';
6-
import { render, screen } from '@testing-library/react';
6+
import { fireEvent, render, screen } from '@testing-library/react';
77
import userEvent from '@testing-library/user-event';
88
import type { MorphemeAnalysis, Token } from 'interlinearizer';
99
import * as AnalysisStore from '../../components/AnalysisStore';
@@ -118,6 +118,36 @@ describe('MorphemeBox', () => {
118118
expect(onEditBreakdown).toHaveBeenCalledTimes(1);
119119
});
120120

121+
it('calls onEditBreakdown when a non-first form cell is clicked', async () => {
122+
// Non-first cells are spans, not buttons, so they need their own coverage.
123+
const onEditBreakdown = jest.fn();
124+
renderBox({ onEditBreakdown });
125+
await userEvent.click(screen.getByText('-lo'));
126+
expect(onEditBreakdown).toHaveBeenCalledTimes(1);
127+
});
128+
129+
it('stops a non-first form cell mousedown from bubbling to an ancestor handler', () => {
130+
// Regression test: an ancestor onMouseDown (e.g. TokenChip's label) would otherwise focus the
131+
// gloss input, since a span (unlike a button) doesn't match its input/button guard.
132+
const onAncestorMouseDown = jest.fn();
133+
render(
134+
// Stand-in for an ancestor React handler, not real UI.
135+
// eslint-disable-next-line jsx-a11y/no-static-element-interactions
136+
<div onMouseDown={onAncestorMouseDown}>
137+
<MorphemeBox
138+
analysisLanguage="en"
139+
disabled={false}
140+
morphemes={MORPHEMES}
141+
onEditBreakdown={jest.fn()}
142+
popoverOpen={false}
143+
token={WORD_TOKEN}
144+
/>
145+
</div>,
146+
);
147+
fireEvent.mouseDown(screen.getByText('-lo'));
148+
expect(onAncestorMouseDown).not.toHaveBeenCalled();
149+
});
150+
121151
it('does not call onEditBreakdown when disabled', async () => {
122152
const onEditBreakdown = jest.fn();
123153
renderBox({ disabled: true, onEditBreakdown });

0 commit comments

Comments
 (0)