Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix feature test for adding/deleting an enterprise token

Christophe Bliard87ef998c0f8f
diff --git a/app/components/admin/enterprise_tokens/create_dialog_component.html.erb b/app/components/admin/enterprise_tokens/create_dialog_component.html.erb
index b77af480078..665443d17c0 100644
--- a/app/components/admin/enterprise_tokens/create_dialog_component.html.erb
+++ b/app/components/admin/enterprise_tokens/create_dialog_component.html.erb
@@ -28,10 +28,11 @@
Primer::Beta::Button.new(
scheme: :primary,
form: "enterprise-token-form",
+ data: { turbo: true },
type: :submit
)
) do
- I18n.t(:button_create)
+ I18n.t(:button_add)
end
end
end
diff --git a/app/views/enterprise_tokens/index.html.erb b/app/views/enterprise_tokens/index.html.erb
index 5478a43969d..13ede2ee4e2 100644
--- a/app/views/enterprise_tokens/index.html.erb
+++ b/app/views/enterprise_tokens/index.html.erb
@@ -17,6 +17,7 @@
size: :medium,
href: new_enterprise_token_path,
aria: { label: button_title },
+ role: "button",
data: {
turbo_stream: true
},
diff --git a/spec/features/admin/enterprise/enterprise_spec.rb b/spec/features/admin/enterprise/enterprise_spec.rb
index f7e6c6a94f3..0ae4fe21911 100644
--- a/spec/features/admin/enterprise/enterprise_spec.rb
+++ b/spec/features/admin/enterprise/enterprise_spec.rb
@@ -38,7 +38,7 @@ RSpec.describe "Enterprise token", :js do
OpenProject::Token.new.tap do |token|
token.subscriber = "Foobar"
token.mail = "[email protected]"
- token.starts_at = Time.zone.today
+ token.starts_at = Date.current
token.expires_at = nil
token.domain = Setting.host_name
end
@@ -50,24 +50,27 @@ RSpec.describe "Enterprise token", :js do
describe "EnterpriseToken management" do
before do
login_as admin
- visit enterprise_path
+ visit enterprise_tokens_path
end
- it "shows a teaser and token form without a token" do
+ it "shows a teaser page and has a button to add a token" do
+ # The teaser page is displayed
+ # TODO: this will likely change, adapt to the new teaser page
expect(page).to have_css(".button", text: "Start free trial")
expect(page).to have_css(".button", text: "Book now")
- expect(textarea.value).to be_empty
- textarea.set "foobar"
- submit_button.click
+ # Try adding invalid enterprise token data
+ expect(page).to have_button("Add Enterprise token")
+ click_button "Add Enterprise token"
- # Error output
- expect_flash(type: :error,
- message: "Enterprise support token can't be read. Are you sure it is a support token?")
+ expect(page).to have_dialog("Add Enterprise token")
+ fill_in "Type support token text", with: "foobar"
+ click_button "Add"
- within "span.errorSpan" do
- expect(page).to have_css("#enterprise_token_encoded_token")
- end
+ # The dialog is still open with an error message on token field
+ expect(page).to have_dialog("Add Enterprise token")
+ expect(page).to have_field("Type support token text",
+ validation_error: "Enterprise support token can't be read. Are you sure it is a support token?")
end
context "with valid input" do
@@ -76,60 +79,53 @@ RSpec.describe "Enterprise token", :js do
end
it "allows token import flow" do
- textarea.set "foobar"
- submit_button.click
-
- expect_flash(message: I18n.t(:notice_successful_update))
- expect(page).to have_test_selector("op-enterprise--active-token")
-
- expect(page.all(".attributes-key-value--key").map(&:text))
- .to eq ["Subscriber", "Email", "Domain", "Maximum active users", "Starts at", "Expires at", "Plan"]
- expect(page.all(".attributes-key-value--value").map(&:text))
- .to eq [
- "Foobar",
- Setting.host_name,
- "Unlimited",
- format_date(Time.zone.today),
- "Unlimited",
- "Enterprise Plan (Token Version #{token_object.version})"
- ]
-
- expect(page).to have_css(".button.icon-delete", text: I18n.t(:button_delete))
-
- # Expect section to be collapsed
- expect(page).to have_no_css("#token_encoded_token")
-
- RequestStore.clear!
- expect(EnterpriseToken.current.encoded_token).to eq("foobar")
-
- expect(page).to have_text("Successful update")
- find("h2", text: "Replace your current support token").click
- fill_in "enterprise_token_encoded_token", with: "blabla"
- submit_button.click
-
- wait_for_reload
-
- expect_flash(message: I18n.t(:notice_successful_update))
-
- # Assume next request
- RequestStore.clear!
- expect(EnterpriseToken.current.encoded_token).to eq("blabla")
+ click_button "Add Enterprise token"
+ fill_in "Type support token text", with: "foobar"
+ click_button "Add"
+
+ expect_and_dismiss_flash(message: I18n.t(:notice_successful_update))
+
+ # Table headers
+ [
+ "Plan",
+ "Subscriber",
+ "Maximum active users",
+ "Email",
+ "Domain",
+ "Dates"
+ ].each do |attribute|
+ expect(page).to have_text(attribute)
+ end
+
+ # Token values
+ [
+ "Enterprise Plan (Token Version #{token_object.version})",
+ "Foobar",
+ "Unlimited",
+ Setting.host_name,
+ "#{format_date(Date.current)} – Unlimited"
+ ].each do |attribute|
+ expect(page).to have_text(attribute)
+ end
+
+ # Token is stored in the database
+ expect(EnterpriseToken.last.encoded_token).to eq("foobar")
# Remove token
- click_on "Delete"
+ click_on "more-button"
+ find(:menuitem, "Delete").click
wait_for_network_idle
- # Expect modal
- find_test_selector("confirmation-modal--confirmed").click
-
- wait_for_reload
-
- expect_flash(message: I18n.t(:notice_successful_delete))
+ # Expect deletion modal
+ expect(page).to have_dialog("Delete enterprise token")
+ within_dialog("Delete enterprise token") do
+ click_button "Delete"
+ end
- # Assume next request
- RequestStore.clear!
- expect(EnterpriseToken.current).to be_nil
+ # Token deleted
+ expect_and_dismiss_flash(message: I18n.t(:notice_successful_delete))
+ expect(EnterpriseToken.all).to be_empty
end
end
end
diff --git a/spec/support/capybara.rb b/spec/support/capybara.rb
index eacac2da84a..db4ca77e6db 100644
--- a/spec/support/capybara.rb
+++ b/spec/support/capybara.rb
@@ -34,8 +34,14 @@ RSpec.shared_context "with host name set to test.host" do
end
RSpec.configure do |config|
+ # The maximum number of seconds to wait for asynchronous processes to finish
+ # Would default to 2 seconds otherwise
Capybara.default_max_wait_time = 4
+ # Selectors will check for relevant aria role (currently only `button`)
+ # Would default to `false` otherwise
+ Capybara.enable_aria_role = true
+
port = ENV.fetch("CAPYBARA_SERVER_PORT", ParallelHelper.port_for_app).to_i
if port > 0
Capybara.server_port = port