Skip to content

Commit

Permalink
field_section name adjust
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmst committed Nov 2, 2023
1 parent 57d7121 commit c6bb833
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/lib/drupal/facilitySideNav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const normalizeMenuItem = (item: MenuItem): SideNavItem => {
label: item.title,
links: nestedItems,
url: { path: item.url },
fieldMenuSection: item.field_menu_section || null,
lovellSection: item.field_menu_section || null,
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/lib/drupal/lovell/tests/mockData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ export const lovellSidenavData = {
url: {
path: '/lovell-federal-health-care-tricare/health-services/returning-service-member-care',
},
fieldMenuSection: 'tricare',
lovellSection: 'tricare',
},
],
url: {
path: '/lovell-federal-health-care-va/health-services',
},
fieldMenuSection: 'va',
lovellSection: 'va',
},
{
description: null,
Expand All @@ -129,7 +129,7 @@ export const lovellSidenavData = {
url: {
path: '/lovell-federal-health-care-tricare/health-services',
},
fieldMenuSection: 'tricare',
lovellSection: 'tricare',
},
{
description: null,
Expand All @@ -144,11 +144,11 @@ export const lovellSidenavData = {
url: {
path: '/lovell-federal-health-care-va/locations/captain-james-a-lovell-federal-health-care-center',
},
fieldMenuSection: 'va',
lovellSection: 'va',
},
],
url: { path: '/lovell-federal-health-care-va/locations' },
fieldMenuSection: 'va',
lovellSection: 'va',
},
{
description: 'TRICARE locations',
Expand All @@ -163,17 +163,17 @@ export const lovellSidenavData = {
url: {
path: '/lovell-federal-health-care-tricare/locations/captain-james-a-lovell-federal-health-care-center',
},
fieldMenuSection: 'tricare',
lovellSection: 'tricare',
},
],
url: {
path: '/lovell-federal-health-care-tricare/locations',
},
fieldMenuSection: 'tricare',
lovellSection: 'tricare',
},
],
url: { path: '' },
fieldMenuSection: 'both',
lovellSection: 'both',
},
{
description: null,
Expand All @@ -186,23 +186,23 @@ export const lovellSidenavData = {
label: 'Events',
links: [],
url: { path: '/lovell-federal-health-care-va/events' },
fieldMenuSection: 'va',
lovellSection: 'va',
},
{
description: null,
expanded: false,
label: 'Events',
links: [],
url: { path: '/lovell-federal-health-care-tricare/events' },
fieldMenuSection: 'tricare',
lovellSection: 'tricare',
},
],
url: { path: '' },
fieldMenuSection: 'both',
lovellSection: 'both',
},
],
url: { path: '/lovell-federal-health-care' },
fieldMenuSection: 'both',
lovellSection: 'both',
},
],
},
Expand Down
24 changes: 10 additions & 14 deletions src/lib/drupal/lovell/tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,38 +323,34 @@ describe('isLovellBifurcatedResource', () => {
})

describe('getLovellVariantOfMenu', () => {
it('should filter out menus with non-matching fieldMenuSection', () => {
it('should filter out menus with non-matching lovellSection', () => {
const result = getLovellVariantOfMenu(lovellSidenavData, 'va')

// Check if the TRICARE specific items are filtered out
expect(
result.data.links[0].links[1].links.find(
(link) => link.fieldMenuSection === 'tricare'
(link) => link.lovellSection === 'tricare'
)
).toBeUndefined()
})

it('should not filter out menus with fieldMenuSection set to "both"', () => {
it('should not filter out menus with lovellSection set to "both"', () => {
const result = getLovellVariantOfMenu(lovellSidenavData, 'va')

// Check if items with fieldMenuSection set to "both" are still there
expect(result.data.links[0].fieldMenuSection).toEqual('both')
expect(result.data.links[0].links[0].fieldMenuSection).toEqual('both')
// Check if items with lovellSection set to "both" are still there
expect(result.data.links[0].lovellSection).toEqual('both')
expect(result.data.links[0].links[0].lovellSection).toEqual('both')
})

it('should keep VA specific items when variant is "va"', () => {
const result = getLovellVariantOfMenu(lovellSidenavData, 'va')

// Check if VA specific items are still there
expect(result.data.links[0].links[0].links[0].fieldMenuSection).toEqual(
'va'
)
expect(result.data.links[0].links[0].links[0].lovellSection).toEqual('va')

// Assert against the 'Locations' sub-submenu item
expect(result.data.links[0].links[0].links[1].label).toEqual('Locations')
expect(result.data.links[0].links[0].links[1].fieldMenuSection).toEqual(
'va'
)
expect(result.data.links[0].links[0].links[1].lovellSection).toEqual('va')
})

it('should filter out VA specific items when variant is "tricare"', () => {
Expand All @@ -363,7 +359,7 @@ describe('getLovellVariantOfMenu', () => {
// Check if VA specific items are filtered out
expect(
result.data.links[0].links[0].links.find(
(link) => link.fieldMenuSection === 'va'
(link) => link.lovellSection === 'va'
)
).toBeUndefined()
})
Expand All @@ -372,7 +368,7 @@ describe('getLovellVariantOfMenu', () => {
const result = getLovellVariantOfMenu(lovellSidenavData, 'tricare')

// Check if TRICARE specific items are still there
expect(result.data.links[0].links[0].links[1].fieldMenuSection).toEqual(
expect(result.data.links[0].links[0].links[1].lovellSection).toEqual(
'tricare'
)
})
Expand Down
3 changes: 1 addition & 2 deletions src/lib/drupal/lovell/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,7 @@ function filterMenu(links: SideNavItem[], variant: LovellVariant) {
return links
.filter(
(menuItem) =>
menuItem.fieldMenuSection === variant ||
menuItem.fieldMenuSection === 'both'
menuItem.lovellSection === variant || menuItem.lovellSection === 'both'
)
.map((menuItem) => ({
...menuItem,
Expand Down
2 changes: 1 addition & 1 deletion src/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export type SideNavItem = {
label: string
links: SideNavItem[]
url: { path: string }
fieldMenuSection?: string
lovellSection?: string
}

export type SideNavData = {
Expand Down

0 comments on commit c6bb833

Please sign in to comment.