Fix double "esc" bug in Auth dialog (#3493)
This commit is contained in:
parent
426b6905da
commit
4e84989d8f
|
@ -45,9 +45,7 @@ describe('AuthDialog', () => {
|
||||||
const onSelect = vi.fn();
|
const onSelect = vi.fn();
|
||||||
const settings: LoadedSettings = new LoadedSettings(
|
const settings: LoadedSettings = new LoadedSettings(
|
||||||
{
|
{
|
||||||
settings: {
|
settings: {},
|
||||||
selectedAuthType: undefined,
|
|
||||||
},
|
|
||||||
path: '',
|
path: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -74,6 +72,40 @@ describe('AuthDialog', () => {
|
||||||
unmount();
|
unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not exit if there is already an error message', async () => {
|
||||||
|
const onSelect = vi.fn();
|
||||||
|
const settings: LoadedSettings = new LoadedSettings(
|
||||||
|
{
|
||||||
|
settings: {},
|
||||||
|
path: '',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
settings: {},
|
||||||
|
path: '',
|
||||||
|
},
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
|
||||||
|
const { lastFrame, stdin, unmount } = render(
|
||||||
|
<AuthDialog
|
||||||
|
onSelect={onSelect}
|
||||||
|
settings={settings}
|
||||||
|
initialErrorMessage="Initial error"
|
||||||
|
/>,
|
||||||
|
);
|
||||||
|
await wait();
|
||||||
|
|
||||||
|
expect(lastFrame()).toContain('Initial error');
|
||||||
|
|
||||||
|
// Simulate pressing escape key
|
||||||
|
stdin.write('\u001b'); // ESC key
|
||||||
|
await wait();
|
||||||
|
|
||||||
|
// Should not call onSelect
|
||||||
|
expect(onSelect).not.toHaveBeenCalled();
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
it('should allow exiting when auth method is already selected', async () => {
|
it('should allow exiting when auth method is already selected', async () => {
|
||||||
const onSelect = vi.fn();
|
const onSelect = vi.fn();
|
||||||
const settings: LoadedSettings = new LoadedSettings(
|
const settings: LoadedSettings = new LoadedSettings(
|
||||||
|
|
|
@ -66,6 +66,11 @@ export function AuthDialog({
|
||||||
|
|
||||||
useInput((_input, key) => {
|
useInput((_input, key) => {
|
||||||
if (key.escape) {
|
if (key.escape) {
|
||||||
|
// Prevent exit if there is an error message.
|
||||||
|
// This means they user is not authenticated yet.
|
||||||
|
if (errorMessage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (settings.merged.selectedAuthType === undefined) {
|
if (settings.merged.selectedAuthType === undefined) {
|
||||||
// Prevent exiting if no auth method is set
|
// Prevent exiting if no auth method is set
|
||||||
setErrorMessage(
|
setErrorMessage(
|
||||||
|
|
Loading…
Reference in New Issue