Skip to content

Commit

Permalink
refactor libraries screen functions into screen class
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Dec 6, 2018
1 parent 8faef97 commit a20a3a0
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions UI/e2e/tests/library.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,34 @@ const uuidv4 = require('uuid/v4');

const EC = protractor.ExpectedConditions;

async function getLibraryNames() {
const libraryNameRows = element.all(by.css('div.es-row-highlight'));
await browser.wait(libraryNameRows.isPresent(), 5000);
return libraryNameRows.map(el => {
return el.element(by.tagName('span')).getText();
});
}

async function getLibraryRowByLibraryName(name) {
const libraryNameRows = element.all(by.css('div.es-row-highlight'));
await browser.wait(libraryNameRows.isPresent(), 5000);
await browser.wait(libraryNameRows.isPresent(), 5000);
class LibrariesScreen {
async getLibraryNames() {
const libraryNameRows = element.all(by.css('div.es-row-highlight'));
await browser.wait(libraryNameRows.isPresent(), 5000);
return libraryNameRows.map(el => {
return el.element(by.tagName('span')).getText();
});
}

return libraryNameRows.filter(async el => {
const libraryNameText = await el.element(by.tagName('span')).getText();
return libraryNameText === name;
}).first();
}

async function getLeaveLibraryButton() {
const leaveLibraryButton = element.all(by.css('i.es-icon-button-large'));
await browser.wait(leaveLibraryButton.isPresent(), 5000);
return leaveLibraryButton.filter(async el => {
const buttonIconName = await el.getText();
return buttonIconName === 'navigate_before';
}).first();
async getLibraryRowByName(name) {
const libraryNameRows = element.all(by.css('div.es-row-highlight'));
await browser.wait(libraryNameRows.isPresent(), 5000);
await browser.wait(libraryNameRows.isPresent(), 5000);

return libraryNameRows.filter(async el => {
const libraryNameText = await el.element(by.tagName('span')).getText();
return libraryNameText === name;
}).first();
}

async getLeaveLibraryButton() {
const leaveLibraryButton = element.all(by.css('i.es-icon-button-large'));
await browser.wait(leaveLibraryButton.isPresent(), 5000);
return leaveLibraryButton.filter(async el => {
const buttonIconName = await el.getText();
return buttonIconName === 'navigate_before';
}).first();
}
}

describe('Library functionality', function() {
Expand All @@ -44,7 +46,9 @@ describe('Library functionality', function() {

const libraryName = uuidv4();

const libraryNameElementsBeforeTest = getLibraryNames();
const librariesScreen = new LibrariesScreen();

const libraryNameElementsBeforeTest = await librariesScreen.getLibraryNames();
expect(libraryNameElementsBeforeTest).not.toContain(libraryName);

// The libraries have to be loaded from the server, so wait for them to be loaded before the add button will be visible.
Expand All @@ -70,7 +74,7 @@ describe('Library functionality', function() {
const createLibraryModal = element(by.id('createLibraryControlModal'));
await browser.wait(EC.invisibilityOf(createLibraryModal), 5000, 'Create library modal did not close');

const libraryNameElements = await getLibraryNames();
const libraryNameElements = await librariesScreen.getLibraryNames();
expect(libraryNameElements).toContain(libraryName);
});

Expand All @@ -80,6 +84,8 @@ describe('Library functionality', function() {

const libraryName = uuidv4();

const librariesScreen = new LibrariesScreen();

// The libraries have to be loaded from the server, so wait for them to be loaded before the add button will be visible.
const addLibraryButton = element(by.css('.es-icon-button'));
await browser.wait(addLibraryButton.isPresent(), 5000);
Expand All @@ -105,14 +111,14 @@ describe('Library functionality', function() {
const createLibraryModal = element(by.id('createLibraryControlModal'));
await browser.wait(EC.invisibilityOf(createLibraryModal), 5000, 'Create library modal did not close');

const libraryRow = await getLibraryRowByLibraryName(libraryName);
const libraryRow = await librariesScreen.getLibraryRowByName(libraryName);
await browser.wait(EC.elementToBeClickable(libraryRow), 5000);
await libraryRow.click();

const leaveLibraryButton = await getLeaveLibraryButton();
const leaveLibraryButton = await librariesScreen.getLeaveLibraryButton();
await leaveLibraryButton.click();

const libraryNameElementsAfterLeave = await getLibraryNames();
const libraryNameElementsAfterLeave = await librariesScreen.getLibraryNames();
expect(libraryNameElementsAfterLeave).toContain(libraryName);
});
});

0 comments on commit a20a3a0

Please sign in to comment.