Skip to content

Commit

Permalink
#10 initial working prototype.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosalaperera committed Sep 1, 2019
1 parent 4e82125 commit f0f5dab
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 65 deletions.
5 changes: 5 additions & 0 deletions actions/helpers/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function listOf(delimitedValues) {
return delimitedValues.split(',').map(function (value) { return value.trim(); });
}

exports = module.exports = { listOf };
6 changes: 3 additions & 3 deletions actions/questions/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { shallSeeTodosOf, } = require('./shallSeeTodosOf.ask');
const { shallSeeTodosCountOf, } = require('./shallSeeTodosCountOf.ask');
const { shallSeeTodosOf } = require('./shallSeeTodosOf.ask');
const { shallSeeTodosCountOf } = require('./shallSeeTodosCountOf.ask');

exports = module.exports = {
shallSeeTodosOf,
shallSeeTodosCountOf,
shallSeeTodosCountOf
};
6 changes: 3 additions & 3 deletions actions/questions/shallSeeTodosCountOf.ask.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { expect, } = require('chai');
const { expect } = require('chai');
const { element, By } = require('protractor');

const nrofTodosElement = element(By.css('.todo-count'));

async function shallSeeTodosCountOf(nrOfTodos) {
const actualNrOfTodos = await nrofTodosElement.getText();

return expect(nrOfTodos).to.be.equal(parseInt(actualNrOfTodos, 10));
return expect(parseInt(actualNrOfTodos, 10)).to.be.at.least(nrOfTodos);
}

exports = module.exports = { shallSeeTodosCountOf, };
exports = module.exports = { shallSeeTodosCountOf };
7 changes: 3 additions & 4 deletions actions/questions/shallSeeTodosOf.ask.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
const { expect, } = require('chai');
const { expect } = require('chai');
const { element, By } = require('protractor');

const todoElements = element.all(By.css('.view'));

async function shallSeeTodosOf(todos) {
const expectedTodos = todos.split(', ');
const actualTodos = await todoElements.getText();

return expect(expectedTodos).to.have.all.members(actualTodos);
return expect(actualTodos).to.have.all.members(todos);
}

exports = module.exports = { shallSeeTodosOf, };
exports = module.exports = { shallSeeTodosOf };
11 changes: 7 additions & 4 deletions actions/tasks/addNewTodos.task.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
const { element, By, Key, promise, } = require('protractor');
const { element, By, promise } = require('protractor');

const newtodoInput = element(By.css('.new-todo'));

async function addNewTodos(todos) {
const todoFns = todos.split(', ').map(addNewTodo);
const todoFns = todos.map(addNewTodo);
return promise.all(todoFns);
}

async function addNewTodo(todo) {
return await newtodoInput.sendKeys(todo.trim() + '\n');
return newtodoInput.sendKeys(todo + '\n');
}

exports = module.exports = { addNewTodos, addNewTodo, };
exports = module.exports = {
addNewTodos,
addNewTodo
};
8 changes: 6 additions & 2 deletions actions/tasks/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
const { addNewTodo, addNewTodos, } = require('./addNewTodos.task');
const { visitHomepage, } = require('./visitPage.task');
const { addNewTodo, addNewTodos } = require('./addNewTodos.task');
const { trashTodoList } = require('./trashTodoList.task');
const { visitHomepage, visitHashActive, visitHashCompleted } = require('./visitPage.task');

exports = module.exports = {
addNewTodo,
addNewTodos,
trashTodoList,
visitHomepage,
visitHashActive,
visitHashCompleted
};
11 changes: 11 additions & 0 deletions actions/tasks/trashTodoList.task.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { element, By } = require('protractor');

async function trashTodoList() {
const nrOfTodos = await element.all(By.css('input[type=checkbox]')).count();
if (nrOfTodos > 0) {
await element(By.id('toggle-all')).click();
}
return element(By.css('.clear-completed')).click();
}

exports = module.exports = { trashTodoList }
21 changes: 17 additions & 4 deletions actions/tasks/visitPage.task.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
const { browser, } = require('protractor');
const { browser } = require('protractor');

function visitHomepage() {
return visitPage();
return visitPage('#');
}

