Skip to content

Commit

Permalink
fix(tests): fixing e2e type errors (#3358)
Browse files Browse the repository at this point in the history
  • Loading branch information
YevheniiaMazur authored and valorkin committed Dec 26, 2017
1 parent 86a747c commit 5136fd6
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 200 deletions.
8 changes: 5 additions & 3 deletions demo/e2e/app.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Ng2BootstrapPage} from './app.po';
import { Ng2BootstrapPage } from './app.po';

describe('ng2-bootstrap demo', function (): any {
let page: Ng2BootstrapPage;
Expand All @@ -7,8 +7,10 @@ describe('ng2-bootstrap demo', function (): any {
page = new Ng2BootstrapPage();
});

it('should display message saying app works', () => {
it('should display message saying app works', async () => {
page.navigateTo();
expect(page.getParagraphText()).toEqual('Bootstrap components for Angular');
const title = await page.getParagraphText();

expect(title).toEqual('Bootstrap components for Angular');
});
});
75 changes: 52 additions & 23 deletions demo/e2e/tests/accordion-demo.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,76 +1,105 @@
import { $, $$, browser, ExpectedConditions } from 'protractor';
import { $, $$, browser, ElementFinder, ExpectedConditions as EC } from 'protractor';
import { leftPanelTests } from './leftPanelTests.po';
import { DataProvider } from '../data-provider/data-provider.po';

let using = require('jasmine-data-provider');
const using = require('jasmine-data-provider');

const buttonToggleLastPanel = $('accordion-demo>p button:nth-child(1)');
const buttonEnableDisablePanel = $('accordion-demo>p button:nth-child(2)');
const buttonAddItem = $('.panel-body .btn');
const checkboxOnlyOne = $('.checkbox .ng-valid');
const getItemsCount = $$('accordion-group:nth-child(4) .panel-body > div');
const buttonArrow = $('.pull-right');

const EC = ExpectedConditions;
function getTabHeader(tabNumber: number): ElementFinder {
return $(`accordion-group:nth-child(${tabNumber}) .panel-heading`);
}

function getTabContent(tabNumber: number): ElementFinder {
return $(`accordion-group:nth-child(${tabNumber}) .panel-body`);
}

async function tabContentIsDisplayed(tabNum: number): Promise<boolean> {
return await getTabContent(tabNum).isDisplayed();
}

const getTabHeader = (tabNumber:number) => {
return $('accordion-group:nth-child(' + tabNumber + ') .panel-heading');
};
const getTabContent = (tabNumber:number) => {
return $('accordion-group:nth-child(' + tabNumber + ') .panel-body');
};
async function tabHeaderIsDisplayed(tabNum: number): Promise<boolean> {
return await getTabHeader(tabNum).isDisplayed();
}

async function getNumberOfItems(): Promise<number> {
return await getItemsCount.count();
}

describe('Check the Accordion page in bootstrap 3', () => {
beforeAll(() => {
browser.get('#/accordion');
leftPanelTests.checkLeftPanelMini();
leftPanelTests.checkLeftPanelMaxi();
});
it('Close/open first tab by click', () => {

it('Close/open first tab by click', async () => {
getTabHeader(1).click();
expect(getTabContent(1).isDisplayed()).toBe(false);
expect(await tabContentIsDisplayed(1)).toBeFalsy();

getTabHeader(1).click();
expect(getTabContent(1).isDisplayed()).toBe(true);
expect(await tabContentIsDisplayed(1)).toBeTruthy();
});
it('Open/close last tab with button Toggle Last Panel', () => {

it('Open/close last tab with button Toggle Last Panel', async () => {
buttonToggleLastPanel.click();
expect(getTabContent(5).isDisplayed()).toBe(true);
expect(await tabContentIsDisplayed(5)).toBeTruthy();
expect(buttonArrow.getAttribute('class')).toContain('glyphicon-chevron-down');

buttonToggleLastPanel.click();
expect(getTabContent(5).isDisplayed()).toBe(false);
expect(await tabContentIsDisplayed(5)).toBeFalsy();
expect(buttonArrow.getAttribute('class')).toContain('glyphicon-chevron-right');
});
it('Button Enable/Disable first panel is ON', () => {

it('Button Enable/Disable first panel is ON', async () => {
buttonEnableDisablePanel.click();
getTabHeader(1).click();
expect(getTabContent(1).isDisplayed()).toBe(false);

expect(await tabContentIsDisplayed(1)).toBeFalsy();
});
it('Button Enable/Disable first panel is OFF', () => {

it('Button Enable/Disable first panel is OFF', async () => {
buttonEnableDisablePanel.click();
getTabHeader(1).click();
expect(getTabHeader(1).isDisplayed()).toBe(true);

expect(await tabHeaderIsDisplayed(1)).toBeTruthy();
});

it('Add items in 4th tab', () => {
getTabHeader(4).click();
expect(getItemsCount.count()).toBe(3);
expect(getNumberOfItems).toBe(3);

buttonAddItem.click();
buttonAddItem.click();
expect(getItemsCount.count()).toBe(5);
expect(getNumberOfItems).toBe(5);

getTabHeader(4).click();
});

it('Open all tabs together', () => {
checkboxOnlyOne.click();
getTabHeader(1).click();
browser.wait(EC.visibilityOf(getTabContent(1)), 500);

getTabHeader(2).click();
browser.wait(EC.visibilityOf(getTabContent(2)), 500);

getTabHeader(3).click();
browser.wait(EC.visibilityOf(getTabContent(3)), 500);

getTabHeader(4).click();
browser.wait(EC.visibilityOf(getTabContent(4)), 500);

getTabHeader(5).click();
});
using (DataProvider.accordionTableContent, (data:any, description:string) => {
it ('Check table texts: ' + description, () => {

using(DataProvider.accordionTableContent, (data: any, description: string) => {
it(`Check table texts: ${description}`, () => {
expect(data.element().getText()).toBe(data.actualResult);
});
});
Expand Down
47 changes: 34 additions & 13 deletions demo/e2e/tests/alert-demo.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,71 @@ import { $, $$, browser } from 'protractor';
import { leftPanelTests } from './leftPanelTests.po';
import { DataProvider } from '../data-provider/data-provider.po';

let using = require('jasmine-data-provider');
const using = require('jasmine-data-provider');

const buttonAddAlert = $('alert-demo .btn');
const alertWarning = $('[ng-reflect-ng-class="alert-warning"]');
const getAlertCount = $$('alert > div');

const getCloseButton = (tabNumber:number) => {
return 'alert-demo alert:nth-child(' + tabNumber + ') .close';
const getCloseButton = (tabNumber: number) => {
return `alert-demo alert:nth-child(${tabNumber}) .close`;
};

async function countGetAlertCount(): Promise<number> {
return await getAlertCount.count();
}

describe('Alerts page test on bootstrap 3', () => {
beforeAll(() => {
browser.get('#/alerts');
browser.ignoreSynchronization = true;
// Not sure, that we actually need browser.ignoreSynchronization = true; so comment it for now
// browser.ignoreSynchronization = true;
});

afterAll(() => {
leftPanelTests.checkLeftPanelMini();
leftPanelTests.checkLeftPanelMaxi();
});

it('Default warnings count', () => {
expect(getAlertCount.count()).toBe(3);
expect(countGetAlertCount).toBe(3);
});

it('Adding warnings', () => {
buttonAddAlert.click();
buttonAddAlert.click();
expect(getAlertCount.count()).toBe(5);

expect(countGetAlertCount).toBe(5);
});
using (DataProvider.alertTableContains, (data:any, description:string) => {
it ('Check tab texts: ' + description, () => {
expect(data.element().getText()).toContain(data.actualResult);

using(DataProvider.alertTableContains, (data: any, description: string) => {
it(`Check tab texts: ${description}`, async () => {
const expectedRes = data.actualResult;
const actualRes = await data.element().getText();

expect(actualRes).toContain(expectedRes);
});
});
it('Warning alert is disappear', () => {

it('Warning alert is disappear', async () => {
browser.sleep(3000);
expect(alertWarning.isPresent()).toBe(false);
const actualRes = await alertWarning.isPresent();

expect(actualRes).toBeFalsy();
});

it('User can delete danger and success alerts', () => {
$(getCloseButton(3)).click();
$(getCloseButton(2)).click();
$(getCloseButton(1)).click();
expect(getAlertCount.count()).toBe(1);

expect(countGetAlertCount).toBe(1);
});

it('User can delete added alerts', () => {
buttonAddAlert.click();
$(getCloseButton(1)).click();
expect(getAlertCount.count()).toBe(1);

expect(countGetAlertCount).toBe(1);
});
});
Loading

0 comments on commit 5136fd6

Please sign in to comment.