require 'spec_helper'

describe "Landing", :js => true, :type => :feature, :capybara_feature => true do

  let (:user)  { FactoryGirl.create(:user) }

  before(:all) do
    MusicSession.delete_all
  end

  before(:each) do
    create_session(creator: user)
    formal_leave_by(user)
  end

  it "should render comments" do

    msh = MusicSession.first
    comment = "test comment"
    timestamp = "less than a minute ago"
    url = "/sessions/#{msh.id}"
    visit url

    # (1) Test a user creating a comment and ensure it displays.

    fill_in "txtSessionComment", with: comment
    find('#btnPostComment').trigger(:click)

    # comment body
    find('div.comment-text', text: comment)

    # timestamp
    find('div.comment-timestamp', text: timestamp)

    # (2) Test a user visiting a landing page with an existing comment.

    # re-visit page to reload from database
    visit url

    # comment body
    find('div.comment-text', text: comment)

    # timestamp
    find('div.comment-timestamp', text: timestamp)
  end
end