diff --git a/actions/helpers/strings.js b/actions/helpers/strings.js new file mode 100644 index 0000000..d845612 --- /dev/null +++ b/actions/helpers/strings.js @@ -0,0 +1,5 @@ +function listOf(delimitedValues) { + return delimitedValues.split(',').map(function (value) { return value.trim(); }); +} + +exports = module.exports = { listOf }; \ No newline at end of file diff --git a/actions/questions/index.js b/actions/questions/index.js index 40a8ea1..2627780 100644 --- a/actions/questions/index.js +++ b/actions/questions/index.js @@ -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 }; \ No newline at end of file diff --git a/actions/questions/shallSeeTodosCountOf.ask.js b/actions/questions/shallSeeTodosCountOf.ask.js index 225a66e..59b4551 100644 --- a/actions/questions/shallSeeTodosCountOf.ask.js +++ b/actions/questions/shallSeeTodosCountOf.ask.js @@ -1,4 +1,4 @@ -const { expect, } = require('chai'); +const { expect } = require('chai'); const { element, By } = require('protractor'); const nrofTodosElement = element(By.css('.todo-count')); @@ -6,7 +6,7 @@ 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, }; \ No newline at end of file +exports = module.exports = { shallSeeTodosCountOf }; \ No newline at end of file diff --git a/actions/questions/shallSeeTodosOf.ask.js b/actions/questions/shallSeeTodosOf.ask.js index e36b07c..1cf255e 100644 --- a/actions/questions/shallSeeTodosOf.ask.js +++ b/actions/questions/shallSeeTodosOf.ask.js @@ -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, }; \ No newline at end of file +exports = module.exports = { shallSeeTodosOf }; \ No newline at end of file diff --git a/actions/tasks/addNewTodos.task.js b/actions/tasks/addNewTodos.task.js index 7115e6d..c653e47 100644 --- a/actions/tasks/addNewTodos.task.js +++ b/actions/tasks/addNewTodos.task.js @@ -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, }; \ No newline at end of file +exports = module.exports = { + addNewTodos, + addNewTodo +}; \ No newline at end of file diff --git a/actions/tasks/index.js b/actions/tasks/index.js index 22ff8a9..2b8849c 100644 --- a/actions/tasks/index.js +++ b/actions/tasks/index.js @@ -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 }; \ No newline at end of file diff --git a/actions/tasks/trashTodoList.task.js b/actions/tasks/trashTodoList.task.js new file mode 100644 index 0000000..e9638d7 --- /dev/null +++ b/actions/tasks/trashTodoList.task.js @@ -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 } \ No newline at end of file diff --git a/actions/tasks/visitPage.task.js b/actions/tasks/visitPage.task.js index 2e632d5..adcbe40 100644 --- a/actions/tasks/visitPage.task.js +++ b/actions/tasks/visitPage.task.js @@ -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, }; \ No newline at end of file +exports = module.exports = { + visitHomepage, + visitHashActive, + visitHashCompleted +}; \ No newline at end of file diff --git a/features/add-more-new-todos.feature b/features/add-more-new-todos.feature new file mode 100644 index 0000000..d56bd42 --- /dev/null +++ b/features/add-more-new-todos.feature @@ -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 "" + When he adds "" to the list + Then he shall see both "" and "" in the list + And he shall see the number of todos should at least be + When he looks at all things to do + Then he shall see the number of todos should at least be + + @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 | diff --git a/features/add-new-todo-items.feature b/features/add-new-todo-items.feature deleted file mode 100644 index 1da6629..0000000 --- a/features/add-new-todo-items.feature +++ /dev/null @@ -1,25 +0,0 @@ -# language: en -@search @functional @gui @uat -Feature: Add new items to the 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. - - @regression @integration @ci - Scenario Outline: Add new items to the todo list - - Given that KP already has a list of things to do such as "" - When he adds "" to the list - Then he shall see both "" and "" in the todo list - And his number of todo items shall increase up to - - @smoke - Examples: - | todo-list | new-items | nr-of-todos | - | Smile more often, Drink more water, Eat a banana | Quit the job, Sleep early | 5 | - | Join the 5AM Club, Join the Audible Inner-circle | Go to Yoga, Meet the shrink | 4 | - | Sprint retrospective starts 2pm, Tech talk starts 6pm | Write some code, do some demos | 4 | - - @sanity @security - Examples: - | todo-list | new-items | nr-of-todos | - | Join the 5AM Club, Join the Audible Inner-circle | Go to Yoga, Meet the shrink | 4 | diff --git a/features/start-using-todo-list.feature b/features/start-using-todo-list.feature new file mode 100644 index 0000000..a5e6440 --- /dev/null +++ b/features/start-using-todo-list.feature @@ -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 "" to the list + Then he shall see the number of todos should at least be + When he looks at pending things to do + Then he shall see "" 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 | diff --git a/features/steps/given-list-of-todo.steps.js b/features/steps/given-list-of-todo.steps.js new file mode 100644 index 0000000..0b3c773 --- /dev/null +++ b/features/steps/given-list-of-todo.steps.js @@ -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(); +}); diff --git a/features/steps/then-assert-todos.steps.js b/features/steps/then-assert-todos.steps.js new file mode 100644 index 0000000..02d7d6e --- /dev/null +++ b/features/steps/then-assert-todos.steps.js @@ -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)); +}); diff --git a/features/steps/when-add-todos.steps.js b/features/steps/when-add-todos.steps.js new file mode 100644 index 0000000..b282102 --- /dev/null +++ b/features/steps/when-add-todos.steps.js @@ -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)); +}); diff --git a/features/steps/when-filter-todos.step.js b/features/steps/when-filter-todos.step.js new file mode 100644 index 0000000..5c7d889 --- /dev/null +++ b/features/steps/when-filter-todos.step.js @@ -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(); +}); diff --git a/steps/add-new-todo-items.steps.js b/steps/add-new-todo-items.steps.js deleted file mode 100644 index 689ad0c..0000000 --- a/steps/add-new-todo-items.steps.js +++ /dev/null @@ -1,20 +0,0 @@ -const { Given, When, Then, } = require('cucumber'); -const { visitHomepage, addNewTodos, } = require('../actions/tasks'); -const { shallSeeTodosOf, shallSeeTodosCountOf, } = require('../actions/questions'); - -Given('that KP already has a list of things to do such as {string}', { timeout: 60 * 1000 }, async function (todos) { - await visitHomepage(); - return addNewTodos(todos); -}); - -When('he adds {string} to the list', async function (todos) { - return await addNewTodos(todos); -}); - -Then('he shall see both {string} and {string} in the todo list', async function (oldTodos, newTodos) { - return shallSeeTodosOf(oldTodos + ', ' + newTodos); -}); - -Then('his number of todo items shall increase up to {int}', async function (nrOfTodos) { - return shallSeeTodosCountOf(nrOfTodos); -});