Просмотр исходного кода

Fix link sharing upgrade prompt show/hide logic

GitOrigin-RevId: 58c1fbdea566b48e770f9f7c7fd5f926fb1fdb37
M Fahru 4 лет назад
Родитель
Сommit
eb63eadca1

+ 3 - 2
services/web/app/src/Features/Project/ProjectController.js

@@ -1115,7 +1115,8 @@ const ProjectController = {
             )
 
             // Persistent upgrade prompts
-            const showHeaderUpgradePrompt =
+            // in header & in share project modal
+            const showUpgradePrompt =
               Features.hasFeature('saas') &&
               userId &&
               !subscription &&
@@ -1194,7 +1195,7 @@ const ProjectController = {
               showStopOnFirstError,
               detachRole,
               metadata: { viewport: false },
-              showHeaderUpgradePrompt,
+              showUpgradePrompt,
             })
             timer.done()
           }

+ 1 - 1
services/web/app/views/project/editor/meta.pug

@@ -27,7 +27,7 @@ meta(name="ol-debugPdfDetach" data-type="boolean" content=debugPdfDetach)
 meta(name="ol-showNewSourceEditorOption" data-type="boolean" content=showNewSourceEditorOption)
 meta(name="ol-showSymbolPalette" data-type="boolean" content=showSymbolPalette)
 meta(name="ol-detachRole" data-type="string" content=detachRole)
-meta(name="ol-showHeaderUpgradePrompt" data-type="boolean" content=showHeaderUpgradePrompt)
+meta(name="ol-showUpgradePrompt" data-type="boolean" content=showUpgradePrompt)
 meta(name="ol-showStopOnFirstError" data-type="boolean" content=showStopOnFirstError)
 
 - var fileActionI18n = ['edited', 'renamed', 'created', 'deleted'].reduce((acc, i) => {acc[i] = translate('file_action_' + i); return acc}, {})

+ 1 - 1
services/web/frontend/js/features/editor-navigation-toolbar/components/toolbar-header.js

@@ -65,7 +65,7 @@ const ToolbarHeader = React.memo(function ToolbarHeader({
           pdfViewIsOpen={pdfViewIsOpen}
         />
       )}
-      {window.showHeaderUpgradePrompt && <UpgradePrompt />}
+      {window.showUpgradePrompt && <UpgradePrompt />}
       <ProjectNameEditableLabel
         className="toolbar-center"
         projectName={projectName}

+ 3 - 7
services/web/frontend/js/features/share-project-modal/components/link-sharing.js

@@ -12,6 +12,7 @@ import * as eventTracking from '../../../infrastructure/event-tracking'
 import { useUserContext } from '../../../shared/context/user-context'
 import StartFreeTrialButton from '../../../shared/components/start-free-trial-button'
 import { useSplitTestContext } from '../../../shared/context/split-test-context'
+import getMeta from '../../../utils/meta'
 
 export default function LinkSharing({ canAddCollaborators }) {
   const [inflight, setInflight] = useState(false)
@@ -273,15 +274,10 @@ function LinkSharingUpgradePrompt({ canAddCollaborators }) {
   const { splitTestVariants } = useSplitTestContext()
   const linkSharingUpgradePromptActive =
     splitTestVariants['link-sharing-upgrade-prompt'] === 'active'
-
-  const user = useUserContext({
-    allowedFreeTrial: PropTypes.bool,
-  })
+  const showUpgradePrompt = getMeta('ol-showUpgradePrompt')
 
   const showLinkSharingUpgradePrompt =
-    linkSharingUpgradePromptActive &&
-    user.allowedFreeTrial &&
-    canAddCollaborators
+    linkSharingUpgradePromptActive && showUpgradePrompt && canAddCollaborators
 
   if (!showLinkSharingUpgradePrompt) {
     return null

+ 65 - 0
services/web/test/frontend/features/share-project-modal/components/share-project-modal.test.js

@@ -88,6 +88,7 @@ describe('<ShareProjectModal/>', function () {
     fetchMock.get('/user/contacts', { contacts })
     window.metaAttributesCache = new Map()
     window.metaAttributesCache.set('ol-user', { allowedFreeTrial: true })
+    window.metaAttributesCache.set('ol-showUpgradePrompt', true)
   })
 
   afterEach(function () {
@@ -833,4 +834,68 @@ describe('<ShareProjectModal/>', function () {
       )
     })
   })
+
+  it('displays link sharing upgrade prompt', async function () {
+    window.metaAttributesCache.set('ol-splitTestVariants', {
+      ...window.metaAttributesCache.get('ol-splitTestVariants'),
+      'link-sharing-upgrade-prompt': 'active',
+    })
+
+    // render when collaborators can still be added
+    renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
+      scope: {
+        project: {
+          ...project,
+          publicAccesLevel: 'tokenBased',
+          features: {
+            collaborators: 1,
+          },
+        },
+      },
+    })
+
+    await screen.findByText('Link sharing is on')
+
+    // text on share project upgrade prompt
+    await screen.findByText(
+      'makes collaboration with others easier with features such as',
+      { exact: false }
+    )
+  })
+
+  it('not displaying link sharing upgrade prompt when can not add collaborators', async function () {
+    window.metaAttributesCache.set('ol-splitTestVariants', {
+      ...window.metaAttributesCache.get('ol-splitTestVariants'),
+      'link-sharing-upgrade-prompt': 'active',
+    })
+
+    // render when collaborators can still be added
+    renderWithEditorContext(<ShareProjectModal {...modalProps} />, {
+      scope: {
+        project: {
+          ...project,
+          publicAccesLevel: 'tokenBased',
+          features: {
+            collaborators: 0,
+          },
+        },
+      },
+    })
+
+    await screen.findByText('Link sharing is on')
+
+    // text on share project upgrade prompt should not be visible
+    expect(
+      screen.queryByText(
+        'makes collaboration with others easier with features such as',
+        { exact: false }
+      )
+    ).to.be.null
+
+    // show add more collaborators text
+    await screen.findByText(
+      'You need to upgrade your account to add more collaborators',
+      { exact: false }
+    )
+  })
 })

