Skip to content

Commit

Permalink
test(Button): Implementa i test e2e per i bottoni
Browse files Browse the repository at this point in the history
ref #44
  • Loading branch information
Mario Traetta committed Jul 30, 2018
1 parent 8d00e44 commit 5201bf8
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
61 changes: 61 additions & 0 deletions e2e/src/button/button.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { browser } from 'protractor';
import { ButtonPage } from './button.po';

const BUTTON_TEXT = 'Numero click eseguiti: ';
describe('Button', () => {
let page: ButtonPage;

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

it('dovrebbe poter essere cliccato', async () => {
let actualValue = await page.getButtonText();
expect(actualValue).toBe(BUTTON_TEXT + 0);

await page.clickButton();

actualValue = await page.getButtonText();
expect(actualValue).toBe(BUTTON_TEXT + 1);
});

it('dovrebbe poter essere disabilitato', async () => {
let actualValue = await page.getButtonText();
let buttonClasses = await page.getButtonClasses();
let isDisabled = buttonClasses.indexOf('disabled') > -1;
expect(actualValue).toBe(BUTTON_TEXT + 0);
expect(isDisabled).toBeFalsy();

await page.clickDisabledCheckbox();
await page.clickButton();

actualValue = await page.getButtonText();
buttonClasses = await page.getButtonClasses();
isDisabled = buttonClasses.indexOf('disabled') > -1;
expect(actualValue).toBe(BUTTON_TEXT + 0);
expect(isDisabled).toBeTruthy();
});

it('dovrebbe poter essere un elemento a blocco', async () => {
let actualValue = await page.getButtonText();
let buttonClasses = await page.getButtonClasses();
let isDisabled = buttonClasses.indexOf('btn-block') > -1;
expect(actualValue).toBe(BUTTON_TEXT + 0);
expect(isDisabled).toBeFalsy();

await page.clickBlockCheckbox();
await page.clickButton();

actualValue = await page.getButtonText();
buttonClasses = await page.getButtonClasses();
isDisabled = buttonClasses.indexOf('btn-block') > -1;
expect(actualValue).toBe(BUTTON_TEXT + 1);
expect(isDisabled).toBeTruthy();
});

/* it('dovrebbe poter aver un colore diverso e poi avere un colore a contorno', async () => {
}); */

});
41 changes: 41 additions & 0 deletions e2e/src/button/button.po.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { browser, by, element, ExpectedConditions } from 'protractor';

export class ButtonPage {
private readonly BUTTON_URL = '/#/componenti/button';
private readonly ID_EXAMPLE_TAB = 'button-examples-tab';

private readonly ID_BUTTON = 'button-21';
private readonly ID_CHECKBOX_DISABLE = 'disabled-checkbox';
private readonly ID_CHECKBOX_BLOCK = 'block-checkbox';

async go() {
await browser.get(this.BUTTON_URL);
await element(by.id(this.ID_EXAMPLE_TAB)).click();
return await browser.sleep(500);
}

async clickButton() {
await element(by.id(this.ID_BUTTON)).click();
}

async clickElement(id: string) {
await element(by.id(id)).click();
}

async clickDisabledCheckbox() {
await this.clickElement(this.ID_CHECKBOX_DISABLE);
}

async clickBlockCheckbox() {
await this.clickElement(this.ID_CHECKBOX_BLOCK);
}

async getButtonText() {
return await element(by.id(this.ID_BUTTON)).getText();
}

async getButtonClasses() {
const classAttribute = await element(by.id(this.ID_BUTTON)).getAttribute('class');
return classAttribute.split(' ');
}
}

0 comments on commit 5201bf8

Please sign in to comment.