Skip to content

Commit 5cdf068

Browse files
authored
Merge pull request #408 from opf/bug/69966-can-t-move-hierarchy-element-underneath-an-element-with-an-and-symbol-in-its-title
[69966] Can't move hierarchy element underneath an element with an "&" symbol in its title
2 parents d640316 + d35389f commit 5cdf068

8 files changed

Lines changed: 31 additions & 7 deletions

File tree

.changeset/clear-cooks-mix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openproject/primer-view-components': patch
3+
---
4+
5+
Support special characters in node names of Primer::Alpha::TreeView

app/components/primer/alpha/tree_view/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def initialize(
129129
@content_arguments, {
130130
data: {
131131
value: value,
132-
path: @path.to_json,
132+
path: JSON.generate(@path),
133133
select_variant: @select_variant
134134
}
135135
}

app/components/primer/alpha/tree_view/skeleton_loader.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% with_loading_failure_message # set the default %>
33
<% end %>
44

5-
<%= render(Primer::BaseComponent.new(tag: :"tree-view-include-fragment", src: @src, loading: :lazy, data: { target: "tree-view-sub-tree-node.subTree tree-view-sub-tree-node.includeFragment", path: @container.path.to_json }, hidden: @container.expanded?, accept: "text/fragment+html")) do %>
5+
<%= render(Primer::BaseComponent.new(tag: :"tree-view-include-fragment", src: @src, loading: :lazy, data: { target: "tree-view-sub-tree-node.subTree tree-view-sub-tree-node.includeFragment", path: JSON.generate(@container.path) }, hidden: @container.expanded?, accept: "text/fragment+html")) do %>
66
<%= render(@container) do %>
77
<%= render(Primer::Alpha::TreeView::Node.new(path: [*@container.path, :loader], node_variant: :div)) do |node| %>
88
<% node.with_text_content do %>

app/components/primer/alpha/tree_view/spinner_loader.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% with_loading_failure_message # set the default %>
33
<% end %>
44

5-
<%= render(Primer::BaseComponent.new(tag: :"tree-view-include-fragment", src: @src, loading: :lazy, data: { target: "tree-view-sub-tree-node.subTree tree-view-sub-tree-node.includeFragment", path: @container.path.to_json }, hidden: @container.expanded?, accept: "text/fragment+html")) do %>
5+
<%= render(Primer::BaseComponent.new(tag: :"tree-view-include-fragment", src: @src, loading: :lazy, data: { target: "tree-view-sub-tree-node.subTree tree-view-sub-tree-node.includeFragment", path: JSON.generate(@container.path) }, hidden: @container.expanded?, accept: "text/fragment+html")) do %>
66
<%= render(@container) do %>
77
<%= render(Primer::Alpha::TreeView::Node.new(path: [*@container.path, :loader], data: { target: "tree-view-sub-tree-node.loadingIndicator" }, node_variant: :div)) do |node| %>
88
<% node.with_text_content { "Loading..." } %>

docs/contributors/playwright-testing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- [Table of Contents](#table-of-contents)
1010
- [Visual testing](#visual-testing)
1111
- [Prerequisites](#prerequisites)
12-
- [Continous Integration](#continous-integration)
12+
- [Continuous Integration](#continuous-integration)
1313
- [Other tests](#other-tests)
1414
- [System tests](#system-tests)
1515

@@ -41,7 +41,7 @@ rendering the screenshots will match the browser in CI.
4141

4242
Once you have the codespace open, make sure you're up to date with `script/setup`. Then you can run the `npx playwright test` command.
4343

44-
### Continous Integration
44+
### Continuous Integration
4545

4646
Playwright tests are included in the `Tests > Visual Regressions` jobs of the CI workflow.
4747
The results of the test run are uploaded at the end of the job and are available
@@ -55,7 +55,7 @@ When the workflow runs, it will check in screenshots of previews for visual diff
5555

5656
## Other tests
5757

58-
Before running the whole test suite with: `script/test`, you must run `bundle exec rake docs:preview`.
58+
Before running the whole test suite with: `script/test`, you must run `script/test-setup` to start Vite and CSS builds in watch mode.
5959

6060
Run a subset of tests by supplying arguments to `script/test`:
6161

previews/primer/alpha/tree_view_preview/form_input.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<% end %>
88

99
<% tree.with_leaf(label: "action_menu.rb", select_variant: select_variant, value: 3) %>
10+
<% tree.with_sub_tree(label: "Docs & legal requirements", select_variant: select_variant, value: 4) do |sub_tree| %>
11+
<% sub_tree.with_leaf(label: "Readme.md", select_variant: select_variant, value: 5) %>
12+
<% sub_tree.with_leaf(label: "Copyright.md", select_variant: select_variant, value: 6) %>
13+
<% end %>
1014
<% end %>
1115

1216
<%= render(Primer::Alpha::SubmitButton.new(name: :submit, label: "Submit")) %>

test/system/alpha/tree_view_test.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,5 +885,20 @@ def test_initial_form_state_for_single_select
885885

886886
assert_equal "{\"path\":[\"src\",\"button.rb\"],\"value\":\"1\"}", response.dig("form_params", "folder_structure", 0)
887887
end
888+
889+
def test_single_select_with_special_character
890+
visit_preview(:form_input, expanded: true, select_variant: :single, route_format: :json)
891+
892+
assert_path_checked "src", "button.rb"
893+
activate_at_path("Docs & legal requirements")
894+
assert_path_checked "Docs & legal requirements"
895+
896+
find("button[type=submit]").click
897+
898+
# for some reason the JSON response is wrapped in HTML, I have no idea why
899+
response = JSON.parse(find("pre").text)
900+
901+
assert_equal "{\"path\":[\"Docs & legal requirements\"],\"value\":\"4\"}", response.dig("form_params", "folder_structure", 0)
902+
end
888903
end
889904
end

test/test_helpers/tree_view_helpers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module Primer
44
module TreeViewHelpers
55
def selector_for(*path)
6-
"[role=treeitem][data-path='#{path.to_json}']"
6+
"[role=treeitem][data-path='#{JSON.generate(path)}']"
77
end
88

99
def activate_at_path(*path)

0 commit comments

Comments
 (0)