Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Dec 4, 2023
1 parent 1f3b123 commit f4e541b
Show file tree
Hide file tree
Showing 24 changed files with 385 additions and 20 deletions.
5 changes: 5 additions & 0 deletions app/components/application_view_component_preview.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class ApplicationViewComponentPreview < ViewComponentContrib::Preview::Base
self.abstract_class = true

layout 'component_preview'
end
2 changes: 1 addition & 1 deletion app/components/common/form/radio_button/component.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= @form.radio_button @attribute, @title, class: "js-table-filter-btn", checked: true, style: @style, id: @checkbox_id, data: { **data_attributes} %>
<%= @form.radio_button @attribute, @title, class: "js-table-filter-btn", checked: true, style: @style, id: @checkbox_id, data: { **data_attributes} %>
17 changes: 3 additions & 14 deletions app/components/common/header/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,11 @@
<div class="c-toolbar__socials">
<% if user_signed_in? %>
<%= link_to destroy_user_session_path, class: "c-header__user", method: :delete, data: { 'turbo-method': 'delete' } do %>
<svg width="10" height="12" viewBox="0 0 10 12" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M6.85524 6.35494C7.34544 5.96927 7.70324 5.4404 7.87886 4.84191C8.05449 4.24342 8.0392 3.60507 7.83514 3.01567C7.63107 2.42628 7.24837 1.91514 6.74028 1.55337C6.23219 1.1916 5.62397 0.997192 5.00024 0.997192C4.37652 0.997192 3.7683 1.1916 3.26021 1.55337C2.75212 1.91514 2.36941 2.42628 2.16535 3.01567C1.96128 3.60507 1.946 4.24342 2.12162 4.84191C2.29725 5.4404 2.65505 5.96927 3.14524 6.35494C2.30528 6.69146 1.57239 7.24961 1.02469 7.9699C0.476991 8.69018 0.135024 9.54559 0.0352425 10.4449C0.0280198 10.5106 0.0338008 10.577 0.0522552 10.6405C0.0707096 10.7039 0.101476 10.7631 0.142798 10.8146C0.226252 10.9187 0.347634 10.9854 0.480243 10.9999C0.612851 11.0145 0.745822 10.9758 0.849905 10.8924C0.953988 10.8089 1.02066 10.6875 1.03524 10.5549C1.14503 9.57754 1.61109 8.67485 2.34435 8.01934C3.07762 7.36383 4.02669 7.00145 5.01024 7.00145C5.99379 7.00145 6.94287 7.36383 7.67613 8.01934C8.4094 8.67485 8.87545 9.57754 8.98524 10.5549C8.99884 10.6778 9.05746 10.7913 9.1498 10.8734C9.24213 10.9556 9.36163 11.0007 9.48524 10.9999H9.54024C9.67131 10.9849 9.79111 10.9186 9.87352 10.8156C9.95594 10.7125 9.9943 10.5811 9.98024 10.4499C9.87999 9.54804 9.53618 8.69043 8.98567 7.96904C8.43515 7.24765 7.6987 6.68968 6.85524 6.35494ZM5.00024 5.99994C4.60468 5.99994 4.218 5.88264 3.8891 5.66288C3.5602 5.44312 3.30386 5.13076 3.15248 4.76531C3.00111 4.39986 2.9615 3.99772 3.03867 3.60976C3.11584 3.2218 3.30632 2.86543 3.58603 2.58573C3.86573 2.30602 4.2221 2.11554 4.61006 2.03837C4.99802 1.9612 5.40016 2.00081 5.76561 2.15218C6.13106 2.30356 6.44342 2.5599 6.66318 2.8888C6.88294 3.2177 7.00024 3.60438 7.00024 3.99994C7.00024 4.53037 6.78953 5.03908 6.41446 5.41415C6.03938 5.78923 5.53068 5.99994 5.00024 5.99994Z"/>
</svg>
<%= t(:sign_out) %>
<%= render 'svg/person' %><%= t(:sign_out) %>
<% end %>
<% else %>
<%= link_to new_user_session_path, class: "c-header__user" do %>
<svg width="10" height="12" viewBox="0 0 10 12" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M6.85524 6.35494C7.34544 5.96927 7.70324 5.4404 7.87886 4.84191C8.05449 4.24342 8.0392 3.60507 7.83514 3.01567C7.63107 2.42628 7.24837 1.91514 6.74028 1.55337C6.23219 1.1916 5.62397 0.997192 5.00024 0.997192C4.37652 0.997192 3.7683 1.1916 3.26021 1.55337C2.75212 1.91514 2.36941 2.42628 2.16535 3.01567C1.96128 3.60507 1.946 4.24342 2.12162 4.84191C2.29725 5.4404 2.65505 5.96927 3.14524 6.35494C2.30528 6.69146 1.57239 7.24961 1.02469 7.9699C0.476991 8.69018 0.135024 9.54559 0.0352425 10.4449C0.0280198 10.5106 0.0338008 10.577 0.0522552 10.6405C0.0707096 10.7039 0.101476 10.7631 0.142798 10.8146C0.226252 10.9187 0.347634 10.9854 0.480243 10.9999C0.612851 11.0145 0.745822 10.9758 0.849905 10.8924C0.953988 10.8089 1.02066 10.6875 1.03524 10.5549C1.14503 9.57754 1.61109 8.67485 2.34435 8.01934C3.07762 7.36383 4.02669 7.00145 5.01024 7.00145C5.99379 7.00145 6.94287 7.36383 7.67613 8.01934C8.4094 8.67485 8.87545 9.57754 8.98524 10.5549C8.99884 10.6778 9.05746 10.7913 9.1498 10.8734C9.24213 10.9556 9.36163 11.0007 9.48524 10.9999H9.54024C9.67131 10.9849 9.79111 10.9186 9.87352 10.8156C9.95594 10.7125 9.9943 10.5811 9.98024 10.4499C9.87999 9.54804 9.53618 8.69043 8.98567 7.96904C8.43515 7.24765 7.6987 6.68968 6.85524 6.35494ZM5.00024 5.99994C4.60468 5.99994 4.218 5.88264 3.8891 5.66288C3.5602 5.44312 3.30386 5.13076 3.15248 4.76531C3.00111 4.39986 2.9615 3.99772 3.03867 3.60976C3.11584 3.2218 3.30632 2.86543 3.58603 2.58573C3.86573 2.30602 4.2221 2.11554 4.61006 2.03837C4.99802 1.9612 5.40016 2.00081 5.76561 2.15218C6.13106 2.30356 6.44342 2.5599 6.66318 2.8888C6.88294 3.2177 7.00024 3.60438 7.00024 3.99994C7.00024 4.53037 6.78953 5.03908 6.41446 5.41415C6.03938 5.78923 5.53068 5.99994 5.00024 5.99994Z"/>
</svg>
<%= t(:sign_in) %>
<%= render 'svg/person' %><%= t(:sign_in) %>
<% end %>
<% end %>
</div>
Expand All @@ -61,12 +55,7 @@
<div class="c-header__lang">
<div class="c-dropdown">
<span class="c-dropdown__label" onclick="this.parentNode.classList.toggle('is-open')">
<span class="c-dropdown__label__lang">
<%= current_language %>
</span>
<svg width="10" height="7" viewBox="0 0 10 7" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M4.50581 5.82828L0.505807 1.82828C0.232439 1.55491 0.232439 1.11169 0.505807 0.838326C0.779174 0.564959 1.22239 0.564959 1.49576 0.838326L5.00078 4.34335L8.50581 0.838326C8.77917 0.564959 9.22239 0.564959 9.49576 0.838326C9.76912 1.11169 9.76912 1.55491 9.49576 1.82828L5.49576 5.82828C5.22239 6.10164 4.77917 6.10164 4.50581 5.82828Z"/>
</svg>
<span class="c-dropdown__label__lang"><%= current_language %></span><%= render 'svg/down_arrow' %>
</span>
<ul class="c-dropdown__list s-dropdown-list">
<%= languages %>
Expand Down
2 changes: 2 additions & 0 deletions app/components/common/header/component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module Common
module Header
class Component < ApplicationViewComponent
include Devise::Controllers::Helpers

