mirror of
https://github.com/penpot/penpot.git
synced 2026-11-20 17:11:15 +00:00
Move the pure subscription rules out of the browser specs and into unit tests, then keep only the cases a browser can prove. - Extract show-manage-subscription-link? and show-main-menu-power-up? from the dashboard team panel and the workspace main menu, and use them at both call sites. A new subscription_dashboard_test.cljs covers which plan a subscription reads to, including unpaid and canceled demotion, the owner and enterprise sides of both affordances, and the banner and members-CTA boundaries: four editors over the seats, no usage data, and the demoted plans. - Add get-versions-stored-days tests to workspace_versions_test.cljs: an active nitrate or enterprise license keeps 90 days, a canceled one lets the team plan decide, a license without the admin console does not count, and unlimited, enterprise, professional and planless teams keep 30, 90 and 7 days. - Rewrite the profile usage tests as async tests with mock/with-mocks* and an async transport double: the editors from the usage call reach [:props :subscription :editors], a failing call leaves the profile untouched and logs once, and the call is skipped without the subscriptions flag. - Cut the e2e suite from 13 cases to 7. Five dashboard cases keep the menu icon, the two sidebar plan names, the owner-only settings link and the members CTA; two workspace cases keep the translated days warning with the upsell step and the enterprise menu with no upsell. Assert the unlimited glyph and drop the CTA count. - Drop the three get-team-info mocks the dashboard never calls and six unreferenced subscription fixtures, reusing the invitations fixture. - Sort the subscription test requires in runner.cljs: cljfmt's :sort-ns-references? wants subscription-dashboard-test first. Closes #13005 AI-assisted-by: deepseek-v4.1-flash
196 lines
9.3 KiB
Clojure
196 lines
9.3 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS SUBSIDIARY SL
|
|
|
|
(ns frontend-tests.ui.subscription-dashboard-test
|
|
"The rules behind the subscription affordances: which plan a
|
|
subscription reads as, when the dashboard shows the upgrade banner or
|
|
the members CTA instead of the plan selector, who gets the billing link
|
|
in the team settings, and when the workspace menu offers the upsell.
|
|
|
|
The fixtures copy the shape the browser sees: the profile carries the
|
|
seats as `:quantity` and the editors under
|
|
`[:props :subscription :editors]`, where `get-subscription-usage` leaves
|
|
them, while the team carries `:seats`."
|
|
(:require
|
|
[app.main.ui.dashboard.subscription :as subscription]
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
(defn- profile
|
|
([subscription]
|
|
{:props {:subscription subscription}})
|
|
([subscription editors]
|
|
{:props {:subscription (assoc subscription :editors (vec (range editors)))}}))
|
|
|
|
(t/deftest a-professional-subscription-reads-as-professional
|
|
(t/is (= "professional"
|
|
(subscription/get-subscription-type
|
|
{:type "professional" :status "active"}))))
|
|
|
|
(t/deftest a-trialing-unlimited-subscription-reads-as-unlimited
|
|
(t/is (= "unlimited"
|
|
(subscription/get-subscription-type
|
|
{:type "unlimited" :status "trialing"}))))
|
|
|
|
(t/deftest an-active-enterprise-subscription-reads-as-enterprise
|
|
(t/is (= "enterprise"
|
|
(subscription/get-subscription-type
|
|
{:type "enterprise" :status "active"}))))
|
|
|
|
(t/deftest a-past-due-subscription-keeps-its-type
|
|
;; Only `unpaid` and `canceled` demote a plan.
|
|
(t/is (= "unlimited"
|
|
(subscription/get-subscription-type
|
|
{:type "unlimited" :status "past_due"}))))
|
|
|
|
(t/deftest an-unpaid-subscription-reads-as-professional
|
|
(t/is (= "professional"
|
|
(subscription/get-subscription-type
|
|
{:type "unlimited" :status "unpaid"}))))
|
|
|
|
(t/deftest a-canceled-subscription-reads-as-professional
|
|
(t/is (= "professional"
|
|
(subscription/get-subscription-type
|
|
{:type "enterprise" :status "canceled"}))))
|
|
|
|
(t/deftest a-subscription-without-a-type-reads-as-professional
|
|
(t/is (= "professional"
|
|
(subscription/get-subscription-type {:status "active"}))))
|
|
|
|
(t/deftest a-nil-subscription-reads-as-professional
|
|
(t/is (= "professional" (subscription/get-subscription-type nil))))
|
|
|
|
(t/deftest the-owner-of-an-unlimited-team-sees-the-manage-subscription-link
|
|
(t/is (true? (subscription/show-manage-subscription-link?
|
|
true {:type "unlimited" :status "active"}))))
|
|
|
|
(t/deftest the-owner-of-an-enterprise-team-sees-the-manage-subscription-link
|
|
(t/is (true? (subscription/show-manage-subscription-link?
|
|
true {:type "enterprise" :status "active"}))))
|
|
|
|
(t/deftest the-owner-of-a-professional-team-has-no-manage-subscription-link
|
|
(t/is (false? (subscription/show-manage-subscription-link?
|
|
true {:type "professional" :status "active"}))))
|
|
|
|
(t/deftest a-member-of-an-unlimited-team-has-no-manage-subscription-link
|
|
(t/is (false? (subscription/show-manage-subscription-link?
|
|
false {:type "unlimited" :status "active"}))))
|
|
|
|
(t/deftest an-unlimited-plan-offers-the-upsell-in-the-main-menu
|
|
(t/is (true? (subscription/show-main-menu-power-up?
|
|
#{:subscriptions} "unlimited"))))
|
|
|
|
(t/deftest a-professional-plan-offers-the-upsell-in-the-main-menu
|
|
(t/is (true? (subscription/show-main-menu-power-up?
|
|
#{:subscriptions} "professional"))))
|
|
|
|
(t/deftest an-enterprise-plan-hides-the-upsell-in-the-main-menu
|
|
(t/is (false? (subscription/show-main-menu-power-up?
|
|
#{:subscriptions} "enterprise"))))
|
|
|
|
(t/deftest without-the-subscriptions-flag-the-upsell-is-hidden
|
|
(t/is (false? (subscription/show-main-menu-power-up?
|
|
#{} "unlimited"))))
|
|
|
|
(t/deftest the-admin-console-offers-the-upsell-on-an-enterprise-plan
|
|
(t/is (true? (subscription/show-main-menu-power-up?
|
|
#{:admin-console} "enterprise"))))
|
|
|
|
(t/deftest a-professional-plan-shows-the-banner-above-eight-editors
|
|
;; Nine editors do not fit the eight the plan allows.
|
|
(t/is (true? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "professional" :status "active"} 9)))))
|
|
|
|
(t/deftest a-professional-plan-at-eight-editors-does-not-show-the-banner
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "professional" :status "active"} 8)))))
|
|
|
|
(t/deftest a-professional-plan-without-usage-data-does-not-show-the-banner
|
|
;; The editors arrive with the usage call; until then the count is zero.
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "professional" :status "active"})))))
|
|
|
|
(t/deftest an-unlimited-plan-with-four-editors-over-the-seats-shows-the-banner
|
|
(t/is (true? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "active" :quantity 20} 24)))))
|
|
|
|
(t/deftest an-unlimited-plan-with-three-editors-over-the-seats-does-not-show-the-banner
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "active" :quantity 20} 23)))))
|
|
|
|
(t/deftest an-unlimited-plan-at-the-seat-limit-does-not-show-the-banner
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "active" :quantity 25} 30)))))
|
|
|
|
(t/deftest an-unlimited-plan-with-25-editors-over-24-seats-shows-the-banner
|
|
;; The editors already passed the size the plan prices per seat.
|
|
(t/is (true? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "active" :quantity 24} 25)))))
|
|
|
|
(t/deftest an-unlimited-plan-with-editors-within-the-seats-does-not-show-the-banner
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "active" :quantity 24} 24)))))
|
|
|
|
(t/deftest a-canceled-enterprise-plan-is-judged-as-a-professional-plan
|
|
;; Nine editors on thirty seats fit the enterprise plan; only the
|
|
;; demotion to professional makes the banner show.
|
|
(t/is (true? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "enterprise" :status "canceled" :quantity 30} 9)))
|
|
"canceled reads as professional, so the professional rule applies")
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "enterprise" :status "canceled" :quantity 30} 8)))))
|
|
|
|
(t/deftest an-unpaid-unlimited-plan-is-judged-as-a-professional-plan
|
|
;; Six editors on two seats trip the unlimited rule (four or more over
|
|
;; the seats); only the demotion keeps the banner away.
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "unlimited" :status "unpaid" :quantity 2} 6)))))
|
|
|
|
(t/deftest an-enterprise-plan-does-not-show-the-banner
|
|
(t/is (false? (subscription/show-subscription-dashboard-banner?
|
|
(profile {:type "enterprise" :status "active" :quantity 30} 30)))))
|
|
|
|
(t/deftest the-owner-of-an-unlimited-team-shows-the-members-banner
|
|
(t/is (true? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "unlimited" :status "active" :seats 2}}
|
|
(profile {:type "unlimited"} 8)))))
|
|
|
|
(t/deftest a-member-of-an-unlimited-team-does-not-show-the-members-banner
|
|
(t/is (false? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner false}
|
|
:subscription {:type "unlimited" :status "active" :seats 2}}
|
|
(profile {:type "unlimited"} 8)))))
|
|
|
|
(t/deftest the-owner-with-four-editors-over-the-seats-shows-the-members-banner
|
|
(t/is (true? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "unlimited" :status "active" :seats 20}}
|
|
(profile {:type "unlimited"} 24)))))
|
|
|
|
(t/deftest the-owner-with-three-editors-over-the-seats-does-not-show-the-members-banner
|
|
(t/is (false? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "unlimited" :status "active" :seats 20}}
|
|
(profile {:type "unlimited"} 23)))))
|
|
|
|
(t/deftest the-owner-at-the-seat-limit-does-not-show-the-members-banner
|
|
(t/is (false? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "unlimited" :status "active" :seats 25}}
|
|
(profile {:type "unlimited"} 40)))))
|
|
|
|
(t/deftest the-owner-of-an-enterprise-team-does-not-show-the-members-banner
|
|
(t/is (false? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "enterprise" :status "active" :seats 2}}
|
|
(profile {:type "enterprise"} 40)))))
|
|
|
|
(t/deftest a-members-banner-without-usage-data-does-not-show
|
|
(t/is (false? (subscription/show-subscription-members-banner?
|
|
{:permissions {:is-owner true}
|
|
:subscription {:type "unlimited" :status "active" :seats 2}}
|
|
(profile {:type "unlimited"})))))
|