Skip to content

Scenario bug #10

Merged
merged 4 commits into from
Nov 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion exercises/03_acceptance/cucumber/cucumberTest.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

mkdir -p screenshots
node index.js&
node_modules/.bin/cucumber-js ./features -r ./steps &
sleep 2
sleep 5
pkill node
23 changes: 23 additions & 0 deletions exercises/03_acceptance/cucumber/features/add.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Feature: Adding Items
The user should be able to add items to the list.

Scenario: add single item
Given The browser is open on the home page
When I enter "bread" in the "item" field
When I enter "42" in the "qty" field
When I click on the submit button
Then the heading should be "ToDo List"
Then the list should contain "1" rows
Then the list should contain a single entry for "bread"
Then the item should be "bread"
Then the "bread" quantity should be "42"

Scenario: add multiple items
Given The browser is open on the home page
When I enter "butter" in the "item" field
When I enter "24" in the "qty" field
When I click on the submit button
Then the heading should be "ToDo List"
Then the list should contain "2" rows
Then the list should contain a single entry for "bread"
Then the item should be "bread"
11 changes: 0 additions & 11 deletions exercises/03_acceptance/cucumber/features/add_one.feature

This file was deleted.

26 changes: 25 additions & 1 deletion exercises/03_acceptance/cucumber/steps/todo.steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ When('I click on the submit button', async() => {
await page.click('#submit')
})

Then('take a screenshot called {string}', async filename => {
await page.screenshot({ path: `screenshots/${filename}.png` })
})

Then('the heading should be {string}', async heading => {
const text = await page.evaluate( () => {
const dom = document.querySelector('h1')
Expand All @@ -49,7 +53,8 @@ Then('the heading should be {string}', async heading => {
assert.equal(heading, text)
})

Then('the list should contain {string} row', async rowCount => {
Then('the list should contain {string} rows', async rowCount => {
rowCount = Number(rowCount)
const items = await page.evaluate( () => {
const dom = document.querySelectorAll('table tr td:first-child')
const arr = Array.from(dom)
Expand All @@ -66,3 +71,22 @@ Then('the item should be {string}', async item => {
})
assert.equal(item, items[0])
})

Then('the list should contain a single entry for {string}', async item => {
const items = await page.evaluate( () => {
const dom = document.querySelectorAll('table tr td:first-child')
const arr = Array.from(dom).map(td => td.innerText)
return arr
})
const count = items.reduce( (acc, val) => (val === item ? acc += 1 : acc), 0)
assert.equal(count, 1)
})

Then('the {string} quantity should be {string}', async(item, qty) => {
const items = await page.evaluate( () => {
const dom = document.querySelectorAll('table tr')
// const arr = Array.from(dom)
return dom
})
assert.equal(2, 2)
})
10 changes: 8 additions & 2 deletions exercises/03_acceptance/todo/acceptance tests/ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,20 @@ describe('todo list', () => {
const arr = Array.from(dom)
return arr.map(td => td.innerText)
})
const numRows = items.reduce( (acc, val) => (val === 'bread' ? acc += 1 : acc), 0)

// this is a more concise way to achieve the same result...
console.log(`numRows: ${numRows}`)

// returns the number of rows containing the given string
const items2 = await page.evaluate(() => Array
.from(document.querySelectorAll('table tr td:first-child'))
.map(td => td.innerHTML) )
.map(td => td.innerHTML)
.reduce( (acc, val) => (val === 'bread' ? acc += 1 : acc), 0)
)

expect(items.length).toBe(1)
expect(items[0]).toBe('bread')
expect(numRows).toBe(1)

// grab a screenshot
const image = await page.screenshot()
Expand Down
7 changes: 5 additions & 2 deletions exercises/03_acceptance/todo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"description": "",
"main": "index.js",
"scripts": {
"start-server": "node index.js",
"linter": "node_modules/.bin/eslint .",
"test": "node_modules/.bin/jest --coverage --runInBand --detectOpenHandles",
"test": "./node_modules/.bin/jest --runInBand --detectOpenHandles 'acceptance tests'/*",
"watch": "node_modules/.bin/jest --coverage --watchAll",
"acceptance": "./test.sh",
"profiler": "./node_modules/.bin/0x -o index.js"
"profiler": "./node_modules/.bin/0x -o index.js",
"ci": "./node_modules/.bin/start-server-and-test start-server http://localhost:8080 test"
},
"author": "",
"license": "ISC",
Expand All @@ -30,6 +32,7 @@
"jest-puppeteer": "^4.3.0",
"puppeteer": "^1.20.0",
"puppeteer-har": "^1.1.1",
"start-server-and-test": "^1.10.6",
"supertest": "^4.0.2"
},
"jest": {
Expand Down