Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VACMS-19406]Correct Manila Profile Page Leadership Links #2399

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions script/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const createMetalSmithSymlink = require('../src/site/stages/build/plugins/create
const {
processLovellPages,
} = require('../src/site/stages/build/drupal/process-lovell-pages');
const {
processManilaPages,
} = require('../src/site/stages/build/drupal/process-manila-pages');

const defaultBuildtype = ENVIRONMENTS.LOCALHOST;
const defaultHost = HOSTNAMES[defaultBuildtype];
Expand Down Expand Up @@ -284,6 +287,8 @@ app.get('/preview', async (req, res, next) => {

drupalData.data.nodeQuery = drupalData.data.nodes;
processLovellPages(drupalData);
processManilaPages(drupalData);

const pageIndex = req.query?.lovellVariant === 'va' ? 1 : 0;

const drupalPage = drupalData.data.nodes.entities[pageIndex];
Expand Down
3 changes: 3 additions & 0 deletions src/site/stages/build/drupal/metalsmith-drupal.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const { addHubIconField } = require('./benefit-hub');
const { addHomeContent } = require('./home');

const { processLovellPages } = require('./process-lovell-pages');
const { processManilaPages } = require('./process-manila-pages');

const DRUPAL_CACHE_FILENAME = 'drupal/pages.json';
const DRUPAL_HUB_NAV_FILENAME = 'hubNavNames.json';
Expand Down Expand Up @@ -398,6 +399,8 @@ function getDrupalContent(buildOptions) {

// Lovell specific data bifurcation
processLovellPages(drupalData);
// Manila specific data bifurcation
processManilaPages(drupalData);

pipeDrupalPagesIntoMetalsmith(drupalData, files);
await createReactPages(files, drupalData);
Expand Down
76 changes: 76 additions & 0 deletions src/site/stages/build/drupal/process-manila-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* eslint-disable no-param-reassign */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint disabled here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled as the page does need to be reassigned in this build adjustment specific to Manila pages

const MANILA_VA_CLINIC_ENTITY_ID = '1187';

function getManilaClinicUrl(path) {
return typeof path === 'string'
? path.replace(/manila-va-system/i, 'manila-va-clinic')
: path;
}

function isManilaVAClinicPage(page) {
return (
page?.fieldAdministration?.entity?.entityId === MANILA_VA_CLINIC_ENTITY_ID
);
}

function updateManilaSystemLinks(page) {
// Update main URL path
if (page.entityUrl?.path) {
page.entityUrl.path = getManilaClinicUrl(page.entityUrl.path);
}

// Update breadcrumb links
if (page.entityUrl?.breadcrumb) {
page.entityUrl.breadcrumb = page.entityUrl.breadcrumb.map(crumb => ({
...crumb,
url: crumb.url ? getManilaClinicUrl(crumb.url) : crumb.url,
}));
}

// Update field office links
if (page?.fieldOffice?.entity?.entityUrl) {
page.fieldOffice.entity.entityUrl.path = getManilaClinicUrl(
page.fieldOffice.entity.entityUrl.path,
);
}

// Update any listing page links
if (page?.fieldListing?.entity?.entityUrl) {
page.fieldListing.entity.entityUrl.path = getManilaClinicUrl(
page.fieldListing.entity.entityUrl.path,
);
}

return page;
}

function processManilaPages(drupalData) {
const {
manilaVAClinicPages,
otherPages,
} = drupalData.data.nodeQuery.entities.reduce(
(acc, page) => {
if (isManilaVAClinicPage(page)) {
acc.manilaVAClinicPages.push(page);
} else {
acc.otherPages.push(page);
}

return acc;
},
{
manilaVAClinicPages: [],
otherPages: [],
},
);

const processedManilaPages = [
...manilaVAClinicPages,
].map((page, _index, _pages) => updateManilaSystemLinks(page));

drupalData.data.nodeQuery.entities = [...processedManilaPages, ...otherPages];
}

module.exports = {
processManilaPages,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/* eslint-disable @department-of-veterans-affairs/axe-check-required */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESLint disabled here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disabled as there is no direct FE components (labels, titles, wording) being affected, with no way for this to do more than adjust the path of a URL on the page.

const { expect } = require('chai');
const { processManilaPages } = require('../process-manila-pages');

describe('processManilaPages', () => {
it('should process Manila VA Clinic pages and update links', () => {
const mockDrupalData = {
data: {
nodeQuery: {
entities: [
{
fieldAdministration: {
entity: {
entityId: '1187',
},
},
entityUrl: {
path: '/manila-va-system/test',
breadcrumb: [
{ url: '/manila-va-system' },
{ url: '/manila-va-system/test' },
],
},
fieldOffice: {
entity: {
entityUrl: {
path: '/manila-va-system/office',
},
},
},
fieldListing: {
entity: {
entityUrl: {
path: '/manila-va-system/listing',
},
},
},
},
{
fieldAdministration: {
entity: {
entityId: '999',
},
},
entityUrl: {
path: '/other-path',
},
},
],
},
},
};

processManilaPages(mockDrupalData);

const processedEntities = mockDrupalData.data.nodeQuery.entities;
const manilaPage = processedEntities[0];
const otherPage = processedEntities[1];

expect(manilaPage.entityUrl.path).to.equal('/manila-va-clinic/test');
expect(manilaPage.entityUrl.breadcrumb[0].url).to.equal(
'/manila-va-clinic',
);
expect(manilaPage.entityUrl.breadcrumb[1].url).to.equal(
'/manila-va-clinic/test',
);
expect(manilaPage.fieldOffice.entity.entityUrl.path).to.equal(
'/manila-va-clinic/office',
);
expect(manilaPage.fieldListing.entity.entityUrl.path).to.equal(
'/manila-va-clinic/listing',
);
expect(otherPage.entityUrl.path).to.equal('/other-path');
});

it('should handle empty data gracefully', () => {
const emptyDrupalData = {
data: {
nodeQuery: {
entities: [],
},
},
};

processManilaPages(emptyDrupalData);
expect(emptyDrupalData.data.nodeQuery.entities).to.deep.equal([]);
});
});
Loading