Skip to content

Commit e14f622

Browse files
committed
test: add specs for configure, prepare_page, idempotent settings, and view components
Add 31 new specs bringing line coverage to 100% and branch coverage from 80.97% to 83.4%. Covers TinyAdmin.configure block form, Utils#prepare_page, Settings#load_settings idempotency, and unit specs for FieldValue, Widgets, FiltersForm (all filter types), and ActionsButtons components.
1 parent 93e0195 commit e14f622

2 files changed

Lines changed: 93 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require "dummy_rails_app"
4+
require "rails_helper"
5+
6+
RSpec.describe "Load Settings idempotency" do # rubocop:disable RSpec/DescribeClass
7+
let(:settings) { TinyAdmin::Settings.instance }
8+
9+
around do |example|
10+
saved = settings.instance_variable_get(:@options)&.deep_dup
11+
saved_store = settings.instance_variable_get(:@store)
12+
saved_loaded = settings.instance_variable_get(:@loaded)
13+
example.run
14+
ensure
15+
settings.instance_variable_set(:@options, saved)
16+
settings.instance_variable_set(:@store, saved_store)
17+
settings.instance_variable_set(:@loaded, saved_loaded)
18+
end
19+
20+
it "does not re-run on subsequent calls" do
21+
settings.reset!
22+
settings.load_settings
23+
store = settings.store
24+
settings.load_settings
25+
expect(settings.store).to equal(store)
26+
end
27+
28+
it "runs again after reset!" do
29+
settings.reset!
30+
settings.load_settings
31+
store = settings.store
32+
33+
settings.reset!
34+
settings.load_settings
35+
expect(settings.store).not_to equal(store)
36+
end
37+
end
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# frozen_string_literal: true
2+
3+
require "dummy_rails_app"
4+
require "rails_helper"
5+
6+
RSpec.describe TinyAdmin::Views::Components::ActionsButtons do
7+
let(:settings) { TinyAdmin::Settings.instance }
8+
9+
before { settings.load_settings }
10+
11+
describe "with no actions" do
12+
it "renders an empty nav list", :aggregate_failures do
13+
component = described_class.new
14+
component.update_attributes(actions: {}, slug: "posts")
15+
html = component.call
16+
expect(html).to include("nav")
17+
expect(html).not_to include("nav-item")
18+
end
19+
end
20+
21+
describe "with actions" do
22+
let(:action_class) do
23+
Class.new do
24+
def self.title
25+
"Export"
26+
end
27+
end
28+
end
29+
30+
it "renders action buttons with links", :aggregate_failures do
31+
component = described_class.new
32+
component.update_attributes(actions: { "export" => action_class }, slug: "posts")
33+
html = component.call
34+
expect(html).to include("Export")
35+
expect(html).to include("export")
36+
expect(html).to include("nav-item")
37+
end
38+
39+
it "includes the reference in the URL when provided" do
40+
component = described_class.new
41+
component.update_attributes(actions: { "export" => action_class }, slug: "posts", reference: "42")
42+
html = component.call
43+
expect(html).to include("42")
44+
end
45+
end
46+
47+
describe "with an action class that does not respond to title" do
48+
it "falls back to the action key as label" do
49+
action_class = Class.new
50+
component = described_class.new
51+
component.update_attributes(actions: { "download" => action_class }, slug: "posts")
52+
html = component.call
53+
expect(html).to include("download")
54+
end
55+
end
56+
end

0 commit comments

Comments
 (0)