Improve code coverage for cli package (#13724)

This commit is contained in:
Megha Bansal
2025-11-24 23:11:46 +05:30
committed by GitHub
parent 569c6f1dd0
commit 95693e265e
47 changed files with 5115 additions and 489 deletions
+24 -29
View File
@@ -78,38 +78,33 @@ describe('ApiAuthDialog', () => {
);
});
it('calls onSubmit when the text input is submitted', () => {
mockBuffer.text = 'submitted-key';
render(<ApiAuthDialog onSubmit={onSubmit} onCancel={onCancel} />);
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
keypressHandler({
name: 'return',
it.each([
{
keyName: 'return',
sequence: '\r',
ctrl: false,
meta: false,
shift: false,
paste: false,
});
expectedCall: onSubmit,
args: ['submitted-key'],
},
{ keyName: 'escape', sequence: '\u001b', expectedCall: onCancel, args: [] },
])(
'calls $expectedCall.name when $keyName is pressed',
({ keyName, sequence, expectedCall, args }) => {
mockBuffer.text = 'submitted-key'; // Set for the onSubmit case
render(<ApiAuthDialog onSubmit={onSubmit} onCancel={onCancel} />);
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
expect(onSubmit).toHaveBeenCalledWith('submitted-key');
});
keypressHandler({
name: keyName,
sequence,
ctrl: false,
meta: false,
shift: false,
paste: false,
});
it('calls onCancel when the text input is cancelled', () => {
render(<ApiAuthDialog onSubmit={onSubmit} onCancel={onCancel} />);
const keypressHandler = mockedUseKeypress.mock.calls[0][0];
keypressHandler({
name: 'escape',
sequence: '\u001b',
ctrl: false,
meta: false,
shift: false,
paste: false,
});
expect(onCancel).toHaveBeenCalled();
});
expect(expectedCall).toHaveBeenCalledWith(...args);
},
);
it('displays an error message', () => {
const { lastFrame } = render(