require 'rails_helper'

feature 'Root Page' do
  before(:all) do
    @habit = create(:capybara_habit)
  end
  after(:all) do
    @habit.destroy
  end
  scenario 'visit' do
    visit '/habitable'
    expect(page).to have_title "Habitable"
    #Navbar
      expect(page).to have_css "a", text: "Habitable"
      expect(page).to have_css "a", text: "New Habit"
    expect(page).to have_css "h1", text: "Habits"
    expect(page).to have_content "Apply sunscreen"
  end

  scenario 'submit form with good status' do
    visit '/habitable'
    fill_in 'habit_log_status', :with => "1"
    click_button "Send"
    expect(page).to have_content("Habit logged!")
    @habit.reload
    expect(@habit.streak).to eq(100)
  end

  scenario 'submit form with empty status' do
    visit '/habitable'
    fill_in 'habit_log_status', :with => ""
    click_button "Send"
    expect(page).to have_content("Status can't be blank")
  end

  scenario "submit form with status == 0" do
    visit '/habitable'
    fill_in 'habit_log_status', :with => "0"
    click_button "Send"
    @habit.reload
    expect(@habit.streak).to eq(0)
  end

  scenario "delete a habit" do
    visit '/habitable'
    find('.delete-btn', visible: false).click
    expect(page).to have_content("Habit deleted!")
  end
end
