From 7c0ce6f08dad625a73c63a97a1fb3fae2cd560de Mon Sep 17 00:00:00 2001 From: David Featherston Date: Wed, 23 Oct 2024 17:23:25 +1100 Subject: [PATCH] feat(@dpc-sdp/nuxt-ripple): site specific quick exit --- .../features/site/shared-elements.feature | 24 ++++++++++++++++++- packages/nuxt-ripple/mapping/base/index.ts | 10 ++++++-- .../common/shared-elements.ts | 12 ++++++++++ .../src/utils/mapping-utils.test.ts | 9 ++++++- .../src/utils/mapping-utils.ts | 13 +++++++++- 5 files changed, 63 insertions(+), 5 deletions(-) diff --git a/examples/nuxt-app/test/features/site/shared-elements.feature b/examples/nuxt-app/test/features/site/shared-elements.feature index 6fea7fa727..ea4f55c0b9 100644 --- a/examples/nuxt-app/test/features/site/shared-elements.feature +++ b/examples/nuxt-app/test/features/site/shared-elements.feature @@ -26,7 +26,7 @@ Feature: Shared site elements Then the quick exit should be displayed @mockserver - Scenario: Quick Exit (enabled in site section) + Scenario: Quick Exit (disabled site wide, enabled in site section) Given the site endpoint returns fixture "/site/shared-elements" with status 200 And I load the page fixture with "/landingpage/home" And the site section quick exit is enabled @@ -34,6 +34,28 @@ Feature: Shared site elements Given I visit the page "/section-page" Then the quick exit should be displayed + @mockserver + Scenario: Quick Exit (enabled site wide, disabled in site section) + Given I load the site fixture with "/site/shared-elements" + And the site wide quick exit is enabled + And the site endpoint returns the loaded fixture + Given I load the page fixture with "/landingpage/home" + And the site section quick exit is disabled + And the page endpoint for path "/section-page" returns the loaded fixture + Given I visit the page "/section-page" + Then the quick exit should not be displayed + + @mockserver + Scenario: Quick Exit (enabled site wide, inherited in site section) + Given I load the site fixture with "/site/shared-elements" + And the site wide quick exit is enabled + And the site endpoint returns the loaded fixture + Given I load the page fixture with "/landingpage/home" + And the site section quick exit is inherited + And the page endpoint for path "/section-page" returns the loaded fixture + Given I visit the page "/section-page" + Then the quick exit should be displayed + @mockserver Scenario: Breadcrumbs (page exists in menu) Given the site endpoint returns fixture "/site/shared-elements" with status 200 diff --git a/packages/nuxt-ripple/mapping/base/index.ts b/packages/nuxt-ripple/mapping/base/index.ts index cd4fc285ff..d180578407 100644 --- a/packages/nuxt-ripple/mapping/base/index.ts +++ b/packages/nuxt-ripple/mapping/base/index.ts @@ -23,7 +23,11 @@ import { includes as sidebarSiteSectionNavIncludes } from './sidebar-site-section-nav/sidebar-site-section-nav-mapping.js' import TidePageMeta from './page-meta.js' -import { getSiteKeyValues, getSiteSection } from '@dpc-sdp/ripple-tide-api' +import { + getSiteKeyValues, + getSiteSection, + getBoolFromString +} from '@dpc-sdp/ripple-tide-api' export const tidePageBaseMapping = ({ // eslint-disable-next-line @typescript-eslint/no-unused-vars @@ -76,7 +80,9 @@ export const tidePageBaseMapping = ({ id: siteData.drupal_internal__tid, name: siteData.name, siteOverrides: { - showQuickExit: siteData?.field_site_show_exit_site || null, + showQuickExit: getBoolFromString( + siteData?.field_show_exit_site_specific + ), theme: getSiteKeyValues('field_site_theme_values', siteData) || {}, featureFlags: getSiteKeyValues('field_site_feature_flags', siteData) || {} diff --git a/packages/ripple-test-utils/step_definitions/common/shared-elements.ts b/packages/ripple-test-utils/step_definitions/common/shared-elements.ts index 6cd7232a32..14a1aaca97 100644 --- a/packages/ripple-test-utils/step_definitions/common/shared-elements.ts +++ b/packages/ripple-test-utils/step_definitions/common/shared-elements.ts @@ -252,6 +252,18 @@ Given('the site section quick exit is enabled', () => { }) }) +Given('the site section quick exit is disabled', () => { + cy.get('@pageFixture').then((response) => { + set(response, 'siteSection.siteOverrides.showQuickExit', false) + }) +}) + +Given('the site section quick exit is inherited', () => { + cy.get('@pageFixture').then((response) => { + set(response, 'siteSection.siteOverrides.showQuickExit', null) + }) +}) + Then('the quick exit should be displayed', () => { cy.get('.rpl-primary-nav__quick-exit').should('be.visible') }) diff --git a/packages/ripple-tide-api/src/utils/mapping-utils.test.ts b/packages/ripple-tide-api/src/utils/mapping-utils.test.ts index 0c53b258f0..68accf47b2 100644 --- a/packages/ripple-tide-api/src/utils/mapping-utils.test.ts +++ b/packages/ripple-tide-api/src/utils/mapping-utils.test.ts @@ -9,7 +9,8 @@ import { getSiteKeyValues, getSiteSection, humanizeFilesize, - getPlainText + getPlainText, + getBoolFromString } from './mapping-utils.js' const field = { @@ -229,4 +230,10 @@ describe('ripple-tide-api/mapping utils', () => { 'We acknowledge Aboriginal and Torres Strait Islander people as the First People and traditional owners and custodians of the lands, seas and waters of Australia. We pay our respect to Elders past and present.' ) }) + + it(`returns a boolean value from supplied string`, () => { + expect(getBoolFromString('yes')).toEqual(true) + expect(getBoolFromString('no')).toEqual(false) + expect(getBoolFromString('')).toEqual(null) + }) }) diff --git a/packages/ripple-tide-api/src/utils/mapping-utils.ts b/packages/ripple-tide-api/src/utils/mapping-utils.ts index 63dc1bc33e..c68e247375 100644 --- a/packages/ripple-tide-api/src/utils/mapping-utils.ts +++ b/packages/ripple-tide-api/src/utils/mapping-utils.ts @@ -251,6 +251,16 @@ export const getPlainText = (content: string): string => { return content?.replace(/(\r\n|\n|\r)/g, '')?.trim() } +/** + * @description converts supplied string value i.e. 'yes', 'no' into true or false + */ +export const getBoolFromString = (text: string): boolean | null => { + if (text === 'yes') return true + if (text === 'no') return false + + return null +} + export default { getImageFromField, getLinkFromField, @@ -263,5 +273,6 @@ export default { getDocumentFromField, getSiteKeyValues, getSiteSection, - getPlainText + getPlainText, + getBoolFromString }