Skip to content

Commit

Permalink
#10 async/await impl.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosalaperera committed Aug 26, 2019
1 parent 9bbc388 commit 419c65f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion e2e/pages/navigator.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { browser } = require('protractor');

module.exports = {
gotoGitHub: function () { return browser.get(''); },
gotoGitHub: async function () { return await browser.get(''); },
};
10 changes: 5 additions & 5 deletions e2e/pages/search-summary.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const EC = ExpectedConditions;
module.exports = {
resultsPaneElement: element(by.css('span[data-search-type="Users"]')),

countUsers: function () {
countUsers: async function () {
const self = this;
const presenceOf = EC.presenceOf(self.resultsPaneElement);
const tobeClickable = EC.elementToBeClickable(self.resultsPaneElement);

return browser.wait(EC.and(presenceOf, tobeClickable))
.then(function () {
return self.resultsPaneElement.getText();
});
await browser.wait(EC.and(presenceOf, tobeClickable));
const nrOfContributorsAsString = await self.resultsPaneElement.getText();

return parseInt(nrOfContributorsAsString);
},
};
12 changes: 7 additions & 5 deletions e2e/pages/search.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ module.exports = {
queryInputElement: element(by.css('.header-search-input')),
searchFormElement: element(by.css('.js-site-search-form')),

search: function () {
query: async function (text) {
const self = this;

return self.queryInputElement.sendKeys('kosalanuwan')
.then(function () { return self.searchFormElement.submit(); })
.then(function () { return browser.wait(EC.urlContains('q=kosalanuwan')); });

await self.queryInputElement.sendKeys(text);
await self.searchFormElement.submit();

const queryString = 'q=' + text;
return await browser.wait(EC.urlContains(queryString));
},
};
15 changes: 8 additions & 7 deletions e2e/steps/search-user.steps.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const { expect } = require('chai');;
const { Given, When, Then } = require('cucumber');
const { expect } = require('chai');;
const { navigator, searchPane, searchSummaryPane } = require('../pages');

Given('the user visits GitHub', { timeout: 60 * 1000 }, function () {
return navigator.gotoGitHub();
Given('the user visits GitHub', { timeout: 60 * 1000 }, async function () {
return await navigator.gotoGitHub();
});

When('a contributor name types and hit enter', function () {
return searchPane.search();
When('a contributor search for {string}', async function (name) {
return await searchPane.query(name);
});

Then('the search result summary should have at least 1 contributor', function () {
return expect(searchSummaryPane.countUsers()).to.eventually.equal('1');
Then('the search result summary should have at least {int} contributor', async function (nrOfContributors) {
const actualNrOfContributors = await searchSummaryPane.countUsers();
return expect(actualNrOfContributors).to.be.at.least(nrOfContributors);
});

0 comments on commit 419c65f

Please sign in to comment.