Skip to content

Commit fdb205d

Browse files
committed
Add tests
1 parent 567bd03 commit fdb205d

3 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe SolidusAdmin::Layout::Flashes::Alerts::Component, type: :component do
6+
let(:component) { described_class.new(alerts:) }
7+
8+
context "when alerts passed as Hash" do
9+
let(:alerts) do
10+
{ warning: { title: "Be careful", description: "Something fishy going on" } }
11+
end
12+
13+
it "renders correctly" do
14+
render_inline(component)
15+
16+
aggregate_failures do
17+
expect(page).to have_content("Be careful")
18+
expect(page).to have_content("Something fishy going on")
19+
end
20+
end
21+
end
22+
23+
context "when alerts passed as String" do
24+
let(:alerts) { "Something fishy going on" }
25+
26+
it "renders correctly" do
27+
render_inline(component)
28+
29+
aggregate_failures do
30+
expect(page).to have_content("Caution")
31+
expect(page).to have_content("Something fishy going on")
32+
end
33+
end
34+
end
35+
36+
describe "multiple alerts" do
37+
let(:alerts) do
38+
{
39+
warning: { title: "Be careful", description: "Something fishy going on" },
40+
success: { title: "It worked", description: "Nothing to worry about!" }
41+
}
42+
end
43+
44+
it "renders correctly" do
45+
render_inline(component)
46+
47+
aggregate_failures do
48+
expect(page).to have_content("Be careful")
49+
expect(page).to have_content("Something fishy going on")
50+
expect(page).to have_content("It worked")
51+
expect(page).to have_content("Nothing to worry about!")
52+
end
53+
end
54+
end
55+
end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe SolidusAdmin::Layout::Flashes::Toasts::Component, type: :component do
6+
let(:component) { described_class.new(toasts:) }
7+
8+
describe "error toast" do
9+
let(:toasts) { { error: "Some error" } }
10+
11+
it "renders correctly" do
12+
render_inline(component)
13+
14+
aggregate_failures do
15+
expect(page).to have_content("Some error")
16+
expect(page).to have_css(".bg-red-500")
17+
end
18+
end
19+
end
20+
21+
describe "default toast" do
22+
let(:toasts) { { notice: "All good" } }
23+
24+
it "renders correctly" do
25+
render_inline(component)
26+
27+
aggregate_failures do
28+
expect(page).to have_content("All good")
29+
expect(page).to have_css(".bg-full-black")
30+
end
31+
end
32+
end
33+
end

admin/spec/components/solidus_admin/ui/alert/component_spec.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,29 @@
66
it "renders the overview preview" do
77
render_preview(:overview)
88
end
9+
10+
describe "defaults" do
11+
let(:component) { described_class.new(title:, description:, scheme:) }
12+
let(:title) { "Title" }
13+
let(:description) { "Description" }
14+
let(:scheme) { :success }
15+
16+
context "when title is not present" do
17+
let(:title) { nil }
18+
19+
shared_examples_for "with default title" do |scheme, expected_title|
20+
let(:scheme) { scheme }
21+
22+
it "renders default title for scheme #{scheme}" do
23+
render_inline(component)
24+
expect(page).to have_content(expected_title)
25+
end
26+
end
27+
28+
it_behaves_like "with default title", :success, "Success"
29+
it_behaves_like "with default title", :warning, "Warning"
30+
it_behaves_like "with default title", :danger, "Caution"
31+
it_behaves_like "with default title", :info, "Info"
32+
end
33+
end
934
end

0 commit comments

Comments
 (0)