diff --git a/core/src/components/radio-group/test/basic/index.html b/core/src/components/radio-group/test/basic/index.html index 53e68659f6..5b690307e3 100644 --- a/core/src/components/radio-group/test/basic/index.html +++ b/core/src/components/radio-group/test/basic/index.html @@ -22,161 +22,35 @@ - -

- Add Radio - Add Checked - Remove Radio -

- + - + - Luckiest Man On Earth + Radio Group Header - Biff - - - + Item 1 + - Griff - - - + Item 2 + - Buford - - - + Item 3 + - George - - - - - - - - - Huey - - - - - Dewey - - - - - Louie - - - - - - - - - Maintenance Drone - - - - Huey - - - - - Dewey - - - - - Louie - + Item 4 + - - - - diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts b/core/src/components/radio-group/test/basic/radio-group.e2e.ts new file mode 100644 index 0000000000..3916a5e280 --- /dev/null +++ b/core/src/components/radio-group/test/basic/radio-group.e2e.ts @@ -0,0 +1,110 @@ +import { expect } from '@playwright/test'; +import type { Locator } from '@playwright/test'; +import { test } from '@utils/test/playwright'; +import type { E2EPage } from '@utils/test/playwright'; + +test.describe('radio-group: basic', () => { + test('should not have visual regressions', async ({ page }) => { + await page.goto(`/src/components/radio-group/test/basic`); + + const list = page.locator('ion-list'); + + expect(await list.screenshot()).toMatchSnapshot(`radio-group-diff-${page.getSnapshotSettings()}.png`); + }); +}); + +test.describe('radio-group: interaction', () => { + let radioFixture: RadioFixture; + + test.beforeEach(({ page }, testInfo) => { + test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs RTL logic.'); + radioFixture = new RadioFixture(page); + }); + + test('spacebar should not deselect without allowEmptySelection', async ({ page }) => { + await page.setContent(` + + + One + + + + `); + + await radioFixture.checkRadio('keyboard'); + await radioFixture.expectChecked(true); + }); + + test('spacebar should deselect with allowEmptySelection', async ({ page }) => { + await page.setContent(` + + + One + + + + `); + + await radioFixture.checkRadio('keyboard'); + await radioFixture.expectChecked(false); + }); + + test('click should not deselect without allowEmptySelection', async ({ page }) => { + await page.setContent(` + + + One + + + + `); + + await radioFixture.checkRadio('mouse'); + await radioFixture.expectChecked(true); + }); + + test('click should deselect with allowEmptySelection', async ({ page }) => { + await page.setContent(` + + + One + + + + `); + + await radioFixture.checkRadio('mouse'); + await radioFixture.expectChecked(false); + }); +}); + +class RadioFixture { + readonly page: E2EPage; + + private radio!: Locator; + + constructor(page: E2EPage) { + this.page = page; + } + + async checkRadio(method: 'keyboard' | 'mouse', selector = 'ion-radio') { + const { page } = this; + const radio = (this.radio = page.locator(selector)); + + if (method === 'keyboard') { + await radio.focus(); + await page.keyboard.press('Space'); + } else { + await radio.click(); + } + + await page.waitForChanges(); + + return radio; + } + + async expectChecked(state: boolean) { + const { radio } = this; + await expect(radio.locator('input')).toHaveJSProperty('checked', state); + } +} diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Chrome-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..10526e13ec Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Firefox-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..530024862e Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Safari-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..a25993629a Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Chrome-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..e1c94c7fd0 Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Firefox-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..986c40f8ff Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Safari-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Safari-linux.png new file mode 100644 index 0000000000..4663fa1e04 Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-ios-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Chrome-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..d3e1bdc629 Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Chrome-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Firefox-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..85fa71cf2a Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Firefox-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Safari-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Safari-linux.png new file mode 100644 index 0000000000..64bd3fc737 Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-ltr-Mobile-Safari-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Chrome-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Chrome-linux.png new file mode 100644 index 0000000000..f40e0710aa Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Chrome-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Firefox-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Firefox-linux.png new file mode 100644 index 0000000000..6f574063ce Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Firefox-linux.png differ diff --git a/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Safari-linux.png b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Safari-linux.png new file mode 100644 index 0000000000..b798475214 Binary files /dev/null and b/core/src/components/radio-group/test/basic/radio-group.e2e.ts-snapshots/radio-group-diff-md-rtl-Mobile-Safari-linux.png differ diff --git a/core/src/components/radio-group/test/form/radio-group.e2e.ts b/core/src/components/radio-group/test/form/radio-group.e2e.ts new file mode 100644 index 0000000000..d6a833e6e6 --- /dev/null +++ b/core/src/components/radio-group/test/form/radio-group.e2e.ts @@ -0,0 +1,34 @@ +import { expect } from '@playwright/test'; +import { test } from '@utils/test/playwright'; + +test.describe('radio-group: form', () => { + test.beforeEach(async ({ page }) => { + await page.goto('/src/components/radio-group/test/form'); + }); + + test('selecting an option should update the value', async ({ page }) => { + const radioGroup = page.locator('ion-radio-group'); + const ionChange = await page.spyOnEvent('ionChange'); + const griffRadio = page.locator('ion-radio[value="griff"]'); + + await expect(radioGroup).toHaveAttribute('value', 'biff'); + + await griffRadio.click(); + await page.waitForChanges(); + + await expect(ionChange).toHaveReceivedEventDetail({ value: 'griff' }); + }); + + test('selecting a disabled option should not update the value', async ({ page }) => { + const value = page.locator('#value'); + const disabledRadio = page.locator('ion-radio[value="george"]'); + + await expect(value).toHaveText(''); + await expect(disabledRadio).toHaveAttribute('disabled', ''); + + await disabledRadio.click({ force: true }); + await page.waitForChanges(); + + await expect(value).toHaveText(''); + }); +}); diff --git a/core/src/components/radio-group/test/radio-group.e2e.ts b/core/src/components/radio-group/test/radio-group.e2e.ts deleted file mode 100644 index 9a6aa2f80a..0000000000 --- a/core/src/components/radio-group/test/radio-group.e2e.ts +++ /dev/null @@ -1,133 +0,0 @@ -import { expect } from '@playwright/test'; -import type { Locator } from '@playwright/test'; -import { test } from '@utils/test/playwright'; -import type { E2EPage } from '@utils/test/playwright'; - -test.describe('radio-group', () => { - // eslint-disable-next-line no-empty-pattern - test.beforeEach(({}, testInfo) => { - test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs RTL logic.'); - }); - - test.describe('radio-group: interaction', () => { - let radioFixture: RadioFixture; - - test.beforeEach(({ page }) => { - radioFixture = new RadioFixture(page); - }); - - test('spacebar should not deselect without allowEmptySelection', async ({ page }) => { - await page.setContent(` - - - One - - - - `); - - await radioFixture.checkRadio('keyboard'); - await radioFixture.expectChecked(true); - }); - - test('spacebar should deselect with allowEmptySelection', async ({ page }) => { - await page.setContent(` - - - One - - - - `); - - await radioFixture.checkRadio('keyboard'); - await radioFixture.expectChecked(false); - }); - - test('click should not deselect without allowEmptySelection', async ({ page }) => { - await page.setContent(` - - - One - - - - `); - - await radioFixture.checkRadio('mouse'); - await radioFixture.expectChecked(true); - }); - - test('click should deselect with allowEmptySelection', async ({ page }) => { - await page.setContent(` - - - One - - - - `); - - await radioFixture.checkRadio('mouse'); - await radioFixture.expectChecked(false); - }); - }); - test.describe('radio-group: state', () => { - test('radio should remain checked after being removed/readded to the dom', async ({ page }) => { - await page.goto('/src/components/radio-group/test/search'); - - const radioGroup = page.locator('ion-radio-group'); - const radio = page.locator('ion-radio[value=two]'); - - // select radio - await radio.click(); - await expect(radio.locator('input')).toHaveJSProperty('checked', true); - - // filter radio so it is not in DOM - await page.fill('ion-searchbar input', 'zero'); - await page.waitForChanges(); - expect(radio).toBeHidden(); - - // ensure radio group has the same value - expect(radioGroup).toHaveJSProperty('value', 'two'); - - // clear the search so the radio appears - await page.fill('ion-searchbar input', ''); - await page.waitForChanges(); - - // ensure that the new radio instance is still checked - await expect(radio.locator('input')).toHaveJSProperty('checked', true); - }); - }); -}); - -class RadioFixture { - readonly page: E2EPage; - - private radio!: Locator; - - constructor(page: E2EPage) { - this.page = page; - } - - async checkRadio(method: 'keyboard' | 'mouse', selector = 'ion-radio') { - const { page } = this; - const radio = (this.radio = page.locator(selector)); - - if (method === 'keyboard') { - await radio.focus(); - await page.keyboard.press('Space'); - } else { - await radio.click(); - } - - await page.waitForChanges(); - - return radio; - } - - async expectChecked(state: boolean) { - const { radio } = this; - await expect(radio.locator('input')).toHaveJSProperty('checked', state); - } -} diff --git a/core/src/components/radio-group/test/search/radio-group.e2e.ts b/core/src/components/radio-group/test/search/radio-group.e2e.ts new file mode 100644 index 0000000000..ef031bb4a4 --- /dev/null +++ b/core/src/components/radio-group/test/search/radio-group.e2e.ts @@ -0,0 +1,35 @@ +import { expect } from '@playwright/test'; +import { test } from '@utils/test/playwright'; + +test.describe('radio-group', () => { + test.beforeEach(async ({ page }, testInfo) => { + test.skip(testInfo.project.metadata.rtl === true, 'This does not test LTR vs RTL logic.'); + await page.goto('/src/components/radio-group/test/search'); + }); + + test.describe('radio-group: state', () => { + test('radio should remain checked after being removed/readded to the dom', async ({ page }) => { + const radioGroup = page.locator('ion-radio-group'); + const radio = page.locator('ion-radio[value=two]'); + + // select radio + await radio.click(); + await expect(radio.locator('input')).toHaveJSProperty('checked', true); + + // filter radio so it is not in DOM + await page.fill('ion-searchbar input', 'zero'); + await page.waitForChanges(); + expect(radio).toBeHidden(); + + // ensure radio group has the same value + expect(radioGroup).toHaveJSProperty('value', 'two'); + + // clear the search so the radio appears + await page.fill('ion-searchbar input', ''); + await page.waitForChanges(); + + // ensure that the new radio instance is still checked + await expect(radio.locator('input')).toHaveJSProperty('checked', true); + }); + }); +});