From 8f172de355bc7c910d600ce4d8446b04a6212545 Mon Sep 17 00:00:00 2001 From: Liam DeBeasi Date: Tue, 6 Jul 2021 12:24:20 -0400 Subject: [PATCH] fix(accordion): value can now be set as string when using multiple is true (#23581) resolves #23550 --- .../accordion-group/accordion-group.tsx | 12 +- .../components/accordion/test/multiple/e2e.ts | 55 ++++++++ .../accordion/test/multiple/index.html | 118 ++++++++++++++++++ 3 files changed, 180 insertions(+), 5 deletions(-) create mode 100644 core/src/components/accordion/test/multiple/e2e.ts create mode 100644 core/src/components/accordion/test/multiple/index.html diff --git a/core/src/components/accordion-group/accordion-group.tsx b/core/src/components/accordion-group/accordion-group.tsx index 82e492df79b..3cbf069dd76 100644 --- a/core/src/components/accordion-group/accordion-group.tsx +++ b/core/src/components/accordion-group/accordion-group.tsx @@ -150,10 +150,11 @@ export class AccordionGroup implements ComponentInterface { * to the array. */ if (multiple) { - const groupValue = (value || []) as string[]; - const valueExists = groupValue.find(v => v === accordionValue); + const groupValue = value || []; + const processedValue = Array.isArray(groupValue) ? groupValue : [groupValue]; + const valueExists = processedValue.find(v => v === accordionValue); if (valueExists === undefined && accordionValue !== undefined) { - this.value = [...groupValue, accordionValue]; + this.value = [...processedValue, accordionValue]; } } else { this.value = accordionValue; @@ -164,8 +165,9 @@ export class AccordionGroup implements ComponentInterface { * out of the values array or unset the value. */ if (multiple) { - const groupValue = (value || []) as string[]; - this.value = groupValue.filter(v => v !== accordionValue); + const groupValue = value || []; + const processedValue = Array.isArray(groupValue) ? groupValue : [groupValue]; + this.value = processedValue.filter(v => v !== accordionValue); } else { this.value = undefined; } diff --git a/core/src/components/accordion/test/multiple/e2e.ts b/core/src/components/accordion/test/multiple/e2e.ts new file mode 100644 index 00000000000..70e886e2216 --- /dev/null +++ b/core/src/components/accordion/test/multiple/e2e.ts @@ -0,0 +1,55 @@ +import { newE2EPage } from '@stencil/core/testing'; + +test('accordion: multiple - open', async () => { + const page = await newE2EPage({ + url: '/src/components/accordion/test/multiple?ionic:_testing=true' + }); + + const screenshotCompares = []; + + screenshotCompares.push(await page.compareScreenshot()); + + const accordionGroup = await page.find('ion-accordion-group'); + const diningAccordion = await page.find('ion-accordion[value="dining"] ion-item[slot="header"]'); + const attractionsAccordion = await page.find('ion-accordion[value="attractions"] ion-item[slot="header"]'); + + const groupValue = await accordionGroup.getProperty('value'); + expect(groupValue).toEqual('attractions'); + + await diningAccordion.click(); + await page.waitForChanges(); + + const groupValueAgain = await accordionGroup.getProperty('value'); + expect(groupValueAgain).toEqual(['attractions', 'dining']); + + screenshotCompares.push(await page.compareScreenshot()); + + for (const screenshotCompare of screenshotCompares) { + expect(screenshotCompare).toMatchScreenshot(); + } +}); + +test('accordion: multiple - close', async () => { + const page = await newE2EPage({ + url: '/src/components/accordion/test/multiple?ionic:_testing=true' + }); + + const screenshotCompares = []; + + screenshotCompares.push(await page.compareScreenshot()); + + const accordionGroup = await page.find('ion-accordion-group'); + const attractionsAccordion = await page.find('ion-accordion[value="attractions"] ion-item[slot="header"]'); + + await attractionsAccordion.click(); + await page.waitForChanges(); + + const groupValue = await accordionGroup.getProperty('value'); + expect(groupValue).toEqual([]); + + screenshotCompares.push(await page.compareScreenshot()); + + for (const screenshotCompare of screenshotCompares) { + expect(screenshotCompare).toMatchScreenshot(); + } +}); diff --git a/core/src/components/accordion/test/multiple/index.html b/core/src/components/accordion/test/multiple/index.html new file mode 100644 index 00000000000..25b49c155a6 --- /dev/null +++ b/core/src/components/accordion/test/multiple/index.html @@ -0,0 +1,118 @@ + + + + + Accordion - Multiple + + + + + + + + + + + + Accordion - Multiple + + + +
+
+

Multiple

+ + + + + Attractions + + + + Movie Theaters + + + Amusement Parks + + + Mini Golf + + + + + + + Dining + + + + Breakfast & Brunch + + + New American + + + Sushi Bars + + + + + + + Games + + + + + Xbox + + + Playstation + + + Switch + + + + + + + Exercise + + + + + Jog + + + Swim + + + Nap + + + + +
+
+
+
+ +