Skip to content

Commit

Permalink
feat(@dpc-sdp/nuxt-ripple): site specific quick exit
Browse files Browse the repository at this point in the history
  • Loading branch information
lambry committed Oct 23, 2024
1 parent 8d62aef commit 7c0ce6f
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 5 deletions.
24 changes: 23 additions & 1 deletion examples/nuxt-app/test/features/site/shared-elements.feature
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,36 @@ 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
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: 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
Expand Down
10 changes: 8 additions & 2 deletions packages/nuxt-ripple/mapping/base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) || {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
9 changes: 8 additions & 1 deletion packages/ripple-tide-api/src/utils/mapping-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
getSiteKeyValues,
getSiteSection,
humanizeFilesize,
getPlainText
getPlainText,
getBoolFromString
} from './mapping-utils.js'

const field = {
Expand Down Expand Up @@ -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)
})
})
13 changes: 12 additions & 1 deletion packages/ripple-tide-api/src/utils/mapping-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -263,5 +273,6 @@ export default {
getDocumentFromField,
getSiteKeyValues,
getSiteSection,
getPlainText
getPlainText,
getBoolFromString
}

0 comments on commit 7c0ce6f

Please sign in to comment.