diff --git a/e2e/src/collapse/collapse.e2e-spec.ts b/e2e/src/collapse/collapse.e2e-spec.ts new file mode 100644 index 00000000..890c98a7 --- /dev/null +++ b/e2e/src/collapse/collapse.e2e-spec.ts @@ -0,0 +1,59 @@ +import { CollapsePage } from './collapse.po'; + +describe('Collapse', () => { + let page: CollapsePage; + + beforeEach(async() => { + page = new CollapsePage(); + await page.go(); + }); + + it('dovrebbe essere inizialmente non visibile nel DOM', async () => { + expect(await page.isDiv0Visible()).toBeFalsy(); + }); + + it('dovrebbe essere effettuato il toggle quando si clicca il bottone', async () => { + expect(await page.isDiv0Visible()).toBeFalsy(); + await page.clickButton(); + expect(await page.isDiv0Visible()).toBeTruthy(); + await page.clickButton(); + expect(await page.isDiv0Visible()).toBeFalsy(); + }); + + it('gli item del group dovrebbero essere inizialmente chiusi', async () => { + expect(await page.isItem0Visible()).toBeFalsy(); + expect(await page.isItem1Visible()).toBeFalsy(); + expect(await page.isItem2Visible()).toBeFalsy(); + }); + + it('gli item del group non dovrebbero essere mutuamente esclusivi', async () => { + await page.clickGroup0Button(); + expect(await page.isItem0Visible()).toBeTruthy(); + expect(await page.isItem1Visible()).toBeFalsy(); + expect(await page.isItem2Visible()).toBeFalsy(); + await page.clickGroup1Button(); + expect(await page.isItem0Visible()).toBeTruthy(); + expect(await page.isItem1Visible()).toBeTruthy(); + expect(await page.isItem2Visible()).toBeFalsy(); + await page.clickGroup2Button(); + expect(await page.isItem0Visible()).toBeTruthy(); + expect(await page.isItem1Visible()).toBeTruthy(); + expect(await page.isItem2Visible()).toBeTruthy(); + }); + + it('gli item del group dovrebbero essere mutuamente esclusivi', async () => { + await page.clickCheckbox(); + await page.clickGroup0Button(); + expect(await page.isItem0Visible()).toBeTruthy(); + expect(await page.isItem1Visible()).toBeFalsy(); + expect(await page.isItem2Visible()).toBeFalsy(); + await page.clickGroup1Button(); + expect(await page.isItem0Visible()).toBeFalsy(); + expect(await page.isItem1Visible()).toBeTruthy(); + expect(await page.isItem2Visible()).toBeFalsy(); + await page.clickGroup2Button(); + expect(await page.isItem0Visible()).toBeFalsy(); + expect(await page.isItem1Visible()).toBeFalsy(); + expect(await page.isItem2Visible()).toBeTruthy(); + }); +}); diff --git a/e2e/src/collapse/collapse.po.ts b/e2e/src/collapse/collapse.po.ts new file mode 100644 index 00000000..357b40c4 --- /dev/null +++ b/e2e/src/collapse/collapse.po.ts @@ -0,0 +1,70 @@ +import { browser, by, element } from 'protractor'; + +export class CollapsePage { + private readonly COLLAPSE_URL = '/#/componenti/collapse'; + private readonly ID_EXAMPLE_TAB = 'collapse-examples-tab'; + + private readonly ID_BUTTON = 'button-0'; + private readonly ID_DIV_0 = 'collapseExample'; + + private readonly ID_CHECKBOX_ACCORDION = this.getLabelForAttribute('checkbox-0'); + + private readonly ID_ITEM_0_HEADING = 'collapse-item-0-heading'; + private readonly ID_ITEM_0 = 'collapse-item-0'; + + private readonly ID_ITEM_1_HEADING = 'collapse-item-1-heading'; + private readonly ID_ITEM_1 = 'collapse-item-1'; + + private readonly ID_ITEM_2_HEADING = 'collapse-item-2-heading'; + private readonly ID_ITEM_2 = 'collapse-item-2'; + + async go() { + await browser.get(this.COLLAPSE_URL); + await element(by.id(this.ID_EXAMPLE_TAB)).click(); + return await browser.sleep(500); + } + + private getLabelForAttribute(attr: string) { + return `[for="${attr}"]`; + } + + async existsButton() { + return await element(by.id(this.ID_BUTTON)).isPresent(); + } + + async clickButton() { + await element(by.id(this.ID_BUTTON)).click(); + } + + async isDiv0Visible() { + return await element(by.id(this.ID_DIV_0)).isDisplayed(); + } + + async clickCheckbox() { + await element(by.css(this.ID_CHECKBOX_ACCORDION)).click(); + } + + async clickGroup0Button() { + await element(by.id(this.ID_ITEM_0_HEADING)).click(); + } + + async clickGroup1Button() { + await element(by.id(this.ID_ITEM_1_HEADING)).click(); + } + + async clickGroup2Button() { + await element(by.id(this.ID_ITEM_2_HEADING)).click(); + } + + async isItem0Visible() { + return await element(by.id(this.ID_ITEM_0)).isDisplayed(); + } + + async isItem1Visible() { + return await element(by.id(this.ID_ITEM_1)).isDisplayed(); + } + + async isItem2Visible() { + return await element(by.id(this.ID_ITEM_2)).isDisplayed(); + } +} diff --git a/projects/design-angular-kit/src/lib/collapse/collapse-group.component.css b/projects/design-angular-kit/src/lib/collapse/collapse-group.component.css new file mode 100644 index 00000000..e69de29b diff --git a/projects/design-angular-kit/src/lib/collapse/collapse-group.component.html b/projects/design-angular-kit/src/lib/collapse/collapse-group.component.html new file mode 100644 index 00000000..aee27bff --- /dev/null +++ b/projects/design-angular-kit/src/lib/collapse/collapse-group.component.html @@ -0,0 +1,3 @@ +