Skip to content

Commit

Permalink
fix(redirect): redirecting to index page after each action, closes #9
Browse files Browse the repository at this point in the history
  • Loading branch information
bahmutov committed Oct 4, 2016
1 parent c9626f0 commit abb9473
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ src/.DS_Store
todos.json
cypress/screenshots/
npm-debug.log
.DS_Store
17 changes: 13 additions & 4 deletions cypress/integration/try-cy-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ describe('a cy unit test', function () {
describe('todomvc app', function () {
const baseUrl = Cypress.env('HOST') || 'http://localhost:3000'

function addTodo () {
cy.get('.new-todo')
.type('new todo{enter}')
.get('ul.todo-list')
.find('li').should('not.be.empty')
}

beforeEach(function () {
cy.visit(baseUrl)
})
Expand All @@ -29,10 +36,12 @@ describe('todomvc app', function () {
})

it('can insert new todo', function () {
cy.get('.new-todo')
.type('new todo{enter}')
.get('ul.todo-list')
.find('li').should('not.be.empty')
addTodo()
})

it('can reload the page after adding new todo', () => {
addTodo()
cy.reload()
})

it('can view active todos', function () {
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "npm run lint",
"lint": "standard *.js src/**/*.js",
"start": "node --harmony src/start.js",
"start": "node src/start.js",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"commit": "commit-wizard",
"prod-test": "CYPRESS_HOST=$NOW_URL cypress ci"
Expand Down Expand Up @@ -36,8 +36,8 @@
"homepage": "https://github.com/bahmutov/todomvc-express#readme",
"dependencies": {
"body-parser": "1.15.2",
"check-more-types": "2.22.0",
"express": "4.14.0",
"check-more-types": "2.23.0",
"express": "5.0.0-alpha.2",
"fake-todos": "1.8.0",
"js-beautify": "1.6.4",
"lazy-ass": "1.5.0",
Expand All @@ -49,8 +49,8 @@
},
"devDependencies": {
"pre-git": "3.10.0",
"semantic-release": "6.3.0",
"standard": "8.0.0"
"semantic-release": "6.3.1",
"standard": "8.3.0"
},
"config": {
"pre-git": {
Expand Down
10 changes: 7 additions & 3 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function sendIndexPage (req, res) {
res.send(renderIndexPage())
}

function toIndex (req, res) {
res.redirect('/')
}

function sendAppCss (req, res) {
const cssPath = require('path').join(__dirname, 'app.css')
const css = require('fs').readFileSync(cssPath, 'utf-8')
Expand Down Expand Up @@ -76,8 +80,8 @@ app.get('/', sendIndexPage)
app.get('/app.css', sendAppCss)

// actions
app.post('/', addTodo, sendIndexPage)
app.delete('/', deleteTodo, sendIndexPage)
app.patch('/', markTodo, sendIndexPage)
app.post('/', addTodo, toIndex)
app.delete('/', deleteTodo, toIndex)
app.patch('/', markTodo, toIndex)

module.exports = app

0 comments on commit abb9473

Please sign in to comment.