Skip to content

Commit

Permalink
fix: update specs to work with 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mhenrixon committed Dec 3, 2024
1 parent a9cb7b7 commit 4f20635
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 67 deletions.
65 changes: 4 additions & 61 deletions spec/lib/phlexy_ui/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@
render described_class.new(
:neutral,
class: "my-class",
modal: :my_modal_1,
data: {my: :modals}
modal: "my_modal_1",
data: {my: "modals"}
) do
"Click me"
end
Expand All @@ -226,8 +226,8 @@
expected_html = html <<~HTML
<button
class="btn btn-neutral my-class"
data-my="modals"
onclick="my_modal_1.showModal()">Click me</button>
onclick="my_modal_1.showModal()"
data-my="modals">Click me</button>
HTML

expect(output).to eq(expected_html)
Expand All @@ -247,44 +247,6 @@
end
end

# TODO: Not needed once Phlex 2.0 is released.
context "when passing malicious code via the block" do
subject(:output) do
render described_class.new(:neutral, modal: :my_modal_1) do
"<script>alert('XSS');</script>"
end
end

it "escapes the code" do
expected_html = html <<~HTML
<button
class="btn btn-neutral"
onclick="my_modal_1.showModal()">&lt;script&gt;alert(&#39;XSS&#39;);&lt;/script&gt;</button>
HTML

expect(output).to eq(expected_html)
end
end

# TODO: Not needed once Phlex 2.0 is released.
context "when passing malicious code via the onclick option" do
subject(:output) do
render described_class.new(
:neutral,
:modal => :my_modal_1,
"onclick" => "<script>alert('XSS');</script>"
)
end

it "escapes the code" do
expected_html = "<button class=\"btn btn-neutral\" " \
"onclick=\"&lt;script&gt;alert(&#39;XSS&#39;);&lt;/script&gt;\" " \
"onclick=\"my_modal_1.showModal()\"></button>"

expect(output).to eq(expected_html)
end
end

context "when passing malicious code via the modal option" do
subject(:output) do
render described_class.new(:neutral, modal: %(" onclick="alert('XSS') //;))
Expand All @@ -301,24 +263,5 @@
expect(output).to eq(expected_html)
end
end

# TODO: Not needed once Phlex 2.0 is released.
context "when passing malicious code via the class option" do
subject(:output) do
render described_class.new(
:neutral,
modal: :my_modal_1,
class: %(" onclick="alert('XSS');)
)
end

it "escapes the code" do
expected_html = "<button class=\"btn btn-neutral &quot; " \
"onclick=&quot;alert(&#39;XSS&#39;);\" " \
"onclick=\"my_modal_1.showModal()\"></button>"

expect(output).to eq(expected_html)
end
end
end
end
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/drawer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
let(:component) do
Class.new(Phlex::HTML) do
def view_template(&)
render PhlexyUI::Drawer.new(:end, id: :my_drawer) do |drawer|
render PhlexyUI::Drawer.new(:end, id: "my_drawer") do |drawer|
drawer.toggle(class: "my-toggle", data: {my: "toggles"})
drawer.content(class: "my-content", data: {my: "contents"}) do
drawer.button(:primary, class: "my-button", data: {my: "buttons"}) do
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ def view_template(&)
end

menu.item do |item|
item.submenu :collapsible, :open, :primary, class: "rounded-t-none", data: {my: :collapsible_menus} do |submenu|
item.submenu :collapsible, :open, :primary, class: "rounded-t-none", data: {my: "collapsible_menus"} do |submenu|
submenu.title do
"Parent 1"
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/phlexy_ui/modal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def view_template(&)
"Open Modal"
end

render PhlexyUI::Modal.new(id: :my_modal_1) do |modal|
render PhlexyUI::Modal.new(id: "my_modal_1") do |modal|
modal.body do
h3 do
"Hello!"
Expand Down Expand Up @@ -64,7 +64,7 @@ def view_template(&)
"Open Modal"
end

render PhlexyUI::Modal.new(:tap_outside_to_close, id: :my_modal_1) do |modal|
render PhlexyUI::Modal.new(:tap_outside_to_close, id: "my_modal_1") do |modal|
modal.body do
h3 do
"Hello!"
Expand Down Expand Up @@ -109,7 +109,7 @@ def view_template(&)
"Open Modal"
end

render PhlexyUI::Modal.new(id: :my_modal_1) do |modal|
render PhlexyUI::Modal.new(id: "my_modal_1") do |modal|
modal.body do
modal.close_button :sm, :circle, :ghost, class: "absolute right-2 top-2" do
"✕"
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/phlexy_ui/radial_progress_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def view_template(&)
style: "background-color: red;",
as: :section,
data: {
my: :radial_progress
my: "radial_progress"
}
) do
"50%"
Expand Down

0 comments on commit 4f20635

Please sign in to comment.