attr_reader :notifications

def initialize(notifications:)
Expand Down
4 changes: 2 additions & 2 deletions app/components/common/notifications/icon/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h5 class="c-notification__header__title"><%= t('english_offers.index.you_won') %>! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'OfferNotification' %>
<span class="c-notification__header__icon o-hammer-icon"></span>
<h5 class="c-notification__header__title"><%= t('english_offers.index.new_bid') %> <span class="o-new"></span></h5>
<h5 class="c-notification__header__title"><%= t('english_offers.index.new_bid') %>! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'AuctionLooserNotification' %>
<span class="c-notification__header__icon o-hammer-icon"></span>
<h5 class="c-notification__header__title"><%= t('english_offers.index.you_lose') %>! <span class="o-new"></span></h5>
Expand All @@ -16,7 +16,7 @@
<h5 class="c-notification__header__title"><%= t('english_offers.index.you_won') %>! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'OfferNotification' %>
<span class="o-hammer-icon"></span>
<h5 class="c-notification__header__title"><%= t('english_offers.index.new_bid') %> <span class="o-new"></span></h5>
<h5 class="c-notification__header__title"><%= t('english_offers.index.new_bid') %>! <span class="o-new"></span></h5>
<%- elsif @notification_type == 'AuctionLooserNotification' %>
<span class="o-hammer-icon"></span>
<h5 class="c-notification__header__title"><%= t('english_offers.index.you_lose') %>! <span class="o-new"></span></h5>
Expand Down
3 changes: 3 additions & 0 deletions app/views/svg/_down_arrow.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg width="10" height="7" viewBox="0 0 10 7" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M4.50581 5.82828L0.505807 1.82828C0.232439 1.55491 0.232439 1.11169 0.505807 0.838326C0.779174 0.564959 1.22239 0.564959 1.49576 0.838326L5.00078 4.34335L8.50581 0.838326C8.77917 0.564959 9.22239 0.564959 9.49576 0.838326C9.76912 1.11169 9.76912 1.55491 9.49576 1.82828L5.49576 5.82828C5.22239 6.10164 4.77917 6.10164 4.50581 5.82828Z"/>
</svg>
3 changes: 3 additions & 0 deletions app/views/svg/_person.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg width="10" height="12" viewBox="0 0 10 12" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M6.85524 6.35494C7.34544 5.96927 7.70324 5.4404 7.87886 4.84191C8.05449 4.24342 8.0392 3.60507 7.83514 3.01567C7.63107 2.42628 7.24837 1.91514 6.74028 1.55337C6.23219 1.1916 5.62397 0.997192 5.00024 0.997192C4.37652 0.997192 3.7683 1.1916 3.26021 1.55337C2.75212 1.91514 2.36941 2.42628 2.16535 3.01567C1.96128 3.60507 1.946 4.24342 2.12162 4.84191C2.29725 5.4404 2.65505 5.96927 3.14524 6.35494C2.30528 6.69146 1.57239 7.24961 1.02469 7.9699C0.476991 8.69018 0.135024 9.54559 0.0352425 10.4449C0.0280198 10.5106 0.0338008 10.577 0.0522552 10.6405C0.0707096 10.7039 0.101476 10.7631 0.142798 10.8146C0.226252 10.9187 0.347634 10.9854 0.480243 10.9999C0.612851 11.0145 0.745822 10.9758 0.849905 10.8924C0.953988 10.8089 1.02066 10.6875 1.03524 10.5549C1.14503 9.57754 1.61109 8.67485 2.34435 8.01934C3.07762 7.36383 4.02669 7.00145 5.01024 7.00145C5.99379 7.00145 6.94287 7.36383 7.67613 8.01934C8.4094 8.67485 8.87545 9.57754 8.98524 10.5549C8.99884 10.6778 9.05746 10.7913 9.1498 10.8734C9.24213 10.9556 9.36163 11.0007 9.48524 10.9999H9.54024C9.67131 10.9849 9.79111 10.9186 9.87352 10.8156C9.95594 10.7125 9.9943 10.5811 9.98024 10.4499C9.87999 9.54804 9.53618 8.69043 8.98567 7.96904C8.43515 7.24765 7.6987 6.68968 6.85524 6.35494ZM5.00024 5.99994C4.60468 5.99994 4.218 5.88264 3.8891 5.66288C3.5602 5.44312 3.30386 5.13076 3.15248 4.76531C3.00111 4.39986 2.9615 3.99772 3.03867 3.60976C3.11584 3.2218 3.30632 2.86543 3.58603 2.58573C3.86573 2.30602 4.2221 2.11554 4.61006 2.03837C4.99802 1.9612 5.40016 2.00081 5.76561 2.15218C6.13106 2.30356 6.44342 2.5599 6.66318 2.8888C6.88294 3.2177 7.00024 3.60438 7.00024 3.99994C7.00024 4.53037 6.78953 5.03908 6.41446 5.41415C6.03938 5.78923 5.53068 5.99994 5.00024 5.99994Z"/>
</svg>
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
require "test_helper"

