davidteren
3/16/2019 - 12:58 PM

System Tests

 require "rails_helper"
#
# RSpec.describe "visit app", type: :system do
#
#   # it "allows a user to create a project with tasks" do
#   #   visit new_project_path
#   #   fill_in "Name", with: "Project Runway"
#   #   fill_in "Tasks", with: "Choose Fabric:3\nMake it Work:5"
#   #   click_on("Create Project")
#   #   visit projects_path
#   #   expect(page).to have_content("Project Runway")
#   #   expect(page).to have_content(8)
#   # end
#
#   let(:user) { create(:user, password: "test1234") }
#
#   it 'allows user to sign in' do
#     visit root_path
#     fill_in "Email", with: 'admin@radiobot.com'
#     fill_in "Password", with: 'admin1234'
#     click_on('Log in')
#     assert_selector 'p.notice', text: 'Signed in successfully.'
#
#   end
#
# end

require 'rails_helper'

RSpec.describe "landing page_and_authentication", type: :system do

  let(:user) { create(:user, password: "test1234") }

  def login
    visit root_path
    fill_in "Email", with: user.email
    fill_in "Password", with: user.password
    click_on("Log in")
    assert_selector 'p.notice', text: 'Signed in successfully.'
  end

  context 'valid login' do
    it "allows a user to login and access the landing page" do
      login
      visit root_path
      expect(page).to have_content('Home#index')
    end

    it 'allows the user to logout' do
      login
      click_on("Logout")
      assert_selector 'p.alert', text: 'You need to sign in or sign up before continuing.'
    end
  end

  context 'invalid login' do
    it 'declines invalid email' do
      visit root_path
      fill_in "Email", with: 'foo@bar.com'
      fill_in "Password", with: user.password
      click_on("Log in")
      assert_selector 'p.alert', text: 'Invalid Email or password.'
    end

    it 'declines invalid password' do
      visit root_path
      fill_in "Email", with: user.email
      fill_in "Password", with: 'notvalidpass'
      click_on("Log in")
      assert_selector 'p.alert', text: 'Invalid Email or password.'
    end
  end

  context 'deactivated account' do
    it 'declines non active acount' do
    end
  end

  context 'Edit Account Details' do
    xit 'allows the user to change their email and password' do
      login
      click_on("Edit Account Details")
      fill_in "Email", with: 'someone@somewhere.com'
      fill_in "Password", with: 'newpassword123'
      fill_in "Password confirmation", with: 'newpassword123'
      fill_in "Current password", with: user.password
      click_on("Update")
    end

    xit 'various tests for blank feilds in form', pending: 'write tests here' do
    end
  end
end