require "test_helper"

class UsersIndexTest < ActionDispatch::IntegrationTest

  def setup
    @admin = users(:chuck)
    @non_admin = users(:archer)
  end

  test "index includes pagination" do
    log_in_as(@non_admin)
    get users_path
    assert_template "users/index"
    assert_select "nav.pagy-bootstrap-nav"
    # Add pagy pagination testing
    # User.paginate(page: 1).each do |user|
    #   assert_select 'a[href=?]', user_path(user), text: user.name
    # end

  end

  test "index as admin including pagination and delete links" do
    log_in_as(@admin)
    get users_path
    assert_template "users/index"
    assert_select "nav.pagy-bootstrap-nav"
    assert_difference "User.count", -1 do
      delete user_path(@non_admin)
    end
  end

  test "index as non-admin" do
    log_in_as(@non_admin)
    get users_path
    assert_select "a", text: "delete", count: 0
  end
end