class ButtonToTest < ViewComponent::TestCase
include ViewComponent::SystemTestHelpers

def test_render_delete_component
@user = users(:participant)
@auction = auctions(:valid_with_offers)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "test_helper"

class ButtonToTest < ViewComponent::TestCase
class FooterTest < ViewComponent::TestCase
include ViewComponent::SystemTestHelpers

def test_render_component
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions test/components/common/form/radio_button_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "test_helper"

class Common::Form::RadioButton::ComponentTest < ViewComponent::TestCase
include ActionView::Helpers::FormHelper

def test_render_component
form = ActionView::Helpers::FormBuilder.new(route.auctions_path, nil, self, { })

render_inline(Common::Form::RadioButton::Component.new(
form: form, title: 'blind', attribute: :type,
data_attributes: { }, options: { style: 'visibility: hidden; position: absolute;', id: 'filter_PO_button'}
))

assert_selector 'input.js-table-filter-btn[type="radio"][id="filter_PO_button"][value="blind"][name="/auctions[type]"][checked="checked"]', visible: :all
end
end
15 changes: 15 additions & 0 deletions test/components/common/form/search_field_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "test_helper"

class Common::Form::SearchField::ComponentTest < ViewComponent::TestCase
include ActionView::Helpers::FormHelper

def test_render_component
form = ActionView::Helpers::FormBuilder.new(route.auctions_path, nil, self, { })