+ 6 - 6
services/web/test/unit/src/Project/ProjectControllerTests.js

@@ -1412,7 +1412,7 @@ describe('ProjectController', function () {
       })
     })
 
-    describe('persistent upgrade prompt', function () {
+    describe('upgrade prompt (on header and share project modal)', function () {
       beforeEach(function () {
         // default to saas enabled
         this.Features.hasFeature.withArgs('saas').returns(true)
@@ -1424,14 +1424,14 @@ describe('ProjectController', function () {
       it('should not show without the saas feature', function (done) {
         this.Features.hasFeature.withArgs('saas').returns(false)
         this.res.render = (pageName, opts) => {
-          expect(opts.showHeaderUpgradePrompt).to.equal(false)
+          expect(opts.showUpgradePrompt).to.equal(false)
           done()
         }
         this.ProjectController.loadEditor(this.req, this.res)
       })
       it('should show for a user without a subscription or only non-paid affiliations', function (done) {
         this.res.render = (pageName, opts) => {
-          expect(opts.showHeaderUpgradePrompt).to.equal(true)
+          expect(opts.showUpgradePrompt).to.equal(true)
           done()
         }
         this.ProjectController.loadEditor(this.req, this.res)
@@ -1441,7 +1441,7 @@ describe('ProjectController', function () {
           .stub()
           .callsArgWith(1, null, {})
         this.res.render = (pageName, opts) => {
-          expect(opts.showHeaderUpgradePrompt).to.equal(false)
+          expect(opts.showUpgradePrompt).to.equal(false)
           done()
         }
         this.ProjectController.loadEditor(this.req, this.res)
@@ -1451,7 +1451,7 @@ describe('ProjectController', function () {
           .stub()
           .callsArgWith(1, null, true)
         this.res.render = (pageName, opts) => {
-          expect(opts.showHeaderUpgradePrompt).to.equal(false)
+          expect(opts.showUpgradePrompt).to.equal(false)
           done()
         }
         this.ProjectController.loadEditor(this.req, this.res)
@@ -1461,7 +1461,7 @@ describe('ProjectController', function () {
           .stub()
           .callsArgWith(1, null, true)
         this.res.render = (pageName, opts) => {
-          expect(opts.showHeaderUpgradePrompt).to.equal(false)
+          expect(opts.showUpgradePrompt).to.equal(false)
           done()
         }
         this.ProjectController.loadEditor(this.req, this.res)