From 4781d6cc8440cd5801f415f92fc79485acc8d52e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 12 Apr 2021 09:47:07 +0200 Subject: [PATCH] Add new (and first) component: DistributorTitle - Simple wrapper around `

` for distributor title, used in the shop front --- app/components/distributor_title_component.rb | 7 +++++++ .../distributor_title_component.html.haml | 1 + spec/components/distributor_title_component_spec.rb | 8 ++++++++ .../stories/distributor_title_component_stories.rb | 7 +++++++ 4 files changed, 23 insertions(+) create mode 100644 app/components/distributor_title_component.rb create mode 100644 app/components/distributor_title_component/distributor_title_component.html.haml create mode 100644 spec/components/distributor_title_component_spec.rb create mode 100644 spec/components/stories/distributor_title_component_stories.rb diff --git a/app/components/distributor_title_component.rb b/app/components/distributor_title_component.rb new file mode 100644 index 0000000000..bd2c78c7ab --- /dev/null +++ b/app/components/distributor_title_component.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class DistributorTitleComponent < ViewComponent::Base + def initialize(name:) + @name = name + end +end diff --git a/app/components/distributor_title_component/distributor_title_component.html.haml b/app/components/distributor_title_component/distributor_title_component.html.haml new file mode 100644 index 0000000000..218f0570aa --- /dev/null +++ b/app/components/distributor_title_component/distributor_title_component.html.haml @@ -0,0 +1 @@ +%h3= @name diff --git a/spec/components/distributor_title_component_spec.rb b/spec/components/distributor_title_component_spec.rb new file mode 100644 index 0000000000..3b206c4b2d --- /dev/null +++ b/spec/components/distributor_title_component_spec.rb @@ -0,0 +1,8 @@ +require "spec_helper" + +describe "DistributorTitle tests", type: :component do + it "displays distributor title with its name" do + render_inline(DistributorTitleComponent.new(name: "Freddy's Farm Shop")) { } + expect(page).to have_selector "h3", text: "Freddy's Farm Shop" + end +end diff --git a/spec/components/stories/distributor_title_component_stories.rb b/spec/components/stories/distributor_title_component_stories.rb new file mode 100644 index 0000000000..9a292449b5 --- /dev/null +++ b/spec/components/stories/distributor_title_component_stories.rb @@ -0,0 +1,7 @@ +class DistributorTitleComponentStories < ViewComponent::Storybook::Stories + story(:default) do + controls do + text(:name, "Freddy s Farm Shop") + end + end +end