Merge pull request #4727 from consul/unify-spec-components-expectations
Unify spec components expectations
This commit is contained in:
@@ -49,7 +49,7 @@ describe Admin::Budgets::DurationComponent do
|
|||||||
|
|
||||||
render Admin::Budgets::DurationComponent.new(durable).duration
|
render Admin::Budgets::DurationComponent.new(durable).duration
|
||||||
|
|
||||||
expect(page.text).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not defined when no start date is defined" do
|
it "is not defined when no start date is defined" do
|
||||||
@@ -57,7 +57,7 @@ describe Admin::Budgets::DurationComponent do
|
|||||||
|
|
||||||
render Admin::Budgets::DurationComponent.new(durable).duration
|
render Admin::Budgets::DurationComponent.new(durable).duration
|
||||||
|
|
||||||
expect(page.text).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent do
|
|||||||
|
|
||||||
render_inline Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group)
|
render_inline Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group)
|
||||||
|
|
||||||
expect(page.text).to be_empty
|
expect(page).not_to be_rendered
|
||||||
expect(page).not_to have_css ".budget-group-switcher"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders a link to switch group for budgets with two groups" do
|
it "renders a link to switch group for budgets with two groups" do
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ describe Budgets::Investments::FiltersComponent do
|
|||||||
|
|
||||||
render_inline Budgets::Investments::FiltersComponent.new
|
render_inline Budgets::Investments::FiltersComponent.new
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ describe Budgets::SupportsInfoComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_selector ".supports-info"
|
expect(page).not_to be_rendered
|
||||||
expect(page.text).to be_empty
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#total_supports" do
|
describe "#total_supports" do
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ describe Layout::LocaleSwitcherComponent do
|
|||||||
it "doesn't render anything" do
|
it "doesn't render anything" do
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page.text).to be_empty
|
expect(page).not_to be_rendered
|
||||||
expect(page).not_to have_css ".locale"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ describe Layout::SocialComponent do
|
|||||||
|
|
||||||
render_inline Layout::SocialComponent.new
|
render_inline Layout::SocialComponent.new
|
||||||
|
|
||||||
expect(page).not_to have_css "ul"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe Layout::TopLinksComponent do
|
|||||||
it "does not render when no content block is defined" do
|
it "does not render when no content block is defined" do
|
||||||
render_inline Layout::TopLinksComponent.new
|
render_inline Layout::TopLinksComponent.new
|
||||||
|
|
||||||
expect(page).not_to have_css "ul"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ describe MachineLearning::CommentsSummaryComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not displayed when the machine learning feature is disabled" do
|
it "is not displayed when the machine learning feature is disabled" do
|
||||||
@@ -30,7 +30,7 @@ describe MachineLearning::CommentsSummaryComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "is not displayed when there's no summary" do
|
it "is not displayed when there's no summary" do
|
||||||
@@ -38,6 +38,6 @@ describe MachineLearning::CommentsSummaryComponent do
|
|||||||
|
|
||||||
render_inline MachineLearning::CommentsSummaryComponent.new(commentable)
|
render_inline MachineLearning::CommentsSummaryComponent.new(commentable)
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ describe SDG::Goals::HelpPageComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css ".sdg-help-content"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders content when the feature is enabled" do
|
it "renders content when the feature is enabled" do
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ describe SDG::Goals::PlainTagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ describe SDG::Goals::TagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
@@ -22,7 +22,7 @@ describe SDG::Goals::TagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders a list of goals" do
|
it "renders a list of goals" do
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ describe SDG::Goals::TargetsComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css ".targets"
|
expect(page).not_to be_rendered
|
||||||
expect(page).not_to have_css "#target_tabs"
|
|
||||||
expect(page).not_to have_css ".tabs-content"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders tabs panel" do
|
it "renders tabs panel" do
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe SDG::RelatedListSelectorComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css ".sdg-related-list-selector"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
@@ -23,7 +23,7 @@ describe SDG::RelatedListSelectorComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css ".sdg-related-list-selector"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders related_sdg_list field" do
|
it "renders related_sdg_list field" do
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ describe SDG::TagListComponent do
|
|||||||
|
|
||||||
render_inline SDG::TagListComponent.new(record)
|
render_inline SDG::TagListComponent.new(record)
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when linkable is false" do
|
context "when linkable is false" do
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe SDG::Targets::PlainTagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
@@ -26,7 +26,7 @@ describe SDG::Targets::PlainTagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders a list of targets" do
|
it "renders a list of targets" do
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ describe SDG::Targets::TagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render when the SDG process feature is disabled" do
|
it "does not render when the SDG process feature is disabled" do
|
||||||
@@ -26,7 +26,7 @@ describe SDG::Targets::TagListComponent do
|
|||||||
|
|
||||||
render_inline component
|
render_inline component
|
||||||
|
|
||||||
expect(page).not_to have_css "li"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "renders a list of targets" do
|
it "renders a list of targets" do
|
||||||
|
|||||||
@@ -82,13 +82,13 @@ describe Shared::BannerComponent do
|
|||||||
|
|
||||||
render_inline Shared::BannerComponent.new("debates")
|
render_inline Shared::BannerComponent.new("debates")
|
||||||
|
|
||||||
expect(page).not_to have_css ".banner"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not render anything given nil" do
|
it "does not render anything given nil" do
|
||||||
render_inline Shared::BannerComponent.new(nil)
|
render_inline Shared::BannerComponent.new(nil)
|
||||||
|
|
||||||
expect(page).not_to have_css ".banner"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,22 +4,21 @@ 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
|
||||||
|
|
||||||
expect(page).not_to have_css "ul"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns nothing with a list of nil elements" do
|
it "returns nothing with a list of nil elements" do
|
||||||
render_inline Shared::LinkListComponent.new(nil, nil)
|
render_inline Shared::LinkListComponent.new(nil, nil)
|
||||||
|
|
||||||
expect(page).not_to have_css "ul"
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
|
|
||||||
it "generates a list of links" do
|
it "generates a list of links" do
|
||||||
render_inline Shared::LinkListComponent.new(
|
render_inline Shared::LinkListComponent.new(
|
||||||
["Home", "/"], ["Info", "/info"], class: "menu"
|
["Home", "/"], ["Info", "/info"], class: "menu"
|
||||||
)
|
)
|
||||||
list = page.find("body").native.inner_html
|
|
||||||
|
|
||||||
expect(list).to eq '<ul class="menu">' + "\n" +
|
expect(page).to be_rendered with: '<ul class="menu">' + "\n" +
|
||||||
'<li><a href="/">Home</a></li>' + "\n" +
|
'<li><a href="/">Home</a></li>' + "\n" +
|
||||||
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
||||||
end
|
end
|
||||||
@@ -28,9 +27,8 @@ describe Shared::LinkListComponent do
|
|||||||
render_inline Shared::LinkListComponent.new(
|
render_inline Shared::LinkListComponent.new(
|
||||||
'<a href="/">Home</a>'.html_safe, ["Info", "/info"], class: "menu"
|
'<a href="/">Home</a>'.html_safe, ["Info", "/info"], class: "menu"
|
||||||
)
|
)
|
||||||
list = page.find("body").native.inner_html
|
|
||||||
|
|
||||||
expect(list).to eq '<ul class="menu">' + "\n" +
|
expect(page).to be_rendered with: '<ul class="menu">' + "\n" +
|
||||||
'<li><a href="/">Home</a></li>' + "\n" +
|
'<li><a href="/">Home</a></li>' + "\n" +
|
||||||
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
'<li><a href="/info">Info</a></li>' + "\n</ul>\n"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -42,6 +42,6 @@ describe Shared::TagListComponent do
|
|||||||
it "is not rendered when there are no tags" do
|
it "is not rendered when there are no tags" do
|
||||||
render_inline Shared::TagListComponent.new(Proposal.new, limit: nil)
|
render_inline Shared::TagListComponent.new(Proposal.new, limit: nil)
|
||||||
|
|
||||||
expect(page.native.inner_html).to be_empty
|
expect(page).not_to be_rendered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
25
spec/support/matchers/be_rendered.rb
Normal file
25
spec/support/matchers/be_rendered.rb
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
RSpec::Matchers.define :be_rendered do |with: nil|
|
||||||
|
match do |page|
|
||||||
|
if with.nil?
|
||||||
|
!page.native.inner_html.empty?
|
||||||
|
else
|
||||||
|
page.has_css?("body") && page.find("body").native.inner_html == with
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message do |page|
|
||||||
|
if page.has_css?("body")
|
||||||
|
"expected page to be rendered with #{with}, but was rendered with #{page.find("body").native.inner_html}"
|
||||||
|
else
|
||||||
|
"expected page to be rendered with #{with}, but was not rendered"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
failure_message_when_negated do |page|
|
||||||
|
if page.has_css?("body")
|
||||||
|
"expected page not to be rendered, but was rendered with #{page.find("body").native.inner_html}"
|
||||||
|
else
|
||||||
|
"expected page not to be rendered, but was rendered with #{page.native.inner_html}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user