Skip to content

Commit

Permalink
Merge branch 'main' into 14745-lovell-sidenavs
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmst authored Nov 2, 2023
2 parents c6bb833 + ec00da9 commit aa68c16
Show file tree
Hide file tree
Showing 19 changed files with 227 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version-file: .nvmrc

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"@types/react-gtm-module": "^2.0.1",
"axios": "^1.5.1",
"clsx": "^2.0.0",
"cross-fetch": "^3.1.8",
"cross-fetch": "^4.0.0",
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
Expand Down Expand Up @@ -83,7 +83,7 @@
"@testing-library/cypress": "^10.0.1",
"@testing-library/dom": "^9.3.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^13.4.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/jest": "^27.5.2",
"@types/lodash": "^4.14.199",
Expand All @@ -98,7 +98,7 @@
"cypress-axe": "^1.5.0",
"debug": "^4.3.4",
"eslint": "8.51.0",
"eslint-config-next": "^13.5.4",
"eslint-config-next": "^14.0.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-cypress": "^2.15.1",
"eslint-plugin-jest": "^27.4.2",
Expand All @@ -121,7 +121,7 @@
"storybook": "^7.5.1",
"ts-node": "^10.9.1",
"typedoc": "^0.22.18",
"typescript": "^4.6.3"
"typescript": "^5.2.2"
},
"resolutions": {
"drupal-jsonapi-params": "2.2.0",
Expand Down
3 changes: 3 additions & 0 deletions src/lib/drupal/lovell/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RESOURCE_TYPES } from '@/lib/constants/resourceTypes'

