const {url}       = require('../config')
const {randomStr} = require('../utils')

const selectors = {
  lastPost:   'div[id="posts-list"] > div:last-child .post-list--post-title a',
  createBtn:  'button#post-form--create__create-button',
  iterateBtn: 'button#posts--show--iterate-btn',
  reviseBtn:  'button#post-form--revise__create-button',
  titleInput: 'input#post-form--revise__title',
}

module.exports = {
  beforeAll: browser => {
    const username = randomStr()
    browser
      .url(`${url}/signin`)
      .waitForElementVisible('body', 100)
      .click('a#nav--log-in')
      .click('input#signin-form__username')
      .setValue('input#signin-form__username', username)
      .click('button#signin-form__signup-button')
      .waitForElementVisible('a#nav--user', 1000)
  },
  'Create a new post, then iterate': browser => {
    const title1   = randomStr()
    const title2   = 'New title'
    const content2 = 'New content'
    browser
      // Create Post
      .url(`${url}/posts/new`)
      .setValue('input#post-form--create__title', title1)
      .waitForElementVisible(selectors.createBtn, 1000)
      .click(selectors.createBtn)
      .url(`${url}/posts`)
      .waitForElementVisible('.post-list--post-title', 1000)
      .assert.containsText(selectors.lastPost, title1)
      // Create Iteration on Post
      .click(selectors.lastPost)
      .waitForElementVisible(selectors.iterateBtn, 1000)
      .click(selectors.iterateBtn)
      .keys(content2)
      .clearValue(selectors.titleInput)
      .setValue(selectors.titleInput, title2)
      .assert.elementPresent('#iteration-0')
      .assert.elementNotPresent('#iteration-1')
      .click(selectors.reviseBtn)
      // Assert that a new iteration was added to the timeline
      .waitForElementVisible('#iteration-1', 1000)
      .assert.elementPresent('#iteration-1')
      .click('button#iteration-1')
      .assert.containsText('#iteration-title', title2)
      .assert.containsText('#iteration-body', content2)
      .click('button#iteration-0')
      .assert.containsText('#iteration-title', title1)
  },
  after: browser => browser.end(),
};

@@ -247,22 +247,16 @@
 teBtn: '
-button
 #posts--
@@ -275,16 +275,16 @@
 e-btn',%0A
+
   revise
@@ -941,33 +941,34 @@
  browser%0A      /
-/
+**
  Create Post%0A   
@@ -959,24 +959,28 @@
  Create Post
+ **/
 %0A      .url(
@@ -1297,17 +1297,18 @@
 %0A      /
-/
+**
  Create 
@@ -1324,16 +1324,20 @@
  on Post
+ **/
 %0A      .
@@ -1362,16 +1362,34 @@
 stPost)%0A
+      .pause(100)%0A
       .w
@@ -1486,32 +1486,89 @@
 .keys(content2)%0A
+      .waitForElementVisible(selectors.titleInput, 1000)%0A
       .clearValu
@@ -1650,32 +1650,35 @@
  .assert.element
+Not
 Present('#iterat
@@ -1676,32 +1676,62 @@
 ('#iteration-0')
+ // Hidden until more than one
 %0A      .assert.e
@@ -1804,17 +1804,18 @@
 %0A      /
-/
+**
  Assert 
@@ -1860,16 +1860,20 @@
 timeline
+ **/
 %0A      .
@@ -1906,17 +1906,17 @@
 eration-
-1
+0
 ', 1000)
@@ -1908,32 +1908,77 @@
 ation-0', 1000)%0A
+      .assert.elementPresent('#iteration-0')%0A
       .assert.el
@@ -2012,38 +2012,32 @@
 )%0A      .click('
-button
 #iteration-1')%0A 
@@ -2142,24 +2142,24 @@
 , content2)%0A
+
       .click
@@ -2160,22 +2160,16 @@
 .click('
-button
 #iterati

Fix functional/posts/new FT