From c82de5e512e0310abb173ec818d4c7f10cc994bc Mon Sep 17 00:00:00 2001 From: James Grant Date: Tue, 13 Jun 2023 10:46:22 +0100 Subject: [PATCH] CDPS-209 - fix for two banners --- integration_tests/e2e/profileBanner.cy.ts | 67 +++++++++++++++++++ integration_tests/pages/index.ts | 4 ++ .../profileBanner/profileBannerTop.njk | 54 +++++++-------- 3 files changed, 98 insertions(+), 27 deletions(-) diff --git a/integration_tests/e2e/profileBanner.cy.ts b/integration_tests/e2e/profileBanner.cy.ts index b91942f6c..462fd5905 100644 --- a/integration_tests/e2e/profileBanner.cy.ts +++ b/integration_tests/e2e/profileBanner.cy.ts @@ -1,5 +1,6 @@ import Page from '../pages/page' import OverviewPage from '../pages/overviewPage' +import IndexPage from '../pages' const visitOverviewPage = (): OverviewPage => { cy.signIn({ redirectPath: '/prisoner/G6123VU' }) @@ -40,4 +41,70 @@ context('Profile banner', () => { cy.getDataQa('hidden-outside-establishment-banner').should('exist') }) }) + + context('Given the prisoner is released from prison', () => { + beforeEach(() => { + cy.task('reset') + cy.setupUserAuth({ + roles: ['ROLE_GLOBAL_SEARCH'], + caseLoads: [{ caseloadFunction: '', caseLoadId: 'OUT', currentlyActive: true, description: '', type: '' }], + }) + cy.setupOverviewPageStubs({ + prisonerNumber: 'G6123VU', + bookingId: 1102484, + prisonerDataOverrides: { prisonId: 'OUT' }, + }) + }) + + context('Hide the incorrect banners', () => { + it('Hide the TRN banner', () => { + visitOverviewPage() + cy.getDataQa('TRN-establishment-banner').should('not.exist') + }) + it('Hide the outside your establishment banner', () => { + visitOverviewPage() + cy.getDataQa('outside-establishment-banner').should('not.exist') + }) + }) + + it('Display the prisoner is released banner', () => { + visitOverviewPage() + cy.getDataQa('OUT-establishment-banner').should('exist') + const indexPage = new IndexPage() + indexPage.prisonerOUTBanner().should('exist') + }) + }) + + context('Given the prisoner is being transferred', () => { + beforeEach(() => { + cy.task('reset') + cy.setupUserAuth({ + roles: ['ROLE_GLOBAL_SEARCH'], + caseLoads: [{ caseloadFunction: '', caseLoadId: 'TRN', currentlyActive: true, description: '', type: '' }], + }) + cy.setupOverviewPageStubs({ + prisonerNumber: 'G6123VU', + bookingId: 1102484, + prisonerDataOverrides: { prisonId: 'TRN' }, + }) + }) + + context('Hide the incorrect banners', () => { + it('Hide the OUT banner', () => { + visitOverviewPage() + cy.getDataQa('OUT-establishment-banner').should('not.exist') + }) + it('Hide the outside your establishment banner', () => { + visitOverviewPage() + cy.getDataQa('outside-establishment-banner').should('not.exist') + }) + }) + + it('Display the prisoner TRN banner', () => { + visitOverviewPage() + cy.getDataQa('TRN-establishment-banner').should('exist') + const indexPage = new IndexPage() + indexPage.prisonerTRNBanner().should('exist') + }) + }) }) diff --git a/integration_tests/pages/index.ts b/integration_tests/pages/index.ts index 573917ef2..66db8db75 100644 --- a/integration_tests/pages/index.ts +++ b/integration_tests/pages/index.ts @@ -6,4 +6,8 @@ export default class IndexPage extends Page { } headerUserName = (): PageElement => cy.get('[data-qa=header-user-name]') + + prisonerOUTBanner = (): PageElement => cy.get('[data-qa="OUT-establishment-banner"]') + + prisonerTRNBanner = (): PageElement => cy.get('[data-qa="TRN-establishment-banner"]') } diff --git a/server/views/partials/profileBanner/profileBannerTop.njk b/server/views/partials/profileBanner/profileBannerTop.njk index 32d406e18..4863fe3c5 100644 --- a/server/views/partials/profileBanner/profileBannerTop.njk +++ b/server/views/partials/profileBanner/profileBannerTop.njk @@ -1,36 +1,36 @@ {% from "../../macros/conditionallyShow.njk" import conditionallyShow %}
- {%- call conditionallyShow({condition: prisonerIsTRN(prisonId) == true, id: 'TRN-establishment-banner'}) -%} -
-
-

- This prisoner is being transferred -

-

Some information may be hidden

+ {% if prisonerIsTRN(prisonId) %} +
+
+

+ This prisoner is being transferred +

+

Some information may be hidden

+
-
- {%- endcall -%} - {%- call conditionallyShow({condition: prisonerIsTRN(prisonId) != true and prisonerBelongsToUsersCaseLoad(prisonId, user.caseLoads) != true, id: 'outside-establishment-banner'}) -%} -
-
-

- This prisoner is not in your establishment -

-

Some information may be hidden

+ {% elseif prisonerIsOut(prisonId) %} +
+
+

+ This person has been released +

+

Some information may be hidden

+
-
- {%- endcall -%} - {%- call conditionallyShow({condition: prisonerIsTRN(prisonId) != true and prisonerIsOut(prisonId) == true, id: 'OUT-establishment-banner'}) -%} -
-
-

- This person has been released -

-

Some information may be hidden

+ {% else %} + {%- call conditionallyShow({condition: prisonerBelongsToUsersCaseLoad(prisonId, user.caseLoads) != true, id: 'outside-establishment-banner'}) -%} +
+
+

+ This prisoner is not in your establishment +

+

Some information may be hidden

+
-
- {%- endcall -%} + {%- endcall -%} + {% endif %}