Merge pull request #4690 from consul/simplify_component_specs
Simplify type and current user in component tests
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Budgets::DurationComponent, type: :component do
|
describe Admin::Budgets::DurationComponent do
|
||||||
describe "#dates" do
|
describe "#dates" do
|
||||||
it "shows both dates when both are defined" do
|
it "shows both dates when both are defined" do
|
||||||
durable = double(
|
durable = double(
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Budgets::FormComponent, type: :component do
|
describe Admin::Budgets::FormComponent do
|
||||||
describe "#voting_styles_select_options" do
|
describe "#voting_styles_select_options" do
|
||||||
it "provides vote kinds" do
|
it "provides vote kinds" do
|
||||||
types = [["Knapsack", "knapsack"], ["Approval", "approval"]]
|
types = [["Knapsack", "knapsack"], ["Approval", "approval"]]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Budgets::IndexComponent, type: :component, controller: Admin::BudgetsController do
|
describe Admin::Budgets::IndexComponent, controller: Admin::BudgetsController do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(Admin::BudgetsController).to receive(:valid_filters).and_return(["all"])
|
allow_any_instance_of(Admin::BudgetsController).to receive(:valid_filters).and_return(["all"])
|
||||||
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Budgets::TableActionsComponent, type: :component, controller: Admin::BaseController do
|
describe Admin::Budgets::TableActionsComponent, controller: Admin::BaseController do
|
||||||
let(:budget) { create(:budget) }
|
let(:budget) { create(:budget) }
|
||||||
let(:component) { Admin::Budgets::TableActionsComponent.new(budget) }
|
let(:component) { Admin::Budgets::TableActionsComponent.new(budget) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent, type: :component do
|
describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent do
|
||||||
it "is not rendered for budgets with one group" do
|
it "is not rendered for budgets with one group" do
|
||||||
group = create(:budget_group, budget: create(:budget))
|
group = create(:budget_group, budget: create(:budget))
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::HiddenTableActionsComponent, type: :component do
|
describe Admin::HiddenTableActionsComponent do
|
||||||
let(:record) { create(:user) }
|
let(:record) { create(:user) }
|
||||||
let(:component) { Admin::HiddenTableActionsComponent.new(record) }
|
let(:component) { Admin::HiddenTableActionsComponent.new(record) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Organizations::TableActionsComponent, type: :component do
|
describe Admin::Organizations::TableActionsComponent do
|
||||||
let(:organization) { create(:organization) }
|
let(:organization) { create(:organization) }
|
||||||
let(:component) { Admin::Organizations::TableActionsComponent.new(organization) }
|
let(:component) { Admin::Organizations::TableActionsComponent.new(organization) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Poll::Officers::OfficersComponent, type: :component, controller: Admin::BaseController do
|
describe Admin::Poll::Officers::OfficersComponent, controller: Admin::BaseController do
|
||||||
let(:existing_officer) { create(:poll_officer, name: "Old officer") }
|
let(:existing_officer) { create(:poll_officer, name: "Old officer") }
|
||||||
let(:new_officer) { build(:poll_officer, name: "New officer") }
|
let(:new_officer) { build(:poll_officer, name: "New officer") }
|
||||||
let(:officers) { [existing_officer, new_officer] }
|
let(:officers) { [existing_officer, new_officer] }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Poll::Questions::FilterComponent, type: :component do
|
describe Admin::Poll::Questions::FilterComponent do
|
||||||
it "renders a button to submit the form" do
|
it "renders a button to submit the form" do
|
||||||
render_inline Admin::Poll::Questions::FilterComponent.new([])
|
render_inline Admin::Poll::Questions::FilterComponent.new([])
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Roles::TableActionsComponent, type: :component, controller: Admin::BaseController do
|
describe Admin::Roles::TableActionsComponent, controller: Admin::BaseController do
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
it "renders link to add the role for new records" do
|
it "renders link to add the role for new records" do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::Stats::SDG::GoalComponent, type: :component do
|
describe Admin::Stats::SDG::GoalComponent do
|
||||||
let(:component) { Admin::Stats::SDG::GoalComponent.new(goal: goal) }
|
let(:component) { Admin::Stats::SDG::GoalComponent.new(goal: goal) }
|
||||||
let(:goal) { SDG::Goal.sample }
|
let(:goal) { SDG::Goal.sample }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Admin::TableActionsComponent, type: :component, controller: Admin::BaseController do
|
describe Admin::TableActionsComponent, controller: Admin::BaseController do
|
||||||
let(:record) { create(:banner) }
|
let(:record) { create(:banner) }
|
||||||
|
|
||||||
it "renders links to edit and destroy a record by default" do
|
it "renders links to edit and destroy a record by default" do
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::BudgetComponent, type: :component do
|
describe Budgets::BudgetComponent do
|
||||||
let(:budget) { create(:budget) }
|
let(:budget) { create(:budget) }
|
||||||
let(:heading) { create(:budget_heading, budget: budget) }
|
let(:heading) { create(:budget_heading, budget: budget) }
|
||||||
let(:user) { create(:user) }
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
before do
|
before { sign_in(user) }
|
||||||
allow(controller).to receive(:current_user).and_return(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "budget header" do
|
describe "budget header" do
|
||||||
it "shows budget name and link to help" do
|
it "shows budget name and link to help" do
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::InvestmentComponent, type: :component do
|
describe Budgets::InvestmentComponent do
|
||||||
let(:user) { create(:user) }
|
before { sign_in(create(:user)) }
|
||||||
|
|
||||||
before do
|
|
||||||
allow(controller).to receive(:current_user).and_return(user)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "shows the investment image when defined" do
|
it "shows the investment image when defined" do
|
||||||
investment = create(:budget_investment, :with_image)
|
investment = create(:budget_investment, :with_image)
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::Investments::FormComponent, type: :component do
|
describe Budgets::Investments::FormComponent do
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
let(:budget) { create(:budget) }
|
let(:budget) { create(:budget) }
|
||||||
|
before { sign_in(create(:user)) }
|
||||||
before do
|
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
|
||||||
end
|
|
||||||
|
|
||||||
around do |example|
|
around do |example|
|
||||||
with_request_url(new_budget_investment_path(budget)) { example.run }
|
with_request_url(new_budget_investment_path(budget)) { example.run }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::Investments::VotesComponent, type: :component do
|
describe Budgets::Investments::VotesComponent do
|
||||||
describe "vote link" do
|
describe "vote link" do
|
||||||
context "when investment shows votes" do
|
context "when investment shows votes" do
|
||||||
let(:investment) { create(:budget_investment, title: "Renovate sidewalks in Main Street") }
|
let(:investment) { create(:budget_investment, title: "Renovate sidewalks in Main Street") }
|
||||||
@@ -9,7 +9,7 @@ describe Budgets::Investments::VotesComponent, type: :component do
|
|||||||
before { allow(investment).to receive(:should_show_votes?).and_return(true) }
|
before { allow(investment).to receive(:should_show_votes?).and_return(true) }
|
||||||
|
|
||||||
it "displays a button to support the investment to identified users" do
|
it "displays a button to support the investment to identified users" do
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
sign_in(create(:user))
|
||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
@@ -19,8 +19,6 @@ describe Budgets::Investments::VotesComponent, type: :component do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "disables the button to support the investment to unidentified users" do
|
it "disables the button to support the investment to unidentified users" do
|
||||||
allow(controller).to receive(:current_user).and_return(nil)
|
|
||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).to have_button count: 1, disabled: :all
|
expect(page).to have_button count: 1, disabled: :all
|
||||||
@@ -30,7 +28,7 @@ describe Budgets::Investments::VotesComponent, type: :component do
|
|||||||
it "shows the button to remove support when users have supported the investment" do
|
it "shows the button to remove support when users have supported the investment" do
|
||||||
user = create(:user)
|
user = create(:user)
|
||||||
user.up_votes(investment)
|
user.up_votes(investment)
|
||||||
allow(controller).to receive(:current_user).and_return(user)
|
sign_in(user)
|
||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::InvestmentsListComponent, type: :component do
|
describe Budgets::InvestmentsListComponent do
|
||||||
include Rails.application.routes.url_helpers
|
include Rails.application.routes.url_helpers
|
||||||
|
|
||||||
let(:budget) { create(:budget, :accepting) }
|
let(:budget) { create(:budget, :accepting) }
|
||||||
let(:group) { create(:budget_group, budget: budget) }
|
let(:group) { create(:budget_group, budget: budget) }
|
||||||
let(:heading) { create(:budget_heading, group: group) }
|
let(:heading) { create(:budget_heading, group: group) }
|
||||||
|
|
||||||
before { allow(controller).to receive(:current_user).and_return(nil) }
|
|
||||||
|
|
||||||
describe "#investments" do
|
describe "#investments" do
|
||||||
let(:component) { Budgets::InvestmentsListComponent.new(budget) }
|
let(:component) { Budgets::InvestmentsListComponent.new(budget) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::PhasesComponent, type: :component do
|
describe Budgets::PhasesComponent do
|
||||||
let(:budget) { create(:budget) }
|
let(:budget) { create(:budget) }
|
||||||
|
|
||||||
it "shows budget current phase main link when defined" do
|
it "shows budget current phase main link when defined" do
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::SubheaderComponent, type: :component do
|
describe Budgets::SubheaderComponent do
|
||||||
it "shows budget current phase name" do
|
it "shows budget current phase name" do
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
sign_in(create(:user))
|
||||||
budget = create(:budget, :informing)
|
budget = create(:budget, :informing)
|
||||||
|
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
@@ -17,7 +17,7 @@ describe Budgets::SubheaderComponent, type: :component do
|
|||||||
let(:budget) { create(:budget, :accepting) }
|
let(:budget) { create(:budget, :accepting) }
|
||||||
|
|
||||||
it "and user is level_two_or_three_verified shows a link to create a new investment" do
|
it "and user is level_two_or_three_verified shows a link to create a new investment" do
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user, :level_two))
|
sign_in(create(:user, :level_two))
|
||||||
|
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ describe Budgets::SubheaderComponent, type: :component do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "and user is not verified shows a link to account verification" do
|
it "and user is not verified shows a link to account verification" do
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
sign_in(create(:user))
|
||||||
|
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
@@ -53,8 +53,6 @@ describe Budgets::SubheaderComponent, type: :component do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "and user is not logged in shows links to sign in and sign up" do
|
it "and user is not logged in shows links to sign in and sign up" do
|
||||||
allow(controller).to receive(:current_user).and_return(nil)
|
|
||||||
|
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
expect(page).to have_content "To create a new budget investment you must"
|
expect(page).to have_content "To create a new budget investment you must"
|
||||||
@@ -77,12 +75,12 @@ describe Budgets::SubheaderComponent, type: :component do
|
|||||||
describe "See results link" do
|
describe "See results link" do
|
||||||
it "is showed when budget is finished and results are enabled for all users" do
|
it "is showed when budget is finished and results are enabled for all users" do
|
||||||
budget = create(:budget, :finished)
|
budget = create(:budget, :finished)
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
sign_in(create(:user))
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
expect(page).to have_link "See results"
|
expect(page).to have_link "See results"
|
||||||
|
|
||||||
allow(controller).to receive(:current_user).and_return(create(:administrator).user)
|
sign_in(create(:administrator).user)
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
expect(page).to have_link "See results"
|
expect(page).to have_link "See results"
|
||||||
@@ -90,12 +88,12 @@ describe Budgets::SubheaderComponent, type: :component do
|
|||||||
|
|
||||||
it "is not showed when budget is finished or results are disabled for all users" do
|
it "is not showed when budget is finished or results are disabled for all users" do
|
||||||
budget = create(:budget, :balloting, results_enabled: true)
|
budget = create(:budget, :balloting, results_enabled: true)
|
||||||
allow(controller).to receive(:current_user).and_return(create(:user))
|
sign_in(create(:user))
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
expect(page).not_to have_link "See results"
|
expect(page).not_to have_link "See results"
|
||||||
|
|
||||||
allow(controller).to receive(:current_user).and_return(create(:administrator).user)
|
sign_in(create(:administrator).user)
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
expect(page).not_to have_link "See results"
|
expect(page).not_to have_link "See results"
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Budgets::SupportsInfoComponent, type: :component do
|
describe Budgets::SupportsInfoComponent do
|
||||||
let(:budget) { create(:budget, :selecting) }
|
let(:budget) { create(:budget, :selecting) }
|
||||||
let(:group) { create(:budget_group, budget: budget) }
|
let(:group) { create(:budget_group, budget: budget) }
|
||||||
let(:component) { Budgets::SupportsInfoComponent.new(budget) }
|
let(:component) { Budgets::SupportsInfoComponent.new(budget) }
|
||||||
before { allow(component).to receive(:current_user).and_return(nil) }
|
|
||||||
|
|
||||||
it "renders when the budget is selecting" do
|
it "renders when the budget is selecting" do
|
||||||
create(:budget_heading, group: group)
|
create(:budget_heading, group: group)
|
||||||
@@ -42,7 +41,7 @@ describe Budgets::SupportsInfoComponent, type: :component do
|
|||||||
|
|
||||||
context "logged users" do
|
context "logged users" do
|
||||||
let(:user) { create(:user, :level_two) }
|
let(:user) { create(:user, :level_two) }
|
||||||
before { allow(component).to receive(:current_user).and_return(user) }
|
before { sign_in(user) }
|
||||||
|
|
||||||
it "shows supported investments" do
|
it "shows supported investments" do
|
||||||
heading = create(:budget_heading, budget: budget)
|
heading = create(:budget_heading, budget: budget)
|
||||||
@@ -67,8 +66,6 @@ describe Budgets::SupportsInfoComponent, type: :component do
|
|||||||
it "does not show supports for another budget" do
|
it "does not show supports for another budget" do
|
||||||
second_budget = create(:budget, phase: "selecting")
|
second_budget = create(:budget, phase: "selecting")
|
||||||
second_component = Budgets::SupportsInfoComponent.new(second_budget)
|
second_component = Budgets::SupportsInfoComponent.new(second_budget)
|
||||||
allow(second_component).to receive(:current_user).and_return(user)
|
|
||||||
|
|
||||||
create_list(:budget_investment, 2, :selected, budget: budget, voters: [user])
|
create_list(:budget_investment, 2, :selected, budget: budget, voters: [user])
|
||||||
create_list(:budget_investment, 3, :selected, budget: second_budget, voters: [user])
|
create_list(:budget_investment, 3, :selected, budget: second_budget, voters: [user])
|
||||||
|
|
||||||
@@ -76,6 +73,8 @@ describe Budgets::SupportsInfoComponent, type: :component do
|
|||||||
|
|
||||||
expect(page).to have_content "So far you've supported 2 projects."
|
expect(page).to have_content "So far you've supported 2 projects."
|
||||||
|
|
||||||
|
sign_in(user)
|
||||||
|
|
||||||
render_inline second_component
|
render_inline second_component
|
||||||
|
|
||||||
expect(page).to have_content "So far you've supported 3 projects."
|
expect(page).to have_content "So far you've supported 3 projects."
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Layout::LocaleSwitcherComponent, type: :component do
|
describe Layout::LocaleSwitcherComponent do
|
||||||
let(:component) { Layout::LocaleSwitcherComponent.new }
|
let(:component) { Layout::LocaleSwitcherComponent.new }
|
||||||
|
|
||||||
around do |example|
|
around do |example|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Layout::SocialComponent, type: :component do
|
describe Layout::SocialComponent do
|
||||||
describe "#render?" do
|
describe "#render?" do
|
||||||
it "renders when a social setting is present" do
|
it "renders when a social setting is present" do
|
||||||
Setting["twitter_handle"] = "myhandle"
|
Setting["twitter_handle"] = "myhandle"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Layout::TopLinksComponent, type: :component do
|
describe Layout::TopLinksComponent do
|
||||||
describe "#render?" do
|
describe "#render?" do
|
||||||
it "renders when a content block is defined" do
|
it "renders when a content block is defined" do
|
||||||
create(:site_customization_content_block, name: "top_links")
|
create(:site_customization_content_block, name: "top_links")
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe MachineLearning::CommentsSummaryComponent, type: :component do
|
describe MachineLearning::CommentsSummaryComponent do
|
||||||
let(:commentable) { double(summary_comment: double(body: "There's a general agreement")) }
|
let(:commentable) { double(summary_comment: double(body: "There's a general agreement")) }
|
||||||
let(:component) { MachineLearning::CommentsSummaryComponent.new(commentable) }
|
let(:component) { MachineLearning::CommentsSummaryComponent.new(commentable) }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Setting["feature.machine_learning"] = true
|
Setting["feature.machine_learning"] = true
|
||||||
Setting["machine_learning.comments_summary"] = true
|
Setting["machine_learning.comments_summary"] = true
|
||||||
allow(controller).to receive(:current_user).and_return(nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is displayed when the setting is enabled" do
|
it "is displayed when the setting is enabled" do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Pages::Help::SectionComponent, type: :component do
|
describe Pages::Help::SectionComponent do
|
||||||
describe "#image_path" do
|
describe "#image_path" do
|
||||||
it "returns the image for the first fallback language with an image" do
|
it "returns the image for the first fallback language with an image" do
|
||||||
allow(I18n).to receive(:fallbacks).and_return({ en: [:es, :de] })
|
allow(I18n).to receive(:fallbacks).and_return({ en: [:es, :de] })
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Relationable::RelatedListComponent, type: :component do
|
describe Relationable::RelatedListComponent do
|
||||||
let(:proposal) { create(:proposal) }
|
let(:proposal) { create(:proposal) }
|
||||||
let(:user_proposal) { create(:proposal, title: "I am user related") }
|
let(:user_proposal) { create(:proposal, title: "I am user related") }
|
||||||
let(:machine_proposal) { create(:proposal, title: "I am machine related") }
|
let(:machine_proposal) { create(:proposal, title: "I am machine related") }
|
||||||
@@ -14,8 +14,6 @@ describe Relationable::RelatedListComponent, type: :component do
|
|||||||
create(:related_content, parent_relationable: proposal,
|
create(:related_content, parent_relationable: proposal,
|
||||||
child_relationable: machine_proposal,
|
child_relationable: machine_proposal,
|
||||||
machine_learning: true)
|
machine_learning: true)
|
||||||
|
|
||||||
allow(controller).to receive(:current_user).and_return(nil)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "displays machine learning and user content when machine learning is enabled" do
|
it "displays machine learning and user content when machine learning is enabled" do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::HelpPageComponent, type: :component do
|
describe SDG::Goals::HelpPageComponent do
|
||||||
let(:goals) { SDG::Goal.all }
|
let(:goals) { SDG::Goal.all }
|
||||||
let(:component) { SDG::Goals::HelpPageComponent.new(goals) }
|
let(:component) { SDG::Goals::HelpPageComponent.new(goals) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::IndexComponent, type: :component do
|
describe SDG::Goals::IndexComponent do
|
||||||
let!(:goals) { SDG::Goal.all }
|
let!(:goals) { SDG::Goal.all }
|
||||||
let!(:phases) { SDG::Phase.all }
|
let!(:phases) { SDG::Phase.all }
|
||||||
let!(:component) { SDG::Goals::IndexComponent.new(goals, header: nil, phases: phases) }
|
let!(:component) { SDG::Goals::IndexComponent.new(goals, header: nil, phases: phases) }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::PlainTagListComponent, type: :component do
|
describe SDG::Goals::PlainTagListComponent do
|
||||||
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
|
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
|
||||||
let(:component) { SDG::Goals::PlainTagListComponent.new(debate) }
|
let(:component) { SDG::Goals::PlainTagListComponent.new(debate) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::ShowComponent, type: :component do
|
describe SDG::Goals::ShowComponent do
|
||||||
let!(:goal_1) { SDG::Goal[1] }
|
let!(:goal_1) { SDG::Goal[1] }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::TagCloudComponent, type: :component do
|
describe SDG::Goals::TagCloudComponent do
|
||||||
before do
|
before do
|
||||||
Setting["feature.sdg"] = true
|
Setting["feature.sdg"] = true
|
||||||
Setting["sdg.process.debates"] = true
|
Setting["sdg.process.debates"] = true
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::TagListComponent, type: :component do
|
describe SDG::Goals::TagListComponent do
|
||||||
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
|
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1], SDG::Goal[3]]) }
|
||||||
let(:component) { SDG::Goals::TagListComponent.new(debate) }
|
let(:component) { SDG::Goals::TagListComponent.new(debate) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Goals::TargetsComponent, type: :component do
|
describe SDG::Goals::TargetsComponent do
|
||||||
let(:goal) { SDG::Goal[1] }
|
let(:goal) { SDG::Goal[1] }
|
||||||
let(:component) { SDG::Goals::TargetsComponent.new(goal) }
|
let(:component) { SDG::Goals::TargetsComponent.new(goal) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::RelatedListSelectorComponent, type: :component do
|
describe SDG::RelatedListSelectorComponent do
|
||||||
let(:debate) { create(:debate) }
|
let(:debate) { create(:debate) }
|
||||||
let(:form) { ConsulFormBuilder.new(:debate, debate, ActionView::Base.new, {}) }
|
let(:form) { ConsulFormBuilder.new(:debate, debate, ActionView::Base.new, {}) }
|
||||||
let(:component) { SDG::RelatedListSelectorComponent.new(form) }
|
let(:component) { SDG::RelatedListSelectorComponent.new(form) }
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::TagListComponent, type: :component do
|
describe SDG::TagListComponent do
|
||||||
let(:debate) do
|
let(:debate) do
|
||||||
create(:debate,
|
create(:debate,
|
||||||
sdg_goals: [SDG::Goal[3]],
|
sdg_goals: [SDG::Goal[3]],
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Targets::PlainTagListComponent, type: :component do
|
describe SDG::Targets::PlainTagListComponent do
|
||||||
let(:debate) do
|
let(:debate) do
|
||||||
create(:debate,
|
create(:debate,
|
||||||
sdg_targets: [SDG::Target[1.1], SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")]
|
sdg_targets: [SDG::Target[1.1], SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDG::Targets::TagListComponent, type: :component do
|
describe SDG::Targets::TagListComponent do
|
||||||
let(:debate) do
|
let(:debate) do
|
||||||
create(:debate,
|
create(:debate,
|
||||||
sdg_targets: [SDG::Target[1.1], SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")]
|
sdg_targets: [SDG::Target[1.1], SDG::Target[3.2], create(:sdg_local_target, code: "3.2.1")]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDGManagement::MenuComponent, type: :component do
|
describe SDGManagement::MenuComponent do
|
||||||
let(:component) { SDGManagement::MenuComponent.new }
|
let(:component) { SDGManagement::MenuComponent.new }
|
||||||
|
|
||||||
before do
|
before do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDGManagement::Relations::IndexComponent, type: :component, controller: SDGManagement::RelationsController do
|
describe SDGManagement::Relations::IndexComponent, controller: SDGManagement::RelationsController do
|
||||||
before do
|
before do
|
||||||
allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters)
|
allow_any_instance_of(SDGManagement::RelationsController).to receive(:valid_filters)
|
||||||
.and_return(SDGManagement::RelationsController::FILTERS)
|
.and_return(SDGManagement::RelationsController::FILTERS)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDGManagement::Relations::SearchComponent, type: :component do
|
describe SDGManagement::Relations::SearchComponent do
|
||||||
describe "#goal_options" do
|
describe "#goal_options" do
|
||||||
it "orders goals by code in the select" do
|
it "orders goals by code in the select" do
|
||||||
component = SDGManagement::Relations::SearchComponent.new(label: "Search proposals")
|
component = SDGManagement::Relations::SearchComponent.new(label: "Search proposals")
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe SDGManagement::SubnavigationComponent, type: :component do
|
describe SDGManagement::SubnavigationComponent do
|
||||||
let(:component) do
|
let(:component) do
|
||||||
SDGManagement::SubnavigationComponent.new(current: :goals) do
|
SDGManagement::SubnavigationComponent.new(current: :goals) do
|
||||||
"Tab content"
|
"Tab content"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Shared::AdvancedSearchComponent, type: :component do
|
describe Shared::AdvancedSearchComponent do
|
||||||
let(:component) { Shared::AdvancedSearchComponent.new }
|
let(:component) { Shared::AdvancedSearchComponent.new }
|
||||||
|
|
||||||
context "JavaScript disabled" do
|
context "JavaScript disabled" do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Shared::BannerComponent, type: :component do
|
describe Shared::BannerComponent do
|
||||||
it "renders given a banner" do
|
it "renders given a banner" do
|
||||||
banner = create(:banner,
|
banner = create(:banner,
|
||||||
title: "Vote now!",
|
title: "Vote now!",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Shared::FilterSelectorComponent, type: :component do
|
describe Shared::FilterSelectorComponent do
|
||||||
it "renders a form with a select" do
|
it "renders a form with a select" do
|
||||||
component = Shared::FilterSelectorComponent.new(i18n_namespace: "budgets.investments.index")
|
component = Shared::FilterSelectorComponent.new(i18n_namespace: "budgets.investments.index")
|
||||||
allow(component).to receive(:valid_filters).and_return(["unfeasible", "winners"])
|
allow(component).to receive(:valid_filters).and_return(["unfeasible", "winners"])
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Shared::LinkListComponent, type: :component do
|
describe Shared::LinkListComponent do
|
||||||
it "renders nothing with an empty list" do
|
it "renders nothing with an empty list" do
|
||||||
render_inline Shared::LinkListComponent.new
|
render_inline Shared::LinkListComponent.new
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Shared::TagListComponent, type: :component do
|
describe Shared::TagListComponent do
|
||||||
let(:user_tag) { create(:tag, name: "user tag") }
|
let(:user_tag) { create(:tag, name: "user tag") }
|
||||||
let(:ml_tag) { create(:tag, name: "machine learning tag") }
|
let(:ml_tag) { create(:tag, name: "machine learning tag") }
|
||||||
let(:proposal) { create(:proposal, tag_list: [user_tag], ml_tag_list: [ml_tag]) }
|
let(:proposal) { create(:proposal, tag_list: [user_tag], ml_tag_list: [ml_tag]) }
|
||||||
@@ -9,7 +9,6 @@ describe Shared::TagListComponent, type: :component do
|
|||||||
before do
|
before do
|
||||||
Setting["feature.machine_learning"] = true
|
Setting["feature.machine_learning"] = true
|
||||||
Setting["machine_learning.tags"] = true
|
Setting["machine_learning.tags"] = true
|
||||||
allow(controller).to receive(:current_user).and_return(create(:administrator).user)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "displays machine learning tags when machine learning is enabled" do
|
it "displays machine learning tags when machine learning is enabled" do
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Widget::Feeds::DebateComponent, type: :component do
|
describe Widget::Feeds::DebateComponent do
|
||||||
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1]]) }
|
let(:debate) { create(:debate, sdg_goals: [SDG::Goal[1]]) }
|
||||||
let(:component) { Widget::Feeds::DebateComponent.new(debate) }
|
let(:component) { Widget::Feeds::DebateComponent.new(debate) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Widget::Feeds::FeedComponent, type: :component do
|
describe Widget::Feeds::FeedComponent do
|
||||||
it "renders a message when there are no items" do
|
it "renders a message when there are no items" do
|
||||||
feed = double(kind: "debates", items: [])
|
feed = double(kind: "debates", items: [])
|
||||||
component = Widget::Feeds::FeedComponent.new(feed)
|
component = Widget::Feeds::FeedComponent.new(feed)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Widget::Feeds::ProcessComponent, type: :component do
|
describe Widget::Feeds::ProcessComponent do
|
||||||
let(:process) { create(:legislation_process, sdg_goals: [SDG::Goal[1]]) }
|
let(:process) { create(:legislation_process, sdg_goals: [SDG::Goal[1]]) }
|
||||||
let(:component) { Widget::Feeds::ProcessComponent.new(process) }
|
let(:component) { Widget::Feeds::ProcessComponent.new(process) }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
require "rails_helper"
|
require "rails_helper"
|
||||||
|
|
||||||
describe Widget::Feeds::ProposalComponent, type: :component do
|
describe Widget::Feeds::ProposalComponent do
|
||||||
let(:proposal) { create(:proposal, sdg_goals: [SDG::Goal[1]]) }
|
let(:proposal) { create(:proposal, sdg_goals: [SDG::Goal[1]]) }
|
||||||
let(:component) { Widget::Feeds::ProposalComponent.new(proposal) }
|
let(:component) { Widget::Feeds::ProposalComponent.new(proposal) }
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,14 @@ require "capybara/rspec"
|
|||||||
require "selenium/webdriver"
|
require "selenium/webdriver"
|
||||||
require "view_component/test_helpers"
|
require "view_component/test_helpers"
|
||||||
|
|
||||||
|
module ViewComponent
|
||||||
|
module TestHelpers
|
||||||
|
def sign_in(user)
|
||||||
|
allow(controller).to receive(:current_user).and_return(user)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.include ViewComponent::TestHelpers, type: :component
|
config.include ViewComponent::TestHelpers, type: :component
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -20,6 +20,10 @@ RSpec.configure do |config|
|
|||||||
config.include(CommonActions)
|
config.include(CommonActions)
|
||||||
config.include(ActiveSupport::Testing::TimeHelpers)
|
config.include(ActiveSupport::Testing::TimeHelpers)
|
||||||
|
|
||||||
|
config.define_derived_metadata(file_path: Regexp.new("/spec/components/")) do |metadata|
|
||||||
|
metadata[:type] = :component
|
||||||
|
end
|
||||||
|
|
||||||
config.before(:suite) do
|
config.before(:suite) do
|
||||||
Rails.application.load_seed
|
Rails.application.load_seed
|
||||||
end
|
end
|
||||||
@@ -79,6 +83,10 @@ RSpec.configure do |config|
|
|||||||
sign_in(create(:administrator).user)
|
sign_in(create(:administrator).user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
config.before(:each, type: :component) do
|
||||||
|
sign_in(nil)
|
||||||
|
end
|
||||||
|
|
||||||
config.around(:each, :controller, type: :component) do |example|
|
config.around(:each, :controller, type: :component) do |example|
|
||||||
with_controller_class(example.metadata[:controller]) { example.run }
|
with_controller_class(example.metadata[:controller]) { example.run }
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user