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 specs

Oliver Güntherdc369872e882
diff --git a/app/components/enterprise_edition/banner_component.rb b/app/components/enterprise_edition/banner_component.rb
index 89992f90a1e..2eefef0cc33 100644
--- a/app/components/enterprise_edition/banner_component.rb
+++ b/app/components/enterprise_edition/banner_component.rb
@@ -41,13 +41,11 @@ module EnterpriseEdition
# Defaults to "ee.upsale.{feature_key}"
# @param dismissable [boolean] Allow this banner to be dismissed.
# @param dismiss_key [String] Provide a string to identify this banner when being dismissed. Defaults to feature_key
- # @param skip_render [Boolean] Whether to skip rendering the banner.
# @param system_arguments [Hash] <%= link_to_system_arguments_docs %>
def initialize(feature_key,
i18n_scope: "ee.upsale.#{feature_key}",
dismissable: false,
dismiss_key: feature_key,
- skip_render: EnterpriseToken.hide_banners?,
**system_arguments)
@system_arguments = system_arguments
@system_arguments[:tag] = :div
@@ -58,7 +56,6 @@ module EnterpriseEdition
self.feature_key = feature_key
self.i18n_scope = i18n_scope
- @skip_render = skip_render
@dismissable = dismissable
@dismiss_key = dismiss_key
end
@@ -68,7 +65,11 @@ module EnterpriseEdition
attr_reader :skip_render
def render?
- !(skip_render || dismissed?)
+ !(EnterpriseToken.hide_banners? || feature_available? || dismissed?)
+ end
+
+ def feature_available?
+ EnterpriseToken.allows_to?(feature_key)
end
def dismissed?
diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb
index a4766c0a47f..6fc73f7bbb8 100644
--- a/app/helpers/types_helper.rb
+++ b/app/helpers/types_helper.rb
@@ -64,7 +64,7 @@ module ::TypesHelper
path: edit_tab_type_path(id: @type.id, tab: :subject_configuration),
label: "types.edit.subject_configuration.tab",
view_component: WorkPackages::Types::SubjectConfigurationComponent,
- enterprise_feature: :automatic_subject_generation
+ enterprise_feature: :work_package_subject_generation
}
tabs.insert(2, subject_configuration_tab)
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a068a5fc372..e316084f8d1 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -4697,7 +4697,7 @@ en:
sso_auth_providers: Single sign-on
team_planner_view: Team Planner View
two_factor_authentication: 2FA Authentication
- virus_scanning: Antivirus scanning
+ virus_scanning: Antivirus Scanning
work_package_query_relation_columns: Work Package Query Relation Columns
work_package_sharing: Share work packages with external users
work_package_subject_generation: Work Package Subject Generation
diff --git a/modules/auth_plugins/spec/requests/auth_plugins_spec.rb b/modules/auth_plugins/spec/requests/auth_plugins_spec.rb
index 7eaeb43a6ef..0f2ce0c4691 100644
--- a/modules/auth_plugins/spec/requests/auth_plugins_spec.rb
+++ b/modules/auth_plugins/spec/requests/auth_plugins_spec.rb
@@ -29,7 +29,7 @@
require "spec_helper"
require "open_project/auth_plugins"
-RSpec.describe OpenProject::Plugins::AuthPlugin, with_ee: %i[board_view] do
+RSpec.describe OpenProject::Plugins::AuthPlugin, with_ee: %i[sso_auth_providers] do # rubocop:disable RSpec/SpecFilePathFormat
let(:dummy_engine_klass) do
Class.new { extend OpenProject::Plugins::AuthPlugin }
end
diff --git a/spec/components/enterprise_edition/banner_component_spec.rb b/spec/components/enterprise_edition/banner_component_spec.rb
index 84b89ba8fe5..5873e39e66d 100644
--- a/spec/components/enterprise_edition/banner_component_spec.rb
+++ b/spec/components/enterprise_edition/banner_component_spec.rb
@@ -32,18 +32,20 @@ require "rails_helper"
RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
let(:title) { "Some title" }
+ let(:expected_title) { title }
let(:description) { "Some description" }
+ let(:expected_description) { description }
let(:href) { "https://www.example.org" }
- let(:link_title) { "Get more information" }
- let(:ee_show_banners) { true }
+ let(:component_test_selector) { "op-enterprise-banner-some-enterprise-feature" }
+ let(:features) { nil }
let(:enforce_available_locales) { I18n.config.enforce_available_locales }
let(:i18n_upsale) do
{
- title:,
- link_title:,
some_enterprise_feature: {
- description:
- }
+ title:,
+ description:,
+ features:
+ }.compact
}
end
let(:static_links) do
@@ -55,9 +57,20 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
}
}
end
+ let(:translations) do
+ {
+ ee: {
+ upsale: i18n_upsale
+ },
+ enterprise_features: {
+ some_enterprise_feature: "Enterprise feature translation"
+ }
+ }
+ end
+ let(:component_args) { {} }
let(:render_component) do
- render_inline(described_class.new(:some_enterprise_feature))
+ render_inline(described_class.new(:some_enterprise_feature, **component_args))
end
let(:render_component_in_mo) do
@@ -75,11 +88,7 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
I18n.backend.store_translations(
:mo,
- {
- ee: {
- upsale: i18n_upsale
- }
- }
+ translations
)
end
@@ -92,51 +101,101 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
it "renders the component" do
render_component_in_mo
- expect(page).to have_test_selector("op-ee-banner-some-enterprise-feature")
- expect(page).to have_css ".op-ee-banner--title-container", text: title
- expect(page).to have_css ".op-ee-banner--description-container", text: description
- expect(page).to have_link link_title, href:
+ component = find_test_selector(component_test_selector)
+
+ expect(component).to have_text(expected_title)
+ expect(component).to have_text(expected_description)
+ expect(component).to have_link("More information", href:)
+ end
+ end
+
+ shared_examples_for "does not render the component" do
+ it "does not render the component" do
+ render_component_in_mo
+
+ expect(page).not_to have_test_selector(component_test_selector)
+ expect(page).to have_no_text("Enterprise feature translation")
+ expect(page).to have_no_text(expected_title)
+ expect(page).to have_no_text(expected_description)
+ expect(page).to have_no_link(href:)
end
end
it_behaves_like "renders the component"
- context "with a description_html in the i18n file" do
+ context "when feature is available", with_ee: %i[some_enterprise_feature] do
+ it_behaves_like "does not render the component"
+ end
+
+ context "when banners are hidden" do
+ before do
+ allow(EnterpriseToken).to receive(:hide_banners?).and_return(true)
+ end
+
+ it_behaves_like "does not render the component"
+ end
+
+ context "when banner is dismissed" do
+ let(:preference) { build_stubbed(:user_preference) }
+ let(:user) { build_stubbed(:user, preference:) }
+ let(:dismiss_key) { :some_enterprise_feature }
+ let(:component_args) { { dismissable: true } }
+
+ before do
+ login_as(user)
+ allow(preference)
+ .to receive(:dismissed_banner?)
+ .with(dismiss_key)
+ .and_return(true)
+ end
+
+ it_behaves_like "does not render the component"
+
+ context "when not dismissable" do
+ let(:component_args) { { dismissable: false } }
+
+ it_behaves_like "renders the component"
+ end
+
+ context "when using a custom dismiss_key" do
+ let(:dismiss_key) { :foo }
+ let(:component_args) { { dismiss_key:, dismissable: true } }
+
+ it_behaves_like "does not render the component"
+ end
+ end
+
+ context "without a title, but a description_html" do
let(:i18n_upsale) do
{
- title:,
- link_title:,
some_enterprise_feature: {
description_html: description
}
}
end
+ let(:expected_title) { "Enterprise feature translation" }
it_behaves_like "renders the component"
end
- context "with a more specific title in the i18n file" do
+ context "without a title, but a description" do
let(:i18n_upsale) do
{
- title: "The general title",
- link_title:,
some_enterprise_feature: {
- title:,
description:
}
}
end
+ let(:expected_title) { "Enterprise feature translation" }
it_behaves_like "renders the component"
end
- context "with a more specific link title in the i18n file" do
+ context "with a more specific title in the i18n file" do
let(:i18n_upsale) do
{
- title:,
- link_title: "The general link title",
some_enterprise_feature: {
- link_title:,
+ title:,
description:
}
}
@@ -145,11 +204,32 @@ RSpec.describe EnterpriseEdition::BannerComponent, type: :component do
it_behaves_like "renders the component"
end
+ context "with a custom i18n_scope" do
+ let(:translations) do
+ {
+ my: {
+ custom: {
+ upsale: {
+ title: "Foo",
+ description: "Bar"
+ }
+ }
+ },
+ enterprise_features: {
+ some_enterprise_feature: "Enterprise feature translation"
+ }
+ }
+ end
+ let(:expected_title) { "Foo" }
+ let(:expected_description) { "Bar" }
+ let(:component_args) { { i18n_scope: "my.custom.upsale" } }
+
+ it_behaves_like "renders the component"
+ end
+
context "without a description key in the i18n file" do
let(:i18n_upsale) do
{
- title:,
- link_title:,
some_enterprise_feature: {}
}
end
diff --git a/spec/components/users/hover_card_component_spec.rb b/spec/components/users/hover_card_component_spec.rb
index b2d10036046..d3e95187d97 100644
--- a/spec/components/users/hover_card_component_spec.rb
+++ b/spec/components/users/hover_card_component_spec.rb
@@ -46,11 +46,10 @@ RSpec.describe Users::HoverCardComponent, type: :component do
groups
login_as(current_user)
render_inline(subject)
- page.extend TestSelectorFinders
end
it "renders successfully" do
- page.find_test_selector("user-hover-card-name", text: user.name)
+ find_test_selector("user-hover-card-name", text: user.name)
end
context "when the user does not exist" do
@@ -71,14 +70,14 @@ RSpec.describe Users::HoverCardComponent, type: :component do
let(:current_user) { build(:admin) }
it "shows the email address of a user" do
- page.find_test_selector("user-hover-card-email", text: user.mail)
+ find_test_selector("user-hover-card-email", text: user.mail)
end
end
end
context "when showing the group summary" do
it "shows a no results text for users without group memberships" do
- g = page.find_test_selector("user-hover-card-groups")
+ g = find_test_selector("user-hover-card-groups")
expect(g).to have_text(I18n.t("users.groups.no_results_title_text"))
end
@@ -88,7 +87,7 @@ RSpec.describe Users::HoverCardComponent, type: :component do
end
it "lists the group names for a user" do
- g = page.find_test_selector("user-hover-card-groups")
+ g = find_test_selector("user-hover-card-groups")
expect(g).to have_text("Member of #{groups.first.lastname}, #{groups.last.lastname}.")
end
@@ -98,7 +97,7 @@ RSpec.describe Users::HoverCardComponent, type: :component do
let(:another_user) { create(:user) }
it "does not show groups" do
- g = page.find_test_selector("user-hover-card-groups")
+ g = find_test_selector("user-hover-card-groups")
expect(g).to have_text(I18n.t("users.groups.no_results_title_text"))
end
@@ -111,7 +110,7 @@ RSpec.describe Users::HoverCardComponent, type: :component do
end
it "lists some group names with truncation" do
- g = page.find_test_selector("user-hover-card-groups")
+ g = find_test_selector("user-hover-card-groups")
expect(g).to have_text("Member of #{groups.slice(0, 4).map(&:lastname).join(', ')} and 4 more.")
end
@@ -120,7 +119,7 @@ RSpec.describe Users::HoverCardComponent, type: :component do
context "when clicking on the Open Profile button" do
it "leads to the users profile" do
- b = page.find_test_selector("user-hover-card-profile-btn")
+ b = find_test_selector("user-hover-card-profile-btn")
expect(b).to have_text(I18n.t("users.open_profile"))
expect(b["href"]).to eq(user_path(user))
@@ -130,7 +129,7 @@ RSpec.describe Users::HoverCardComponent, type: :component do
let(:current_user) { build(:admin) }
it "leads to editing the users profile" do
- b = page.find_test_selector("user-hover-card-profile-btn")
+ b = find_test_selector("user-hover-card-profile-btn")
expect(b).to have_text(I18n.t("users.open_profile"))
expect(b["href"]).to eq(edit_user_path(user))
diff --git a/spec/components/work_packages/types/subject_configuration_component_spec.rb b/spec/components/work_packages/types/subject_configuration_component_spec.rb
index 18b2900cee1..6ce0a382039 100644
--- a/spec/components/work_packages/types/subject_configuration_component_spec.rb
+++ b/spec/components/work_packages/types/subject_configuration_component_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
it "shows no enterprise banner" do
render_component
- expect(page).not_to have_test_selector("op-ee-banner-automatic-subject-generation")
+ expect(page).not_to have_test_selector("op-enterprise-banner-work-package-subject-generation")
end
it "enables mode selectors", :aggregate_failures do
@@ -109,7 +109,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
it "shows the enterprise banner" do
render_component
- expect(page).to have_test_selector("op-ee-banner-automatic-subject-generation")
+ expect(page).to have_test_selector("op-enterprise-banner-work-package-subject-generation")
end
it "disables only automatic mode selector", :aggregate_failures do
@@ -125,7 +125,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
it "shows the enterprise banner" do
render_component
- expect(page).to have_test_selector("op-ee-banner-automatic-subject-generation")
+ expect(page).to have_test_selector("op-enterprise-banner-work-package-subject-generation")
end
it "enables mode selectors", :aggregate_failures do
diff --git a/spec/helpers/enterprise_helper_spec.rb b/spec/helpers/enterprise_helper_spec.rb
index dd7f0b7093e..ba768e1ea37 100644
--- a/spec/helpers/enterprise_helper_spec.rb
+++ b/spec/helpers/enterprise_helper_spec.rb
@@ -52,7 +52,7 @@ RSpec.describe EnterpriseHelper do
let(:token) { instance_double(EnterpriseToken, features: %i[baseline_comparison virus_scanning]) }
it "returns translated names of features" do
- expect(helper.enterprise_plan_additional_features(token)).to eq("Attachment Virus Scanning, Baseline Comparison")
+ expect(helper.enterprise_plan_additional_features(token)).to eq("Antivirus Scanning, Baseline Comparisons")
end
end
@@ -63,7 +63,7 @@ RSpec.describe EnterpriseHelper do
end
it "returns translated names of features and removes unknowns" do
- expect(helper.enterprise_plan_additional_features(token)).to eq("Work Package Sharing")
+ expect(helper.enterprise_plan_additional_features(token)).to eq("Share work packages with external users")
end
end
end
diff --git a/spec/models/enterprise_token_spec.rb b/spec/models/enterprise_token_spec.rb
index 35dbf232483..cdf1a66deda 100644
--- a/spec/models/enterprise_token_spec.rb
+++ b/spec/models/enterprise_token_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe EnterpriseToken do
let(:ee_manager_visible) { true }
it "returns true" do
- expect(described_class).to be_show_banners
+ expect(described_class).not_to be_hide_banners
end
end
@@ -82,7 +82,7 @@ RSpec.describe EnterpriseToken do
let(:ee_manager_visible) { false }
it "returns false" do
- expect(described_class).not_to be_show_banners
+ expect(described_class).to be_hide_banners
end
end
end
@@ -176,7 +176,7 @@ RSpec.describe EnterpriseToken do
allow(service_double)
.to receive(:call)
.with(:forbidden_action)
- .and_return ServiceResult.success(result: true)
+ .and_return ServiceResult.success(result: false)
allow(service_double)
.to receive(:call)
.with(:allowed_action)
diff --git a/spec/requests/admin/attachments/virus_scanning_settings_spec.rb b/spec/requests/admin/attachments/virus_scanning_settings_spec.rb
index 354bf3b68ed..c218c170a57 100644
--- a/spec/requests/admin/attachments/virus_scanning_settings_spec.rb
+++ b/spec/requests/admin/attachments/virus_scanning_settings_spec.rb
@@ -130,9 +130,10 @@ RSpec.describe "Attachments virus scanning",
end
describe "without ee" do
- it "redirects to upsale" do
+ it "renders upsale" do
get "/admin/settings/virus_scanning"
- expect(response.body).to have_text "Virus scanning is an Enterprise add-on", normalize_ws: true
+ expect(response.body).to have_text "Virus scanning"
+ expect(response.body).to have_text "Available only through the Corporate enterprise plan."
end
end
end
diff --git a/spec/support/finders/test_selector.rb b/spec/support/finders/test_selector.rb
index 775ce19151c..8aed726042e 100644
--- a/spec/support/finders/test_selector.rb
+++ b/spec/support/finders/test_selector.rb
@@ -33,11 +33,13 @@ module TestSelectorFinders
end
def find_test_selector(value, **)
- find(:test_id, value, **)
+ target = respond_to?(:page) ? page : self
+ target.find(:test_id, value, **)
end
def within_test_selector(value, **, &)
- within(:test_id, value, **, &)
+ target = respond_to?(:page) ? page : self
+ target.within(:test_id, value, **, &)
end
# expect(page).to have_test_selector('foo')
@@ -57,4 +59,5 @@ RSpec.configure do |config|
Capybara::Session.include(TestSelectorFinders)
Capybara::DSL.extend(TestSelectorFinders)
config.include TestSelectorFinders, type: :feature
+ config.include TestSelectorFinders, type: :component
end