From 202803bb2476e21d304614841272113f470626f7 Mon Sep 17 00:00:00 2001 From: baarkerlounger Date: Tue, 30 Nov 2021 19:09:59 +0000 Subject: [PATCH] Add component test --- .../tab_navigation_component_spec.rb | 27 +++++++++++++++++++ spec/rails_helper.rb | 3 +++ 2 files changed, 30 insertions(+) create mode 100644 spec/components/tab_navigation_component_spec.rb diff --git a/spec/components/tab_navigation_component_spec.rb b/spec/components/tab_navigation_component_spec.rb new file mode 100644 index 000000000..e000221c6 --- /dev/null +++ b/spec/components/tab_navigation_component_spec.rb @@ -0,0 +1,27 @@ +require "rails_helper" + +RSpec.describe TabNavigationComponent, type: :component do + let(:items) do + [{ name: "Application", url: "#", current: true }, + { name: "Notes", url: "#" }, + { name: "Timeline", url: "#" }] + end + + context "nav tabs appearing as selected" do + it "when the item is 'current' then that tab is selected" do + result = render_inline(described_class.new(items: items)) + + expect(result.css('.app-tab-navigation__link[aria-current="page"]').text).to include("Application") + end + end + + context "rendering tabs" do + it "renders all of the nav tabs specified in the items hash passed to it" do + result = render_inline(described_class.new(items: items)) + + expect(result.text).to include("Application") + expect(result.text).to include("Notes") + expect(result.text).to include("Timeline") + end + end +end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c9f3b729e..5787ffe66 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,6 +7,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ require "rspec/rails" require "capybara/rspec" require "selenium-webdriver" +require "view_component/test_helpers" Capybara.register_driver :headless do |app| options = Selenium::WebDriver::Firefox::Options.new @@ -80,4 +81,6 @@ RSpec.configure do |config| config.include Devise::Test::ControllerHelpers, type: :controller config.include Devise::Test::IntegrationHelpers, type: :request + config.include ViewComponent::TestHelpers, type: :component + config.include Capybara::RSpecMatchers, type: :component end