Skip to content

Commit

Permalink
feat(checkbox): configura test e2e
Browse files Browse the repository at this point in the history
fix #7
  • Loading branch information
nsanitate committed Jun 20, 2018
1 parent 5a24dc9 commit d4734e4
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 77 deletions.
14 changes: 0 additions & 14 deletions e2e/src/app.e2e-spec.ts

This file was deleted.

11 changes: 0 additions & 11 deletions e2e/src/app.po.ts

This file was deleted.

45 changes: 45 additions & 0 deletions e2e/src/checkbox/checkbox.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { browser } from 'protractor';
import { CheckboxPage } from './checkbox.po';

describe('Checkbox', () => {
let page: CheckboxPage;

beforeEach(async() => {
page = new CheckboxPage();
await page.go();
});

it('dovrebbe iniziare spuntato e abilitato', async () => {
expect(await page.getRisultatoCheckboxChecked()).toBeTruthy();
expect(await page.getRisultatoCheckboxDisabled()).toBeFalsy();
});

it('dovrebbe interagire con l\'utente', async () => {
await page.clickRisultatoCheckbox();
let actual = await page.getRisultatoCheckboxChecked();
expect(actual).toBeFalsy();
await page.clickRisultatoCheckbox();
actual = await page.getRisultatoCheckboxChecked();
expect(actual).toBeTruthy();
});

it('dovrebbe permettere di modificare la spunta', async () => {
await page.clickSpuntatoCheckbox();
expect(await page.getRisultatoCheckboxChecked()).toBeFalsy();
await page.clickSpuntatoCheckbox();
expect(await page.getRisultatoCheckboxChecked()).toBeTruthy();
});

it('dovrebbe permettere di modificare l\'abilitazione', async () => {
await page.clickDisabilitatoCheckbox();
expect(await page.getRisultatoCheckboxDisabled()).toBeTruthy();
await page.clickDisabilitatoCheckbox();
expect(await page.getRisultatoCheckboxDisabled()).toBeFalsy();
});

it('dovrebbe evitare di far modificare la spunta se disabilitato', async () => {
await page.clickDisabilitatoCheckbox();
await page.clickRisultatoCheckbox();
expect(await page.getRisultatoCheckboxChecked()).toBeTruthy();
});
});
46 changes: 46 additions & 0 deletions e2e/src/checkbox/checkbox.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { browser, by, element } from 'protractor';

export class CheckboxPage {
private readonly ID_CHECBOX_SPUNTATO = 'checkbox-0';
private readonly ID_CHECBOX_DISABILITATO = 'checkbox-1';
private readonly ID_CHECBOX_RISULTATO = 'checkbox-2';

private readonly ATTR_FOR_LABEL_SPUNTATO = this.getLabelForAttribute(this.ID_CHECBOX_SPUNTATO);
private readonly ATTR_FOR_LABEL_DISABILITATO = this.getLabelForAttribute(this.ID_CHECBOX_DISABILITATO);
private readonly ATTR_FOR_LABEL_RISULTATO = this.getLabelForAttribute(this.ID_CHECBOX_RISULTATO);

private readonly ATTR_CHECKED = 'checked';
private readonly ATTR_DISABLED = 'disabled';

async go() {
return await browser.get('/checkbox');
}

async clickSpuntatoCheckbox() {
await element(by.css(this.ATTR_FOR_LABEL_SPUNTATO)).click();
}

async clickDisabilitatoCheckbox() {
await element(by.css(this.ATTR_FOR_LABEL_DISABILITATO)).click();
}

async clickRisultatoCheckbox() {
await element(by.css(this.ATTR_FOR_LABEL_RISULTATO)).click();
}

async getRisultatoCheckboxChecked() {
return this.getRisultatoCheckbox().getAttribute(this.ATTR_CHECKED);
}

async getRisultatoCheckboxDisabled() {
return this.getRisultatoCheckbox().getAttribute(this.ATTR_DISABLED);
}

private getRisultatoCheckbox() {
return element(by.id(this.ID_CHECBOX_RISULTATO));
}

private getLabelForAttribute(attr: string) {
return `[for="${attr}"]`;
}
}
Loading

0 comments on commit d4734e4

Please sign in to comment.