Skip to content

Commit 14c67f8

Browse files
committed
Test numeric ID button in WP context menu specs
1 parent e36d14c commit 14c67f8

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

spec/features/work_packages/details/context_menu_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,24 @@
3030
# It can either succeed (showing success message) or fail (showing the URL to copy manually).
3131
expect(page).to have_message_copied_to_clipboard("/wp/#{work_package.id}")
3232
end
33+
34+
describe "'Copy numeric ID to clipboard' item" do
35+
context "in classic (numeric) mode", with_settings: { work_packages_identifier: "classic" } do
36+
it "is not offered (the displayed id is already the numeric id)" do
37+
find("button[wpsinglecontextmenu]").click
38+
within(".op-context-menu--overlay") do
39+
expect(page).to have_no_css(".menu-item", text: "Copy numeric ID to clipboard")
40+
end
41+
end
42+
end
43+
44+
context "in semantic mode", with_settings: { work_packages_identifier: "semantic" } do
45+
it "is offered" do
46+
find("button[wpsinglecontextmenu]").click
47+
within(".op-context-menu--overlay") do
48+
expect(page).to have_css(".menu-item", text: "Copy numeric ID to clipboard")
49+
end
50+
end
51+
end
52+
end
3353
end

spec/features/work_packages/table/semantic_id_navigation_follow_ups_spec.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,48 @@
8484
end
8585
end
8686

87+
describe "right-click context menu 'Copy numeric ID to clipboard' item" do
88+
it "copies the numeric id and does not navigate away (regression: used to 404)" do
89+
numeric_id = work_package.id.to_s
90+
semantic_id = work_package.reload.identifier
91+
92+
# Spy directly on navigator.clipboard.writeText (see the sibling
93+
# 'Copy link to clipboard' example for why the flash matcher won't do).
94+
page.execute_script(<<~JS)
95+
window.__lastCopiedText = null;
96+
navigator.clipboard.writeText = function(text) {
97+
window.__lastCopiedText = text;
98+
return Promise.resolve();
99+
};
100+
JS
101+
102+
context_menu.open_for(work_package)
103+
context_menu.choose("Copy numeric ID to clipboard")
104+
105+
copied = nil
106+
retry_block do
107+
copied = page.evaluate_script("window.__lastCopiedText")
108+
raise "clipboard write not yet observed" if copied.nil?
109+
end
110+
111+
expect(copied).to eq(numeric_id)
112+
expect(copied).not_to eq(semantic_id)
113+
114+
# The action used to fall through to `window.location.href = undefined`,
115+
# navigating to a non-existent URL. It must stay on the table instead.
116+
wp_table.expect_work_package_listed(work_package, other_wp)
117+
end
118+
end
119+
120+
context "in classic (numeric) mode", with_settings: { work_packages_identifier: "classic" } do
121+
describe "right-click context menu 'Copy numeric ID to clipboard' item" do
122+
it "is not offered (the displayed id is already the numeric id)" do
123+
context_menu.open_for(work_package)
124+
context_menu.expect_no_options("Copy numeric ID to clipboard")
125+
end
126+
end
127+
end
128+
87129
describe "toolbar info icon" do
88130
it "opens the split view at the semantic identifier URL" do
89131
semantic_id = work_package.reload.identifier

0 commit comments

Comments
 (0)