Skip to content

Commit

Permalink
Merge pull request #2855 from cloudfoundry-incubator/e2e-bind-app
Browse files Browse the repository at this point in the history
Services E2E: Service Instance creation with App Binding
  • Loading branch information
richard-cox authored Sep 3, 2018
2 parents eceb0e5 + c342477 commit 3fc8e33
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/test-e2e/e2e.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ServiceConfig {
name: string;
}
export interface E2EServicesConfig {
bindApp: string;
publicService: ServiceConfig;
privateService: ServiceConfig;
spaceScopedService: ServiceConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export class CreateServiceInstanceStepper extends StepperComponent {
private spaceFieldName = 'space';
private serviceFieldName = 'service';
private serviceNameFieldName = 'name';
private bindApp = 'apps';

constructor() {
super();
Expand Down Expand Up @@ -37,6 +38,10 @@ export class CreateServiceInstanceStepper extends StepperComponent {
return this.getStepperForm().fill({ [this.serviceNameFieldName]: serviceInstanceName });
}

setBindApp = (bindAppName: string) => {
return this.getStepperForm().fill({ [this.bindApp]: bindAppName });
}

isBindAppStepDisabled = () => {
return this.isStepDisabled('Bind App (Optional)');
}
Expand Down
106 changes: 106 additions & 0 deletions src/test-e2e/marketplace/create-service-instances-bind-app-e2e.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { ElementFinder, promise, by, browser } from 'protractor';

import { e2e } from '../e2e';
import { ConsoleUserType } from '../helpers/e2e-helpers';
import { MetaCard } from '../po/meta-card.po';
import { CreateServiceInstance } from './create-service-instance.po';
import { ServicesHelperE2E } from './services-helper-e2e';
import { ServicesWallPage } from './services-wall.po';

describe('Create Service Instance with binding', () => {
const createServiceInstance = new CreateServiceInstance();
const servicesWall = new ServicesWallPage();
let servicesHelperE2E: ServicesHelperE2E;
let cardIdx = -1;
beforeAll(() => {
const e2eSetup = e2e.setup(ConsoleUserType.user)
.clearAllEndpoints()
.registerDefaultCloudFoundry()
.connectAllEndpoints(ConsoleUserType.user)
.connectAllEndpoints(ConsoleUserType.admin)
.getInfo();
servicesHelperE2E = new ServicesHelperE2E(e2eSetup, createServiceInstance);
});

beforeEach(() => {
createServiceInstance.navigateTo();
createServiceInstance.waitForPage();
});

it('- should reach create service instance page', () => {
expect(createServiceInstance.isActivePage()).toBeTruthy();
});

it('- should be able to to create a service instance with binding', () => {

const servicesSecrets = e2e.secrets.getDefaultCFEndpoint().services;
servicesHelperE2E.createService(servicesSecrets.publicService.name, false, servicesSecrets.bindApp);
servicesWall.waitForPage();

const serviceName = servicesHelperE2E.serviceInstanceName;

servicesWall.serviceInstancesList.cards.getCards().then(
(cards: ElementFinder[]) => {
return cards.map(card => {
const metaCard = new MetaCard(card);
return metaCard.getTitle();
});
}).then(cardTitles => {
promise.all(cardTitles).then(titles => {
expect(titles.filter((t, idx) => {
const isCorrectCard = (t === serviceName);
if (isCorrectCard) {
cardIdx = idx;

const card = servicesWall.serviceInstancesList.cards.getCard(cardIdx);
card.getMetaCardItems().then(metaCardRows => {
expect(metaCardRows[1].value).toBe(servicesSecrets.publicService.name);
expect(metaCardRows[2].value).toBe('shared');
expect(metaCardRows[3].value).toBe('1');
}).catch(e => fail(e));
}
return isCorrectCard;
}).length).toBe(1);
});
}).catch(e => fail(e));


});

it('- should have correct number in list view', () => {
servicesWall.navigateTo();
servicesWall.waitForPage();

expect(servicesWall.serviceInstancesList.isCardsView()).toBeTruthy();

// Switch to list view
servicesWall.serviceInstancesList.header.getCardListViewToggleButton().click();
expect(servicesWall.serviceInstancesList.isTableView()).toBeTruthy();
const servicesSecrets = e2e.secrets.getDefaultCFEndpoint().services;

// Filter for name
servicesWall.serviceInstancesList.header.setSearchText(servicesHelperE2E.serviceInstanceName)
.then(() => {
servicesWall.serviceInstancesList.table.getRows().then((rows: ElementFinder[]) => {
expect(rows.length).toBe(1);

const attachedApps = rows[0].element(by.css('.mat-column-attachedApps'));

expect(attachedApps.getText()).toBe(servicesSecrets.bindApp);

// Navigate to Apps
attachedApps.element(by.tagName('a')).click();

browser.getCurrentUrl().then(url => {
expect(url.endsWith('summary?breadcrumbs=service-wall')).toBeTruthy();
});
});
});
});

afterAll((done) => {
servicesHelperE2E.cleanUpServiceInstance(servicesHelperE2E.serviceInstanceName).then(() => done());
});
});


11 changes: 7 additions & 4 deletions src/test-e2e/marketplace/services-helper-e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ServicesHelperE2E {
);
}

createService = (serviceName: string, marketplaceMode = false) => {
createService = (serviceName: string, marketplaceMode = false, bindApp: string = null) => {
this.createServiceInstance.waitForPage();

// Select CF/Org/Space
Expand All @@ -72,7 +72,7 @@ export class ServicesHelperE2E {
// Bind App
this.createServiceInstance.stepper.isBindAppStepDisabled().then(bindAppDisabled => {
if (!bindAppDisabled) {
this.setBindApp();
this.setBindApp(bindApp);
this.createServiceInstance.stepper.next();
}

Expand All @@ -99,9 +99,12 @@ export class ServicesHelperE2E {
this.createServiceInstance.stepper.setServiceName(this.serviceInstanceName);
}

setBindApp = () => {
setBindApp = (bindApp: string = null) => {
this.createServiceInstance.stepper.waitForStep('Bind App (Optional)');
// Optional step can be skipped

if (!!bindApp) {
this.createServiceInstance.stepper.setBindApp(bindApp);
}
expect(this.createServiceInstance.stepper.canPrevious()).toBeTruthy();
expect(this.createServiceInstance.stepper.canNext()).toBeTruthy();
expect(this.createServiceInstance.stepper.canCancel()).toBeTruthy();
Expand Down
24 changes: 23 additions & 1 deletion src/test-e2e/marketplace/services-wall.po.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { Page } from '../po/page.po';
import { ListComponent } from '../po/list.po';
import { ElementArrayFinder } from 'protractor';
import { ElementArrayFinder, promise, ElementFinder } from 'protractor';
import { MetaCard } from '../po/meta-card.po';

export interface ServiceInstance {
serviceInstanceName: promise.Promise<string>;
spaceName: promise.Promise<string>;
serviceName: promise.Promise<string>;
planName: promise.Promise<string>;
tags?: promise.Promise<string>;
applicationsAttached?: promise.Promise<string>;
creationDate?: promise.Promise<string>;
}

export class ServicesWallPage extends Page {

Expand All @@ -12,4 +23,15 @@ export class ServicesWallPage extends Page {
getServiceInstances = (): ElementArrayFinder => {
return this.serviceInstancesList.cards.getCards();
}

getServiceInstanceFromCard = (card: ElementFinder): promise.Promise<ServiceInstance> => {
const metaCard = new MetaCard(card);
return metaCard.getMetaCardItems().then(items => ({
serviceInstanceName: metaCard.getTitle(),
spaceName: items[0].value,
serviceName: items[1].value,
planName: items[2].value,
applicationsAttached: items[3].value,
}));
}
}
13 changes: 13 additions & 0 deletions src/test-e2e/po/meta-card.po.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { Component } from './component.po';
import { ElementFinder, element, by, promise } from 'protractor';
import { MenuComponent } from './menu.po';

export interface MetaCardItem {
key: promise.Promise<string>;
value: promise.Promise<string>;
}

export class MetaCard extends Component {

constructor(private elementFinder: ElementFinder) {
Expand All @@ -21,6 +26,14 @@ export class MetaCard extends Component {
});
}

getMetaCardItems(): promise.Promise<MetaCardItem[]> {
const metaCardRows = this.elementFinder.all(by.css('.meta-card-item-row'));
return metaCardRows.then((rows: ElementFinder[]) => rows.map( row => ({
key: row.element(by.css('.meta-card-item__key')).getText(),
value: row.element(by.css('.meta-card-item__value')).getText()
})));
}

click() {
return this.elementFinder.click();
}
Expand Down

0 comments on commit 3fc8e33

Please sign in to comment.