|
3 | 3 | /// <reference types="@testing-library/jest-dom" /> |
4 | 4 |
|
5 | 5 | import { useLocalizedStrings } from '@papi/frontend/react'; |
6 | | -import { render, screen } from '@testing-library/react'; |
| 6 | +import { fireEvent, render, screen } from '@testing-library/react'; |
7 | 7 | import userEvent from '@testing-library/user-event'; |
8 | 8 | import type { MorphemeAnalysis, Token } from 'interlinearizer'; |
9 | 9 | import * as AnalysisStore from '../../components/AnalysisStore'; |
@@ -118,6 +118,36 @@ describe('MorphemeBox', () => { |
118 | 118 | expect(onEditBreakdown).toHaveBeenCalledTimes(1); |
119 | 119 | }); |
120 | 120 |
|
| 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 | + |
121 | 151 | it('does not call onEditBreakdown when disabled', async () => { |
122 | 152 | const onEditBreakdown = jest.fn(); |
123 | 153 | renderBox({ disabled: true, onEditBreakdown }); |
|
0 commit comments