render_inline(Common::Form::SearchField::Component.new(
form: form, attribute: :domain_name, value: nil, placeholder: I18n.t('search_by_domain_name')
))

assert_selector "input.c-table__search__input.js-table-search-dt[type='search'][name='/auctions[domain_name]'][id='_auctions_domain_name'][placeholder='#{I18n.t('search_by_domain_name')}']"
end
end
9 changes: 9 additions & 0 deletions test/components/common/hero_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "test_helper"

class HeroTest < ViewComponent::TestCase
def test_render_component
render_inline(Common::Hero::Component.new(title: 'Test', ))

assert_selector 'h1.c-hero__content__title', text: 'Test'
end
end
116 changes: 116 additions & 0 deletions test/components/common/link_button_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
require "test_helper"

class LinkButtonTest < ViewComponent::TestCase
def setup
@auction = auctions(:valid_with_offers)
end

def test_render_component
render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue-secondary', data_attributes: { } )
)

assert_selector "a.c-btn.c-btn--blue-secondary[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'
end

def test_render_nested_component
render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue-secondary', data_attributes: { } )
) do
'Edit'
end

assert_selector "a.c-btn.c-btn--blue-secondary.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'
end


def test_inline_button_colorize
render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue-secondary', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--blue-secondary[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'green', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--green[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--blue[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'orange', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--orange[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'black', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--black[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'ghost', data_attributes: { } )
)
assert_selector "a.c-btn.c-btn--ghost[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Link'
end

def test_nested_button_colorize
render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue-secondary', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--blue-secondary.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'green', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--green.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'blue', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--blue.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'orange', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--orange.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'black', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--black.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'

render_inline(Common::Links::LinkButton::Component.new(
link_title: 'Link', href: route.new_auction_english_offer_path(auction_uuid: @auction.uuid),
color: 'ghost', data_attributes: { } )
) do
'Edit'
end
assert_selector "a.c-btn.c-btn--ghost.c-btn--icon[href='#{route.new_auction_english_offer_path(auction_uuid: @auction.uuid)}']", text: 'Edit'
end
end
Loading

0 comments on commit f4e541b

Please sign in to comment.