From 74754ef34d7fb2b2f91e6afa467bb68d0bc5c85f Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Sun, 11 Jun 2017 13:04:58 +0200 Subject: [PATCH] Add some test to investments feature for suggestions on creation --- spec/features/budgets/investments_spec.rb | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/spec/features/budgets/investments_spec.rb b/spec/features/budgets/investments_spec.rb index ef84cc6fc..b49fa8ddc 100644 --- a/spec/features/budgets/investments_spec.rb +++ b/spec/features/budgets/investments_spec.rb @@ -4,6 +4,7 @@ feature 'Budget Investments' do let(:author) { create(:user, :level_two, username: 'Isabel') } let(:budget) { create(:budget, name: "Big Budget") } + let(:other_budget) { create(:budget, name: "What a Budget!") } let(:group) { create(:budget_group, name: "Health", budget: budget) } let!(:heading) { create(:budget_heading, name: "More hospitals", group: group) } @@ -248,6 +249,56 @@ feature 'Budget Investments' do expect(page).to have_content error_message end + context 'Suggest' do + factory = :budget_investment + + scenario 'Show up to 5 suggestions', :js do + login_as(author) + + %w(first second third fourth fifth sixth).each do |ordinal| + create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) + end + create(factory, title: "This is the last #{factory}", budget: budget) + + visit new_budget_investment_path(budget) + fill_in "budget_investment_title", with: "search" + + within("div#js-suggest") do + expect(page).to have_content ("You are seeing 5 of 6 investments containing the term 'search'") + end + end + + scenario 'No found suggestions', :js do + login_as(author) + + %w(first second third fourth fifth sixth).each do |ordinal| + create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) + end + + visit new_budget_investment_path(budget) + fill_in "budget_investment_title", with: "item" + + within('div#js-suggest') do + expect(page).to_not have_content ('You are seeing') + end + end + + scenario "Don't show suggestions from a different budget", :js do + login_as(author) + + %w(first second third fourth fifth sixth).each do |ordinal| + create(factory, title: "#{ordinal.titleize} #{factory}, has search term", budget: budget) + end + + visit new_budget_investment_path(other_budget) + fill_in "budget_investment_title", with: "search" + + within('div#js-suggest') do + expect(page).to_not have_content ('You are seeing') + end + end + end + scenario 'Ballot is not visible' do login_as(author)