From 5bfcd138b5f29e0ab1a0bdac1e7e2588906b0b0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Mon, 29 Jan 2024 16:45:40 +0000 Subject: [PATCH 01/22] [fix](alert): call pressed button handler, regardless 'role' --- core/src/components/alert/alert.tsx | 8 +++-- .../components/alert/test/basic/index.html | 31 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/core/src/components/alert/alert.tsx b/core/src/components/alert/alert.tsx index 90a1c281bbf..d43b29d5343 100644 --- a/core/src/components/alert/alert.tsx +++ b/core/src/components/alert/alert.tsx @@ -461,8 +461,9 @@ export class Alert implements ComponentInterface, OverlayInterface { private async buttonClick(button: AlertButton) { const role = button.role; + const hasHandler = button.handler !== undefined; const values = this.getValues(); - if (isCancel(role)) { + if (isCancel(role) && hasHandler === false) { return this.dismiss({ values }, role); } const returnData = await this.callButtonHandler(button, values); @@ -669,9 +670,10 @@ export class Alert implements ComponentInterface, OverlayInterface { }; private dispatchCancelHandler = (ev: CustomEvent) => { - const role = ev.detail.role; + const button = ev.detail; + const role = button.role; if (isCancel(role)) { - const cancelButton = this.processedButtons.find((b) => b.role === 'cancel'); + const cancelButton = this.processedButtons.find((b) => (b === button && b.role === 'cancel')); this.callButtonHandler(cancelButton); } }; diff --git a/core/src/components/alert/test/basic/index.html b/core/src/components/alert/test/basic/index.html index 74a6f6c68d2..a72a64cc455 100644 --- a/core/src/components/alert/test/basic/index.html +++ b/core/src/components/alert/test/basic/index.html @@ -31,13 +31,13 @@ + - @@ -35,7 +36,7 @@ Multiple Buttons - + Multiple Cancel Buttons @@ -49,10 +50,16 @@ window.addEventListener('ionToastDidDismiss', function (e) { console.log('didDismiss', e); }); + window.addEventListener('ionToastWillDismiss', function (e) { console.log('willDismiss', e); }); + async function openAlert(opts) { + const alert = await alertController.create(opts); + await alert.present(); + } + async function presentCloseArrayToast() { const opts = { message: 'Are you sure you want to delete this?', @@ -122,32 +129,44 @@ return await presentToastWithOptions(opts); } + function confirmpAlertCancelBtns(expectedDataTestId) { + openAlert({ + header: 'Alert', + subHeader: 'CancelBtnClicked', + message: expectedDataTestId, + buttons: ['OK'], + htmlAttributes: { + 'data-testid': expectedDataTestId, + }, + }); + } + async function presentToastWithMultipleCancelButtons() { const opts = { message: 'Warning.', buttons: [ { - text: 'Cancel', - side: 'start', + text: 'C1', role: 'cancel', + cssClass: 'cancel1-btn', handler: () => { - console.log('Cancel btn'); + confirmpAlertCancelBtns('cancel1-btn-clicked'); }, }, { - text: 'Cancel1', + text: 'C2', role: 'cancel', + cssClass: 'cancel2-btn', handler: () => { - console.log('Cancel1 btn'); + confirmpAlertCancelBtns('cancel2-btn-clicked'); }, }, { - text: 'Cancel2', + text: 'C3', role: 'cancel', - handler: () => { - console.log('Cancel2 btn'); - }, + cssClass: 'cancel3-btn', }, + 'Cancel', ], }; diff --git a/core/src/components/toast/test/buttons/toast.e2e.ts b/core/src/components/toast/test/buttons/toast.e2e.ts new file mode 100644 index 00000000000..aa1afb28c08 --- /dev/null +++ b/core/src/components/toast/test/buttons/toast.e2e.ts @@ -0,0 +1,91 @@ +import type { Locator } from '@playwright/test'; +import { expect } from '@playwright/test'; +import type { E2EPage, E2EPageOptions, ScreenshotFn, EventSpy } from '@utils/test/playwright'; +import { configs, test } from '@utils/test/playwright'; + +class ToastFixture { + readonly page: E2EPage; + + private ionToastDidPresent!: EventSpy; + private ionToastDidDismiss!: EventSpy; + + constructor(page: E2EPage) { + this.page = page; + } + + async goto(config: E2EPageOptions) { + const { page } = this; + await page.goto(`/src/components/toast/test/buttons`, config); + this.ionToastDidPresent = await page.spyOnEvent('ionToastDidPresent'); + this.ionToastDidDismiss = await page.spyOnEvent('ionToastDidDismiss'); + } + + async openToast(selector: string) { + const { page, ionToastDidPresent } = this; + const button = page.locator(selector); + await button.click(); + + await ionToastDidPresent.next(); + + return { + toast: page.locator('ion-toast'), + container: page.locator('ion-toast .toast-container'), + }; + } + + async screenshot(screenshotModifier: string, screenshot: ScreenshotFn, el?: Locator) { + const { page } = this; + + const screenshotString = screenshot(`toast-${screenshotModifier}`); + + if (el === undefined) { + await expect(page).toHaveScreenshot(screenshotString); + } else { + await expect(el).toHaveScreenshot(screenshotString); + } + } +} + +configs().forEach(({ title, screenshot, config }) => { + test.describe(title('toast: position rendering'), () => { + let toastFixture: ToastFixture; + + test.beforeEach(async ({ page }) => { + toastFixture = new ToastFixture(page); + await toastFixture.goto(config); + }); + + test('cancel button 1', async ({ page }) => { + await toastFixture.openToast('#multipleCancelButtons'); + const optBtn1 = page.locator('ion-toast button.cancel1-btn'); + await optBtn1.click(); + const confirmOptBtn1Alert = page.locator('ion-alert[data-testid=cancel1-btn-clicked]'); + const optBtn1AlertInfo = confirmOptBtn1Alert.locator('.alert-message').innerText(); + const optBtn1AlertOkBtn = confirmOptBtn1Alert.locator('.alert-button-group button'); + expect(await optBtn1AlertInfo).toBe('cancel1-btn-clicked'); + await optBtn1AlertOkBtn.click(); + }); + + test('cancel button 2', async ({ page }) => { + await toastFixture.openToast('#multipleCancelButtons'); + const optBtn2 = page.locator('ion-toast button.cancel2-btn'); + await optBtn2.click(); + const confirmOptBtn2Alert = page.locator('ion-alert[data-testid=cancel2-btn-clicked]'); + const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); + const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); + expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); + await optBtn2AlertOkBtn.click(); + }); + + test('cancel button 3', async ({ page }) => { + await toastFixture.openToast('#multipleCancelButtons'); + const ionToastDidDismiss = await page.spyOnEvent('ionToastDidDismiss'); + const optBtn3 = page.locator('ion-toast button.cancel3-btn'); + await optBtn3.click(); + await ionToastDidDismiss.next(); + expect(ionToastDidDismiss).toHaveReceivedEventDetail({ data: { values: undefined }, role: 'cancel' }); + }); + + }); + +}); \ No newline at end of file From f01cabe97f248672cdec4ee215f1b2d339d85513 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Wed, 13 Mar 2024 11:14:39 +0000 Subject: [PATCH 17/22] [fix](toast): Removed unused property. --- core/src/components/toast/test/buttons/toast.e2e.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/components/toast/test/buttons/toast.e2e.ts b/core/src/components/toast/test/buttons/toast.e2e.ts index aa1afb28c08..c9d1b4b5fd9 100644 --- a/core/src/components/toast/test/buttons/toast.e2e.ts +++ b/core/src/components/toast/test/buttons/toast.e2e.ts @@ -7,7 +7,6 @@ class ToastFixture { readonly page: E2EPage; private ionToastDidPresent!: EventSpy; - private ionToastDidDismiss!: EventSpy; constructor(page: E2EPage) { this.page = page; @@ -17,7 +16,6 @@ class ToastFixture { const { page } = this; await page.goto(`/src/components/toast/test/buttons`, config); this.ionToastDidPresent = await page.spyOnEvent('ionToastDidPresent'); - this.ionToastDidDismiss = await page.spyOnEvent('ionToastDidDismiss'); } async openToast(selector: string) { From b0910ed1987915433af2ee188dce482c922a21ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Wed, 13 Mar 2024 11:26:46 +0000 Subject: [PATCH 18/22] [fix](toast): Fixed test issues and add screenshots. --- core/src/components/toast/test/buttons/toast.e2e.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/components/toast/test/buttons/toast.e2e.ts b/core/src/components/toast/test/buttons/toast.e2e.ts index c9d1b4b5fd9..27800ee9168 100644 --- a/core/src/components/toast/test/buttons/toast.e2e.ts +++ b/core/src/components/toast/test/buttons/toast.e2e.ts @@ -52,7 +52,7 @@ configs().forEach(({ title, screenshot, config }) => { toastFixture = new ToastFixture(page); await toastFixture.goto(config); }); - + test('cancel button 1', async ({ page }) => { await toastFixture.openToast('#multipleCancelButtons'); const optBtn1 = page.locator('ion-toast button.cancel1-btn'); @@ -61,6 +61,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn1AlertInfo = confirmOptBtn1Alert.locator('.alert-message').innerText(); const optBtn1AlertOkBtn = confirmOptBtn1Alert.locator('.alert-button-group button'); expect(await optBtn1AlertInfo).toBe('cancel1-btn-clicked'); + await toastFixture.screenshot('cancelBtn1', screenshot); await optBtn1AlertOkBtn.click(); }); @@ -72,6 +73,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); + await toastFixture.screenshot('cancelBtn2', screenshot); await optBtn2AlertOkBtn.click(); }); @@ -81,9 +83,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn3 = page.locator('ion-toast button.cancel3-btn'); await optBtn3.click(); await ionToastDidDismiss.next(); - expect(ionToastDidDismiss).toHaveReceivedEventDetail({ data: { values: undefined }, role: 'cancel' }); + expect(ionToastDidDismiss).toHaveReceivedEventDetail({ data: undefined, role: 'cancel' }); }); - }); - -}); \ No newline at end of file +}); From d05e653b2391a74506a4eebd22fb50be3f91d2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Wed, 13 Mar 2024 11:39:26 +0000 Subject: [PATCH 19/22] [fix](alert): Added screenshot test. --- core/src/components/alert/test/basic/alert.e2e.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/components/alert/test/basic/alert.e2e.ts b/core/src/components/alert/test/basic/alert.e2e.ts index e47c4985c67..f9664109ef8 100644 --- a/core/src/components/alert/test/basic/alert.e2e.ts +++ b/core/src/components/alert/test/basic/alert.e2e.ts @@ -152,6 +152,7 @@ configs().forEach(({ config, screenshot, title }) => { const optBtn1AlertInfo = confirmOptBtn1Alert.locator('.alert-message').innerText(); const optBtn1AlertOkBtn = confirmOptBtn1Alert.locator('.alert-button-group button'); expect(await optBtn1AlertInfo).toBe('cancel1-btn-clicked'); + await alertFixture.screenshot('alertCancelBtn1'); await optBtn1AlertOkBtn.click(); }); @@ -163,6 +164,7 @@ configs().forEach(({ config, screenshot, title }) => { const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); + await alertFixture.screenshot('alertCancelBtn2'); await optBtn2AlertOkBtn.click(); }); From 6ce83c496acad812858e8e2725edffb3a845303e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Wed, 13 Mar 2024 11:39:37 +0000 Subject: [PATCH 20/22] [fix](picker): Added screenshot test. --- core/src/components/picker/test/basic/picker.e2e.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/components/picker/test/basic/picker.e2e.ts b/core/src/components/picker/test/basic/picker.e2e.ts index 2e6ee24ed91..a984eb17d42 100644 --- a/core/src/components/picker/test/basic/picker.e2e.ts +++ b/core/src/components/picker/test/basic/picker.e2e.ts @@ -26,7 +26,7 @@ configs().forEach(({ title, screenshot, config }) => { }); }); - test.describe(title('Test cancel buttons'), () => { + test.describe(title('Test cancel buttons'), () => { test('cancel button 1', async ({ page }) => { await page.goto('/src/components/picker/test/basic', config); await page.click('#basicMultipleCancelBtns'); @@ -36,6 +36,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn1AlertInfo = confirmOptBtn1Alert.locator('.alert-message').innerText(); const optBtn1AlertOkBtn = confirmOptBtn1Alert.locator('.alert-button-group button'); expect(await optBtn1AlertInfo).toBe('cancel1-btn-clicked'); + await expect(page).toHaveScreenshot(screenshot(`pickerCancelBtn1`)); await optBtn1AlertOkBtn.click(); }); @@ -48,6 +49,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); + await expect(page).toHaveScreenshot(screenshot(`pickerCancelBtn2`)); await optBtn2AlertOkBtn.click(); }); From bbd9cda1885fb063b0067e03a9be875ff9989de3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Rio?= Date: Wed, 13 Mar 2024 11:40:15 +0000 Subject: [PATCH 21/22] [fix](toast): Fixed screenshot and test names. --- core/src/components/toast/test/buttons/toast.e2e.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/components/toast/test/buttons/toast.e2e.ts b/core/src/components/toast/test/buttons/toast.e2e.ts index 27800ee9168..bc6ce55b112 100644 --- a/core/src/components/toast/test/buttons/toast.e2e.ts +++ b/core/src/components/toast/test/buttons/toast.e2e.ts @@ -45,7 +45,7 @@ class ToastFixture { } configs().forEach(({ title, screenshot, config }) => { - test.describe(title('toast: position rendering'), () => { + test.describe(title('Test cancel buttons'), () => { let toastFixture: ToastFixture; test.beforeEach(async ({ page }) => { @@ -61,7 +61,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn1AlertInfo = confirmOptBtn1Alert.locator('.alert-message').innerText(); const optBtn1AlertOkBtn = confirmOptBtn1Alert.locator('.alert-button-group button'); expect(await optBtn1AlertInfo).toBe('cancel1-btn-clicked'); - await toastFixture.screenshot('cancelBtn1', screenshot); + await toastFixture.screenshot('toastCancelBtn1', screenshot); await optBtn1AlertOkBtn.click(); }); @@ -73,7 +73,7 @@ configs().forEach(({ title, screenshot, config }) => { const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); - await toastFixture.screenshot('cancelBtn2', screenshot); + await toastFixture.screenshot('toastCancelBtn2', screenshot); await optBtn2AlertOkBtn.click(); }); From 91b5b8b3bb82da20fd0cfed373c478809f01e12d Mon Sep 17 00:00:00 2001 From: Sean Perkins Date: Thu, 14 Mar 2024 13:27:57 -0400 Subject: [PATCH 22/22] test(picker): cancel button handler is called --- .../components/alert/test/basic/index.html | 6 +- .../components/picker/test/basic/index.html | 87 ++++-------------- .../picker/test/basic/picker.e2e.ts | 88 ++++++++++--------- .../components/toast/test/buttons/index.html | 6 +- 4 files changed, 67 insertions(+), 120 deletions(-) diff --git a/core/src/components/alert/test/basic/index.html b/core/src/components/alert/test/basic/index.html index d3d7c5ada32..9fd07b39f05 100644 --- a/core/src/components/alert/test/basic/index.html +++ b/core/src/components/alert/test/basic/index.html @@ -118,7 +118,7 @@ }); } - function confirmpAlertCancelBtns(expectedDataTestId) { + function confirmAlertCancelBtns(expectedDataTestId) { openAlert({ header: 'Alert', subHeader: 'CancelBtnClicked', @@ -141,7 +141,7 @@ role: 'cancel', cssClass: 'cancel1-btn', handler: () => { - confirmpAlertCancelBtns('cancel1-btn-clicked'); + confirmAlertCancelBtns('cancel1-btn-clicked'); }, }, { @@ -149,7 +149,7 @@ role: 'cancel', cssClass: 'cancel2-btn', handler: () => { - confirmpAlertCancelBtns('cancel2-btn-clicked'); + confirmAlertCancelBtns('cancel2-btn-clicked'); }, }, { diff --git a/core/src/components/picker/test/basic/index.html b/core/src/components/picker/test/basic/index.html index fcb107be57b..bf88763140c 100644 --- a/core/src/components/picker/test/basic/index.html +++ b/core/src/components/picker/test/basic/index.html @@ -14,8 +14,7 @@ @@ -23,9 +22,6 @@ Show Picker - Show Picker w/ Multiple Cancel btns Show Custom Picker @@ -48,11 +44,6 @@ - test('cancel button 2', async ({ page }) => { - await page.goto('/src/components/picker/test/basic', config); - await page.click('#basicMultipleCancelBtns'); - const optBtn2 = page.locator('ion-picker button.cancel2-btn'); - await optBtn2.click(); - const confirmOptBtn2Alert = page.locator('ion-alert[data-testid=cancel2-btn-clicked]'); - const optBtn2AlertInfo = confirmOptBtn2Alert.locator('.alert-message').innerText(); - const optBtn2AlertOkBtn = confirmOptBtn2Alert.locator('.alert-button-group button'); - expect(await optBtn2AlertInfo).toBe('cancel2-btn-clicked'); - await expect(page).toHaveScreenshot(screenshot(`pickerCancelBtn2`)); - await optBtn2AlertOkBtn.click(); - }); + - test('cancel button 3', async ({ page }) => { - await page.goto('/src/components/picker/test/basic', config); - await page.click('#basicMultipleCancelBtns'); - const ionPickerDidDismiss = await page.spyOnEvent('ionPickerDidDismiss'); - const optBtn3 = page.locator('ion-picker button.cancel3-btn'); - await optBtn3.click(); - await ionPickerDidDismiss.next(); - expect(ionPickerDidDismiss).toHaveReceivedEventDetail({ - data: { - hours: { - text: '1', - value: '01', - columnIndex: 0, - }, - }, - role: 'cancel', - }); +
+ + + `, + config + ); + + const didPresent = await page.spyOnEvent('ionPickerDidPresent'); + + const openBtn = page.locator('#open'); + await openBtn.click(); + + await didPresent.next(); + + const cancelBtn = page.locator('ion-picker .cancel-btn'); + await cancelBtn.click(); + + const result = page.locator('#result'); + await expect(result).toHaveText('cancelled'); }); }); }); diff --git a/core/src/components/toast/test/buttons/index.html b/core/src/components/toast/test/buttons/index.html index 7ca1d42073a..397dc6a340e 100644 --- a/core/src/components/toast/test/buttons/index.html +++ b/core/src/components/toast/test/buttons/index.html @@ -129,7 +129,7 @@ return await presentToastWithOptions(opts); } - function confirmpAlertCancelBtns(expectedDataTestId) { + function confirmAlertCancelBtns(expectedDataTestId) { openAlert({ header: 'Alert', subHeader: 'CancelBtnClicked', @@ -150,7 +150,7 @@ role: 'cancel', cssClass: 'cancel1-btn', handler: () => { - confirmpAlertCancelBtns('cancel1-btn-clicked'); + confirmAlertCancelBtns('cancel1-btn-clicked'); }, }, { @@ -158,7 +158,7 @@ role: 'cancel', cssClass: 'cancel2-btn', handler: () => { - confirmpAlertCancelBtns('cancel2-btn-clicked'); + confirmAlertCancelBtns('cancel2-btn-clicked'); }, }, {