From b90b7c92acc9ab01d7842a27f16c91d6d95f0dbc Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Wed, 3 Nov 2021 08:21:24 -0500 Subject: [PATCH] Merge pull request #5655 from overleaf/jel-detach-feature-flag Make showNewPdfPreview a dependency of showPdfDetach GitOrigin-RevId: 2bb2f5cd8b2cf68a28e8979713c08c0ceef33fa5 --- .../src/Features/Project/ProjectController.js | 24 ++++-- .../src/Project/ProjectControllerTests.js | 86 +++++++++++++++++++ 2 files changed, 102 insertions(+), 8 deletions(-) diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index e68dd54f34..658aafacb2 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -819,6 +819,20 @@ const ProjectController = { return shouldDisplayFeature('enable_pdf_caching', false) } + let showNewPdfPreview = shouldDisplayFeature( + 'new_pdf_preview', + user.alphaProgram + ) + + const showPdfDetach = shouldDisplayFeature( + 'pdf_detach', + user.alphaProgram + ) + + if (showPdfDetach) { + showNewPdfPreview = true + } + res.render('project/editor', { title: project.name, priority_title: true, @@ -881,14 +895,8 @@ const ProjectController = { 'new_navigation_ui', true ), - showPdfDetach: shouldDisplayFeature( - 'pdf_detach', - user.alphaProgram - ), - showNewPdfPreview: shouldDisplayFeature( - 'new_pdf_preview', - user.alphaProgram - ), + showPdfDetach, + showNewPdfPreview, showSymbolPalette: shouldDisplayFeature( 'symbol_palette', user.alphaProgram || user.betaProgram diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index 17405dbf25..c11ede8dc6 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -1557,6 +1557,92 @@ describe('ProjectController', function () { }) }) }) + + describe('feature flags', function () { + describe('showNewPdfPreview', function () { + it('should be false by default', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showNewPdfPreview).to.be.false + done() + } + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be true when ?new_pdf_preview=true ', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.req.query.new_pdf_preview = 'true' + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be true for alpha group', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.user.alphaProgram = true + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be false when when ?new_pdf_preview=true and alpha group', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.user.alphaProgram = true + this.req.query.new_pdf_preview = 'false' + this.ProjectController.loadEditor(this.req, this.res) + }) + }) + describe('showPdfDetach', function () { + describe('showPdfDetach=false', function () { + it('should be false by default', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showPdfDetach).to.be.false + done() + } + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be false by default, even when ?new_pdf_preview=true', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showPdfDetach).to.be.false + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.req.query.new_pdf_preview = 'true' + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be false when when ?pdf_detach=true and alpha group', function (done) { + this.res.render = (pageName, opts) => { + done() + } + this.user.alphaProgram = true + this.req.query.pdf_detach = 'false' + this.ProjectController.loadEditor(this.req, this.res) + }) + }) + + describe('showPdfDetach=true', function () { + it('should be true when ?pdf_detach=true, and set showNewPdfPreview as true ', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showPdfDetach).to.be.true + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.req.query.pdf_detach = 'true' + this.ProjectController.loadEditor(this.req, this.res) + }) + it('should be true for alpha group, and set showNewPdfPreview as true', function (done) { + this.res.render = (pageName, opts) => { + expect(opts.showPdfDetach).to.be.true + expect(opts.showNewPdfPreview).to.be.true + done() + } + this.user.alphaProgram = true + this.ProjectController.loadEditor(this.req, this.res) + }) + }) + }) + }) }) describe('userProjectsJson', function () {