MOBILE-4081 core: Fix cancelling textarea prompts

main
Noel De Martin 2022-11-24 13:14:39 +01:00
parent c94785a94f
commit b95182cbf9
2 changed files with 31 additions and 0 deletions

View File

@ -18,6 +18,7 @@ import { AlertController, Translate } from '@singletons';
import { mock, mockSingleton, mockTranslate } from '@/testing/utils';
import { CoreSiteError } from '@classes/errors/siteerror';
import { CoreSites } from '@services/sites';
import { OverlayEventDetail } from '@ionic/core';
describe('CoreDomUtilsProvider', () => {
@ -56,4 +57,30 @@ describe('CoreDomUtilsProvider', () => {
});
});
it('ignores alert inputs on cancel', async () => {
// Arrange.
const mockAlert = mock<HTMLIonAlertElement>({
present: () => Promise.resolve(),
onWillDismiss: () => Promise.resolve({
data: {
values: {
'textarea-prompt': 'Not empty!',
},
},
role: 'cancel',
} as OverlayEventDetail<any>), // eslint-disable-line @typescript-eslint/no-explicit-any
});
mockSingleton(AlertController, mock({ create: () => Promise.resolve(mockAlert) }));
// Act.
const result = await domUtils.showTextareaPrompt('Age', 'How old are you?', [
{ text: 'Cancel', role: 'cancel' },
{ text: 'Save' },
]);
// Assert.
expect(result).toBeUndefined();
});
});

View File

@ -1659,6 +1659,10 @@ export class CoreDomUtilsProvider {
const result = await alert.onWillDismiss();
if (result.role === 'cancel') {
return;
}
return result.data?.values?.['textarea-prompt'];
}