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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add teaser specs
Mir Bhatia9ec008ec8fab
diff --git a/app/components/enterprise_edition/banner_component.rb b/app/components/enterprise_edition/banner_component.rbindex 864a0110720..2173ebcab55 100644--- a/app/components/enterprise_edition/banner_component.rb+++ b/app/components/enterprise_edition/banner_component.rb@@ -128,7 +128,8 @@ module EnterpriseEdition"op-enterprise-banner","op-enterprise-banner_medium" => @variant == :medium,"op-enterprise-banner_large" => @variant == :large,- "op-enterprise-banner_trial" => trial_feature?+ "op-enterprise-banner_trial" => trial_feature?,+ "op-enterprise-banner_teaser" => teaser?)enddiff --git a/app/components/enterprise_edition/plan_for_feature.rb b/app/components/enterprise_edition/plan_for_feature.rbindex 7bff4abcf0f..5b3cf342680 100644--- a/app/components/enterprise_edition/plan_for_feature.rb+++ b/app/components/enterprise_edition/plan_for_feature.rb@@ -54,7 +54,7 @@ module EnterpriseEditionenddef teaser_title- I18n.t("ee.teaser.title", count: token.days_left, trial_plan: token.plan)+ I18n.t("ee.teaser.title", count: token.days_left || 365, trial_plan: token.plan)enddef descriptiondiff --git a/app/components/enterprise_edition/upsell_buttons_component.rb b/app/components/enterprise_edition/upsell_buttons_component.rbindex 5b34e32a19e..601ee298573 100644--- a/app/components/enterprise_edition/upsell_buttons_component.rb+++ b/app/components/enterprise_edition/upsell_buttons_component.rb@@ -101,6 +101,8 @@ module EnterpriseEditionenddef more_info_button+ return if @feature_key == :teaser+render(Primer::Beta::Link.new(href: enterprise_link)) do |link|link.with_trailing_visual_icon(icon: "link-external")link_titlediff --git a/app/models/enterprise_token.rb b/app/models/enterprise_token.rbindex c27a2661959..ee76c654a9d 100644--- a/app/models/enterprise_token.rb+++ b/app/models/enterprise_token.rb@@ -223,7 +223,7 @@ class EnterpriseToken < ApplicationRecordenddef days_left- (valid_until.to_date - Time.zone.today).to_i+ valid_until.present? ? (valid_until.to_date - Time.zone.today).to_i : nilendprivatediff --git a/spec/components/enterprise_edition/trial_teaser_component_spec.rb b/spec/components/enterprise_edition/trial_teaser_component_spec.rbnew file mode 100644index 00000000000..28d10d0e9c7--- /dev/null+++ b/spec/components/enterprise_edition/trial_teaser_component_spec.rb@@ -0,0 +1,84 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2024 the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+# ++++require "rails_helper"++RSpec.describe EnterpriseEdition::TrialTeaserComponent, type: :component do+ let(:mock_token) do+ instance_double(+ EnterpriseToken,+ days_left: 7,+ plan: :mocked+ )+ end++ before do+ allow(EnterpriseToken).to receive(:active_trial_tokens).and_return([mock_token])+ end++ context "for an admin user" do+ before do+ admin_user = instance_double(User, admin?: true)+ allow(User).to receive(:current).and_return(admin_user)+ end++ it "renders the trial teaser" do+ render_inline(described_class.new)++ component = find_test_selector("op-enterprise-banner")++ within(component) do+ expect(page).to have_no_css(".op-enterprise-banner--close_icon")++ expect(page).to have_text("Buy now")+ expect(page).to have_text("7 days left of mocked trial token")+ expect(page).to have_text("You have access to all Mocked enterprise plan features.")++ expect(page).to have_no_text("Start free trial")+ expect(page).to have_no_text("Book now")+ expect(page).to have_no_text("Upgrade now")+ expect(page).to have_no_text("More information")+ end+ end+ end++ context "for a non-admin user" do+ before do+ admin_user = instance_double(User, admin?: false)+ allow(User).to receive(:current).and_return(admin_user)+ end++ it "nothing is rendered" do+ render_inline(described_class.new)++ expect(page).to have_no_css("[data-test-selector='op-enterprise-banner']")+ end+ end+enddiff --git a/spec/support/shared/with_ee.rb b/spec/support/shared/with_ee.rbindex c5cafa85c78..4727dda4255 100644--- a/spec/support/shared/with_ee.rb+++ b/spec/support/shared/with_ee.rb@@ -59,6 +59,11 @@ RSpec.configure do |config|enterprise_token = EnterpriseToken.newallow(enterprise_token).to receive_messages(token_object:)+ # To ensure tests don't trip up on the trial teaser banner+ if example.metadata[:with_ee_trial]+ allow(enterprise_token).to receive(:days_left).and_return(42)+ end+# EnterpriseToken is mocked to return the partial double of enterprise# token as active tokenallow(EnterpriseToken).to receive(:active_tokens).and_return([enterprise_token])