Browse Source

Add component test

pull/122/head
baarkerlounger 4 years ago
parent
commit
202803bb24
  1. 27
      spec/components/tab_navigation_component_spec.rb
  2. 3
      spec/rails_helper.rb

27
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

3
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

Loading…
Cancel
Save