Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add edge case tests for TitleBarComponent #452

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,65 @@

assert result =~ "123"
assert result =~ ~R|<style nonce="style_nonce">\s*#.*\{width:0.1%\}|
assert result =~ "div class=\"test-class\""
assert result =~ ~r|<div class="test-class"|
end

test "handles negative and over-max percent values" do

Check failure on line 24 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.14.5, 24.3)

test rendering handles negative and over-max percent values (Phoenix.LiveDashboard.TitleBarComponentTest)

Check failure on line 24 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.15.6, 26.0.2)

test rendering handles negative and over-max percent values (Phoenix.LiveDashboard.TitleBarComponentTest)
result_negative = render_component(TitleBarComponent,
percent: -0.5,
class: "test-class",
csp_nonces: %{img: "img_nonce", style: "style_nonce", script: "script_nonce"},
dom_id: "title-bar",
inner_block: [%{slot: :__inner_block__, inner_block: fn _, _ -> "Negative" end}]
)

assert result_negative =~ "Negative"
assert result_negative =~ ~R|<style nonce="style_nonce">\s*#.*\{width:0%\}|

result_over_max = render_component(TitleBarComponent,
percent: 1.5,
class: "test-class",
csp_nonces: %{img: "img_nonce", style: "style_nonce", script: "script_nonce"},
dom_id: "title-bar",
inner_block: [%{slot: :__inner_block__, inner_block: fn _, _ -> "Over max" end}]
)

assert result_over_max =~ "Over max"
assert result_over_max =~ ~R|<style nonce="style_nonce">\s*#.*\{width:100%\}|
end

test "handles empty or missing nonces" do

Check failure on line 48 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.14.5, 24.3)

test rendering handles empty or missing nonces (Phoenix.LiveDashboard.TitleBarComponentTest)

Check failure on line 48 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.15.6, 26.0.2)

test rendering handles empty or missing nonces (Phoenix.LiveDashboard.TitleBarComponentTest)
result_empty_nonce = render_component(TitleBarComponent,
percent: 0.5,
class: "test-class",
csp_nonces: %{img: "", style: "style_nonce", script: ""},
dom_id: "title-bar",
inner_block: [%{slot: :__inner_block__, inner_block: fn _, _ -> "Empty nonce" end}]
)

assert result_empty_nonce =~ "Empty nonce"
assert result_empty_nonce =~ ~R|<style nonce="style_nonce">\s*#.*\{width:50%\}|

result_missing_nonce = render_component(TitleBarComponent,
percent: 0.5,
class: "test-class",
dom_id: "title-bar",
inner_block: [%{slot: :__inner_block__, inner_block: fn _, _ -> "Missing nonce" end}]
)

assert result_missing_nonce =~ "Missing nonce"
assert result_missing_nonce =~ ~R|<style>\s*#.*\{width:50%\}|
end

test "renders without inner_block" do

Check failure on line 71 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.14.5, 24.3)

test rendering renders without inner_block (Phoenix.LiveDashboard.TitleBarComponentTest)

Check failure on line 71 in test/phoenix/live_dashboard/components/title_bar_component_test.exs

View workflow job for this annotation

GitHub Actions / mix_test (1.15.6, 26.0.2)

test rendering renders without inner_block (Phoenix.LiveDashboard.TitleBarComponentTest)
result_no_inner_block = render_component(TitleBarComponent,
percent: 0.5,
class: "test-class",
csp_nonces: %{img: "img_nonce", style: "style_nonce", script: "script_nonce"},
dom_id: "title-bar"
)

assert result_no_inner_block =~ ~R|<style nonce="style_nonce">\s*#.*\{width:50%\}|
end
end
end
Loading