export const LOVELL = {
federal: {
title: 'Lovell Federal health care',
administration: {
id: 347,
name: 'Lovell Federal health care',
Expand All @@ -10,6 +11,7 @@ export const LOVELL = {
variant: 'federal',
},
tricare: {
title: 'Lovell Federal health care - TRICARE',
administration: {
id: 1039,
name: 'Lovell - TRICARE',
Expand All @@ -18,6 +20,7 @@ export const LOVELL = {
variant: 'tricare',
},
va: {
title: 'Lovell Federal health care - VA',
administration: {
id: 1040,
name: 'Lovell - VA',
Expand Down
13 changes: 11 additions & 2 deletions src/lib/drupal/lovell/staticProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
getOppositeChildVariant,
isLovellBifurcatedResource,
getLovellVariantOfMenu,
getLovellVariantOfBreadcrumbs,
} from './utils'

export function getLovellStaticPropsContext(
Expand Down Expand Up @@ -72,6 +73,7 @@ export function getLovellChildVariantOfResource(

return {
...resource,
breadcrumbs: getLovellVariantOfBreadcrumbs(resource.breadcrumbs, variant),
entityPath: variantPaths[variant],
socialLinks: {
...resource.socialLinks,
Expand Down Expand Up @@ -100,12 +102,19 @@ async function getLovellListingPageStaticPropsResource(
// so we can merge and then calculate page data
}
)) as LovellListingPageFormattedResource
const childVariantPageWithProperBreadcrumbs = {
...childVariantPage,
breadcrumbs: getLovellVariantOfBreadcrumbs(
childVariantPage.breadcrumbs,
context.lovell.variant
),
}

const federalPagePathInfo = await drupalClient.translatePath(
getLovellVariantOfUrl(context.drupalPath, LOVELL.federal.variant)
)
if (!federalPagePathInfo) {
return childVariantPage
return childVariantPageWithProperBreadcrumbs
}
const federalPageId = federalPagePathInfo.entity?.uuid
const federalPage = (await fetchSingleStaticPropsResource(
Expand Down Expand Up @@ -133,7 +142,7 @@ async function getLovellListingPageStaticPropsResource(
const totalPages = Math.ceil(totalItems / pageSize) || 0

return {
...childVariantPage,
...childVariantPageWithProperBreadcrumbs,
[itemProp]: pagedMergedItems,
currentPage: context.listing.page,
totalItems,
Expand Down
79 changes: 79 additions & 0 deletions src/lib/drupal/lovell/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
getOppositeChildVariant,
isLovellBifurcatedResource,
getLovellVariantOfMenu,
getLovellVariantOfUrl,
getLovellVariantOfTitle,
getLovellVariantOfBreadcrumbs,
} from '../utils'
import {
lovellTricareSlug,
Expand Down Expand Up @@ -280,6 +283,82 @@ describe('getOppositeChildVariant', () => {
})
})

describe('getLovellVariantOfUrl', () => {
test('should properly convert relative url', () => {
const url = lovellFederalResource.path.alias
const result = getLovellVariantOfUrl(url, LOVELL.tricare.variant)
expect(result).toBe(lovellTricareResource.path.alias)
})

test('should properly convert absolute url', () => {
const domain = 'https://www.va.gov'
const url = `${domain}${lovellFederalResource.path.alias}`
const result = getLovellVariantOfUrl(url, LOVELL.va.variant)
expect(result).toBe(`${domain}${lovellVaResource.path.alias}`)
})

test('should leave non-Lovell url unchanged', () => {
const url = '/some/non-lovell/path'
const result = getLovellVariantOfUrl(url, LOVELL.va.variant)
expect(result).toBe(url)
})

test('should only replace first occurrence of a lovell path segment', () => {
const url = `${LOVELL.tricare.pathSegment}/${LOVELL.tricare.pathSegment}`
const result = getLovellVariantOfUrl(url, LOVELL.va.variant)
expect(result).toBe(
`${LOVELL.va.pathSegment}/${LOVELL.tricare.pathSegment}`
)
})
})

describe('getLovellVariantOfTitle', () => {
test('should properly convert Lovell title from Federal to child variant', () => {
const title = LOVELL.federal.title
const result = getLovellVariantOfTitle(title, LOVELL.va.variant)
expect(result).toBe(LOVELL.va.title)
})

test('should properly convert Lovell title from child variant to Federal', () => {
const title = LOVELL.tricare.title
const result = getLovellVariantOfTitle(title, LOVELL.federal.variant)
expect(result).toBe(LOVELL.federal.title)
})

test('should leave non-Lovell title unchanged', () => {
const title = 'Some non-Lovell title'
const result = getLovellVariantOfTitle(title, LOVELL.va.variant)
expect(result).toBe(title)
})
})

describe('getLovellVariantOfBreadcrumbs', () => {
const breadcrumbs = [
{
uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/',
title: 'Home',
options: [],
},
{
uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/lovell-federal-health-care',
title: 'Lovell Federal health care',
options: [],
},
]

test('should properly convert breadcrumbs', () => {
const result = getLovellVariantOfBreadcrumbs(breadcrumbs, LOVELL.va.variant)
expect(result).toStrictEqual([
breadcrumbs[0],
{
uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/lovell-federal-health-care-va',
title: 'Lovell Federal health care - VA',
options: [],
},
])
})
})

describe('isLovellBifurcatedResource', () => {
test('should return true when Lovell bifurcated', () => {
const bifurcatedResource = {
Expand Down
95 changes: 88 additions & 7 deletions src/lib/drupal/lovell/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { FormattedResource } from '@/data/queries'
import { ResourceTypeType } from '@/lib/constants/resourceTypes'
import { slugToPath } from '@/lib/utils/slug'
import { SideNavItem, SideNavMenu } from '@/types/index'
import { BreadcrumbItem } from '@/types/dataTypes/drupal/field_type'

export function isLovellResourceType(resourceType: ResourceTypeType): boolean {
return (LOVELL_RESOURCE_TYPES as readonly string[]).includes(resourceType)
Expand Down Expand Up @@ -107,22 +108,102 @@ export function getOppositeChildVariant(
}

/**
* Replaces first segment (system name) in a path according to `variant`.
* Replaces first occurrence of a lovell path segment according to `variant`.
* E.g.
* Input:
* path: `/lovell-federal-health-care-va/stories/story-title`
* variant: `tricare`
* Output: `/lovell-federal-health-care-tricare/stories/story-title`
* Input:
* path: `https://www.va.gov/lovell-federal-health-care-tricare/stories/story-title`
* variant: `va`
* Output: `https://www.va.gov/lovell-federal-health-care-va/stories/story-title`
*
*/
export function getLovellVariantOfUrl(
path: string,
url: string,
variant: LovellVariant
): string {
return url.replace(
// Note: Lovell Federal path segment must be listed
// last since it's a substring of the others and
// we don't want to prematurely match
new RegExp(
[
LOVELL.tricare.pathSegment,
LOVELL.va.pathSegment,
LOVELL.federal.pathSegment,
].join('|')
),
LOVELL[variant].pathSegment
)
}

/**
* Replaces Lovell title string according to `variant`.
* Returns original string if no Lovell match found.
* E.g.
* Input:
* title: `Lovell Federal health care`
* variant: `va`
* Output: `Lovell Federal health care - VA`
*/
export function getLovellVariantOfTitle(
title: string,
variant: LovellVariant
): string {
return `/${LOVELL[variant].pathSegment}/${path
.split('/')
.filter((slug) => slug !== '')
.slice(1)
.join('/')}`
return title.replace(
// Note: Lovell Federal title must be listed
// last since it's a substring of the others and
// we don't want to prematurely match
new RegExp(
[LOVELL.tricare.title, LOVELL.va.title, LOVELL.federal.title].join('|')
),
LOVELL[variant].title
)
}

/**
* Updates breadcrumb entries according to `variant`.
* Non-Lovell entries are unchanged. Lovell entries
* have title and uri updated.
* E.g.
* Input:
* breacrumbs: [
* {
* uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/',
* title: 'Home',
* options: [],
* },
* {
* uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/lovell-federal-health-care',
* title: 'Lovell Federal health care',
* options: [],
* },
* ],
* variant: `va`
* Output: [
* {
* uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/',
* title: 'Home',
* options: [],
* },
* {
* uri: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/lovell-federal-health-care-va',
* title: 'Lovell Federal health care - VA',
* options: [],
* },
* ]
*/
export function getLovellVariantOfBreadcrumbs(
breadcrumbs: BreadcrumbItem[],
variant: LovellVariant
): BreadcrumbItem[] {
return breadcrumbs.map((breadcrumb) => ({
...breadcrumb,
title: getLovellVariantOfTitle(breadcrumb.title, variant),
uri: getLovellVariantOfUrl(breadcrumb.uri, variant),
}))
}

export function isLovellBifurcatedResource(
Expand Down
Loading

0 comments on commit aa68c16

Please sign in to comment.