function visitPage(path = browser.baseUrl) {
function visitHashActive() {
return visitPage('#/active');
}

function visitHashCompleted() {
return visitPage('#/completed');
}

function visitPage(hash) {
const path = browser.baseUrl + '/' + hash + '/';
return browser.driver.get(path);
}

exports = module.exports = { visitHomepage, visitPage, };
exports = module.exports = {
visitHomepage,
visitHashActive,
visitHashCompleted
};
27 changes: 27 additions & 0 deletions features/add-more-new-todos.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# language: en
@search @functional @gui @uat
Feature: Adding more things to do to the list
In order to avoid having to remember things that needs to do
KP wants to records all the things needs to get done.

@regression @integration @ci
Scenario Outline: Add more new items to the todo list

Given that KP has a list of things to do such as "<todo-list>"
When he adds "<more-todos>" to the list
Then he shall see both "<todo-list>" and "<more-todos>" in the list
And he shall see the number of todos should at least be <nr-of-todos>
When he looks at all things to do
Then he shall see the number of todos should at least be <total-nr-of-todos>

@smoke
Examples:
| todo-list | more-todos | nr-of-todos | total-nr-of-todos |
| Smile more often, Drink more water, Eat a banana | Quit the job, Sleep early, Eat a banana | 3 | 6 |
| Join the 5AM Club, Join the Audible Inner-circle | Go to Yoga, Meet the shrink | 2 | 4 |
| Sprint retrospective starts 2pm, Tech talk starts 6pm | Write some code, Do some demos, Smile more often, Drink more water | 4 | 6 |

@sanity @security
Examples:
| todo-list | more-todos | nr-of-todos | total-nr-of-todos |
| Join the 5AM Club, Join the Audible Inner-circle | Go to Yoga, Meet the shrink | 2 | 4 |
25 changes: 0 additions & 25 deletions features/add-new-todo-items.feature

This file was deleted.

30 changes: 30 additions & 0 deletions features/start-using-todo-list.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# language: en
@search @functional @gui @uat
Feature: Start using a fresh todo list
In order to avoid having to remember things that needs to do
KP wants to records all the things needs to get done.

Background:

Given that KP has a list of things to do such as "Write some code, Do some demos, Smile more often, Drink more water"

@regression @integration @ci
Scenario Outline: Create a fresh todo list

Given that KP starts a fresh todo list
When he adds "<new-todo-list>" to the list
Then he shall see the number of todos should at least be <nr-of-todos>
When he looks at pending things to do
Then he shall see "<new-todo-list>" in the list

@smoke
Examples:
| some-todo-list | new-todo-list | nr-of-todos |
| Quit the job, Sleep early, Eat a banana | Smile more often, Drink more water, Eat a banana | 3 |
| Go to Yoga, Meet the shrink | Join the 5AM Club, Join the Audible Inner-circle | 2 |
| Write some code, Do some demos, Smile more often, Drink more water | Sprint retrospective starts 2pm, Tech talk starts 6pm | 2 |

@sanity @security
Examples:
| some-todo-list | new-todo-list | nr-of-todos |
| Go to Yoga, Meet the shrink | Join the 5AM Club, Join the Audible Inner-circle | 2 |
16 changes: 16 additions & 0 deletions features/steps/given-list-of-todo.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { Given } = require('cucumber');
const { listOf } = require('../../actions/helpers/strings');
const { visitHomepage, visitHashActive, addNewTodos, trashTodoList } = require('../../actions/tasks');
const overrideOptions = { timeout: 60 * 1000 };

Given('that KP has a list of things to do such as {string}', overrideOptions, async function (todos) {
await visitHashActive();
await addNewTodos(listOf(todos));
return visitHomepage();
});

Given('that KP starts a fresh todo list', overrideOptions, async function () {
await visitHashActive();
await trashTodoList();
return visitHomepage();
});
15 changes: 15 additions & 0 deletions features/steps/then-assert-todos.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const { Then } = require('cucumber');
const { listOf } = require('../../actions/helpers/strings');
const { shallSeeTodosOf, shallSeeTodosCountOf } = require('../../actions/questions');

Then('he shall see the number of todos should at least be {int}', async function (nrOfTodos) {
return shallSeeTodosCountOf(nrOfTodos);
});

Then('he shall see {string} in the list', async function (todos) {
return shallSeeTodosOf(listOf(todos));
});

Then('he shall see both {string} and {string} in the list', async function (oldTodos, newTodos) {
return shallSeeTodosOf(listOf(oldTodos + ', ' + newTodos));
});
7 changes: 7 additions & 0 deletions features/steps/when-add-todos.steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { When } = require('cucumber');
const { listOf } = require('../../actions/helpers/strings');
const { addNewTodos } = require('../../actions/tasks');

When('he adds {string} to the list', async function (todos) {
return addNewTodos(listOf(todos));
});
10 changes: 10 additions & 0 deletions features/steps/when-filter-todos.step.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { When } = require('cucumber');
const { visitHomepage, visitHashActive } = require('../../actions/tasks');

When('he looks at pending things to do', async function () {
return visitHashActive();
});

When('he looks at all things to do', async function () {
return visitHomepage();
});
20 changes: 0 additions & 20 deletions steps/add-new-todo-items.steps.js

This file was deleted.

0 comments on commit f0f5dab

Please sign in to comment.