diff --git a/src/data/queries/pressRelease.ts b/src/data/queries/pressRelease.ts index 3e51e8b51..b98268cf5 100644 --- a/src/data/queries/pressRelease.ts +++ b/src/data/queries/pressRelease.ts @@ -19,6 +19,7 @@ export const params: QueryParams = () => { 'media--document', ]), 'field_press_release_contact', + 'field_press_release_contact.field_telephone', 'field_listing', 'field_administration', ...getNestedIncludes('field_pdf_version', 'media--document'), @@ -75,6 +76,7 @@ export const formatter: QueryFormatter = ( } }) : [] + // Setting phone numbers to an array even though there is only one in case multiple are added in the future. const formattedContacts = entity.field_press_release_contact ? entity.field_press_release_contact.map((contact) => { return { @@ -82,7 +84,14 @@ export const formatter: QueryFormatter = ( description: contact?.field_description || null, name: contact?.title || null, email: contact?.field_email_address || null, - phone: contact?.field_phone_number || null, + numbers: [contact?.field_telephone].map((number) => { + return { + id: number?.id || null, + type: number?.field_phone_number_type || null, + number: number?.field_phone_number || null, + ext: number?.field_phone_extension || null, + } + }), } }) : [] diff --git a/src/data/queries/tests/__snapshots__/newsStory.test.tsx.snap b/src/data/queries/tests/__snapshots__/newsStory.test.tsx.snap index 211221862..d58c282c1 100644 --- a/src/data/queries/tests/__snapshots__/newsStory.test.tsx.snap +++ b/src/data/queries/tests/__snapshots__/newsStory.test.tsx.snap @@ -31,9 +31,50 @@ exports[`node--news_story formatData outputs formatted data 1`] = ` "field_meta_tags": null, "field_name_first": "Keith", "field_office": null, - "field_phone_number": null, "field_photo_allow_hires_download": false, "field_suffix": null, + "field_telephone": { + "behavior_settings": [], + "breadcrumbs": [], + "content_translation_changed": "2024-11-25T18:00:06+00:00", + "content_translation_outdated": false, + "content_translation_source": "und", + "created": "2024-11-25T18:00:06+00:00", + "default_langcode": true, + "drupal_internal__id": 163647, + "drupal_internal__revision_id": 1561519, + "field_phone_extension": null, + "field_phone_label": null, + "field_phone_number": "412-360-1479", + "field_phone_number_type": "phone", + "id": "a96f65e2-5a82-4b59-b249-25c634e93108", + "langcode": "en", + "links": { + "self": { + "href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519", + }, + }, + "paragraph_type": { + "id": "9c5d2698-f605-42f2-a516-15949b84d17f", + "resourceIdObjMeta": { + "drupal_internal__target_id": "phone_number", + }, + "type": "paragraphs_type--paragraphs_type", + }, + "parent_field_name": "field_telephone", + "parent_id": "94", + "parent_type": "node", + "relationshipNames": [ + "paragraph_type", + ], + "resourceIdObjMeta": { + "drupal_internal__target_id": 163647, + "target_revision_id": 1561519, + }, + "revision_translation_affected": null, + "status": true, + "type": "paragraph--phone_number", + }, "id": "c76037be-ebb0-4338-9b31-973a76958929", "langcode": "en", "links": { diff --git a/src/data/queries/tests/__snapshots__/pressRelease.test.tsx.snap b/src/data/queries/tests/__snapshots__/pressRelease.test.tsx.snap index 54ae6aa44..8b8b2d92d 100644 --- a/src/data/queries/tests/__snapshots__/pressRelease.test.tsx.snap +++ b/src/data/queries/tests/__snapshots__/pressRelease.test.tsx.snap @@ -34,7 +34,22 @@ exports[`node--press_release formatData output formatted data 1`] = ` "uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/wilmington-health-care/news-releases/wilmington-vamc-2019-annual-report", }, ], - "contacts": [], + "contacts": [ + { + "description": "Public Affairs Specialist", + "email": "sheila.tunney@va.gov", + "id": "7ecb5154-7e2c-4c16-a171-bb3710a4dab7", + "name": "Sheila Tunney", + "numbers": [ + { + "ext": null, + "id": "a96f65e2-5a82-4b59-b249-25c634e93108", + "number": "412-360-1479", + "type": "phone", + }, + ], + }, + ], "downloads": [], "entityId": 18141, "entityPath": "/wilmington-health-care/news-releases/wilmington-vamc-2019-annual-report", diff --git a/src/data/queries/tests/pressRelease.test.tsx b/src/data/queries/tests/pressRelease.test.tsx index 676829666..abd00f262 100644 --- a/src/data/queries/tests/pressRelease.test.tsx +++ b/src/data/queries/tests/pressRelease.test.tsx @@ -43,6 +43,40 @@ describe(`${RESOURCE_TYPES.PRESS_RELEASE} formatData`, () => { expect(formattedData.administration.name).toBeNull() expect(formattedData.pdfVersion).toBeNull() }) + test('handles missing or null contact fields correctly', () => { + const modifiedMockContact: NodePressRelease = { + ...nodePressReleaseMock, + field_press_release_contact: [ + { + ...nodePressReleaseMock.field_press_release_contact[0], + id: undefined, + field_description: undefined, + title: undefined, + field_email_address: undefined, + field_telephone: { + ...nodePressReleaseMock.field_press_release_contact[0] + .field_telephone, + id: undefined, + field_phone_number_type: undefined, + field_phone_number: undefined, + field_phone_extension: undefined, + }, + }, + ], + } + const formattedData = queries.formatData( + RESOURCE_TYPES.PRESS_RELEASE, + modifiedMockContact + ) + expect(formattedData.contacts[0].id).toBeNull() + expect(formattedData.contacts[0].description).toBeNull() + expect(formattedData.contacts[0].name).toBeNull() + expect(formattedData.contacts[0].email).toBeNull() + expect(formattedData.contacts[0].numbers[0].id).toBeNull() + expect(formattedData.contacts[0].numbers[0].type).toBeNull() + expect(formattedData.contacts[0].numbers[0].number).toBeNull() + expect(formattedData.contacts[0].numbers[0].ext).toBeNull() + }) }) describe('DrupalJsonApiParams configuration for pressRelease', () => { @@ -50,7 +84,7 @@ describe('DrupalJsonApiParams configuration for pressRelease', () => { const paramsInstance = params() const queryString = decodeURIComponent(paramsInstance.getQueryString()) expect(queryString).toMatch( - /include=field_press_release_downloads,field_press_release_downloads.image,field_press_release_downloads.field_document,field_press_release_contact,field_listing,field_administration,field_pdf_version,field_pdf_version.field_document/ + /include=field_press_release_downloads,field_press_release_downloads.image,field_press_release_downloads.field_document,field_press_release_contact,field_press_release_contact.field_telephone,field_listing,field_administration,field_pdf_version,field_pdf_version.field_document/ ) }) }) diff --git a/src/mocks/newsStory.mock.json b/src/mocks/newsStory.mock.json index fd7fd0910..d04130df4 100644 --- a/src/mocks/newsStory.mock.json +++ b/src/mocks/newsStory.mock.json @@ -195,7 +195,46 @@ "field_last_saved_by_editor": "2019-11-12T20:21:16+00:00", "field_meta_tags": null, "field_name_first": "Keith", - "field_phone_number": null, + "field_telephone": { + "type": "paragraph--phone_number", + "id": "a96f65e2-5a82-4b59-b249-25c634e93108", + "drupal_internal__id": 163647, + "drupal_internal__revision_id": 1561519, + "langcode": "en", + "status": true, + "created": "2024-11-25T18:00:06+00:00", + "parent_id": "94", + "parent_type": "node", + "parent_field_name": "field_telephone", + "behavior_settings": [], + "default_langcode": true, + "revision_translation_affected": null, + "breadcrumbs": [], + "content_translation_source": "und", + "content_translation_outdated": false, + "content_translation_changed": "2024-11-25T18:00:06+00:00", + "field_phone_extension": null, + "field_phone_label": null, + "field_phone_number": "412-360-1479", + "field_phone_number_type": "phone", + "links": { + "self": { + "href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519" + } + }, + "resourceIdObjMeta": { + "target_revision_id": 1561519, + "drupal_internal__target_id": 163647 + }, + "paragraph_type": { + "type": "paragraphs_type--paragraphs_type", + "id": "9c5d2698-f605-42f2-a516-15949b84d17f", + "resourceIdObjMeta": { + "drupal_internal__target_id": "phone_number" + } + }, + "relationshipNames": ["paragraph_type"] + }, "field_photo_allow_hires_download": false, "field_suffix": null, "links": { diff --git a/src/mocks/pressRelease.mock.json b/src/mocks/pressRelease.mock.json index dbb0df281..86b2c680a 100644 --- a/src/mocks/pressRelease.mock.json +++ b/src/mocks/pressRelease.mock.json @@ -368,7 +368,170 @@ } } }, - "field_press_release_contact": [], + "field_press_release_contact": [ + { + "type": "node--person_profile", + "id": "7ecb5154-7e2c-4c16-a171-bb3710a4dab7", + "drupal_internal__nid": 94, + "drupal_internal__vid": 988884, + "sticky": false, + "default_langcode": true, + "langcode": "en", + "status": true, + "title": "Sheila Tunney", + "created": "2019-02-26T05:47:15+00:00", + "changed": "2024-11-25T18:00:07+00:00", + "breadcrumbs": [ + { + "uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/", + "title": "Home", + "options": [] + }, + { + "uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/pittsburgh-health-care", + "title": "VA Pittsburgh Health Care", + "options": [] + }, + { + "uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/pittsburgh-health-care/staff-profiles/sheila-tunney", + "title": "Sheila Tunney", + "options": [] + } + ], + "moderation_state": "published", + "expiration_date": null, + "warning_date": null, + "metatag": [ + { + "tag": "meta", + "attributes": { + "name": "title", + "content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs" + } + }, + { + "tag": "link", + "attributes": { + "rel": "image_src", + "href": "https://www.va.gov/img/design/logo/va-og-image.png" + } + }, + { + "tag": "meta", + "attributes": { + "property": "og:site_name", + "content": "Veterans Affairs" + } + }, + { + "tag": "meta", + "attributes": { + "property": "og:title", + "content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs" + } + }, + { + "tag": "meta", + "attributes": { + "name": "twitter:card", + "content": "summary_large_image" + } + }, + { + "tag": "meta", + "attributes": { + "name": "twitter:site", + "content": "@DeptVetAffairs" + } + }, + { + "tag": "meta", + "attributes": { + "name": "twitter:title", + "content": "Sheila Tunney | VA Pittsburgh health care | Veterans Affairs" + } + } + ], + "path": { + "alias": "/pittsburgh-health-care/staff-profiles/sheila-tunney", + "pid": 214, + "langcode": "en" + }, + "field_body": null, + "field_complete_biography_create": false, + "field_description": "Public Affairs Specialist", + "field_email_address": "sheila.tunney@va.gov", + "field_intro_text": null, + "field_last_name": "Tunney", + "field_last_saved_by_an_editor": "2024-05-02T13:03:19+00:00", + "field_meta_tags": null, + "field_name_first": "Sheila", + "field_photo_allow_hires_download": false, + "field_suffix": null, + "links": { + "self": { + "href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/node/person_profile/7ecb5154-7e2c-4c16-a171-bb3710a4dab7?resourceVersion=id%3A934975" + } + }, + "node_type": { + "type": "node_type--node_type", + "id": "89b07673-7fd5-4292-8fba-58cc10c4e3ec", + "resourceIdObjMeta": { + "drupal_internal__target_id": "person_profile" + } + }, + "field_administration": { + "type": "taxonomy_term--administration", + "id": "87832236-1e54-4ce3-8141-8dec27c8a9a7", + "resourceIdObjMeta": { + "drupal_internal__target_id": 12 + } + }, + "field_complete_biography": null, + "field_media": null, + "field_office": null, + "field_telephone": { + "type": "paragraph--phone_number", + "id": "a96f65e2-5a82-4b59-b249-25c634e93108", + "drupal_internal__id": 163647, + "drupal_internal__revision_id": 1561519, + "langcode": "en", + "status": true, + "created": "2024-11-25T18:00:06+00:00", + "parent_id": "94", + "parent_type": "node", + "parent_field_name": "field_telephone", + "behavior_settings": [], + "default_langcode": true, + "revision_translation_affected": null, + "breadcrumbs": [], + "content_translation_source": "und", + "content_translation_outdated": false, + "content_translation_changed": "2024-11-25T18:00:06+00:00", + "field_phone_extension": null, + "field_phone_label": null, + "field_phone_number": "412-360-1479", + "field_phone_number_type": "phone", + "links": { + "self": { + "href": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519" + } + }, + "resourceIdObjMeta": { + "target_revision_id": 1561519, + "drupal_internal__target_id": 163647 + }, + "paragraph_type": { + "type": "paragraphs_type--paragraphs_type", + "id": "9c5d2698-f605-42f2-a516-15949b84d17f", + "resourceIdObjMeta": { + "drupal_internal__target_id": "phone_number" + } + }, + "relationshipNames": ["paragraph_type"] + } + } + ], "field_press_release_downloads": [], "field_administration": { "drupal_internal__tid": 188, diff --git a/src/mocks/staffProfile.mock.js b/src/mocks/staffProfile.mock.js index ac31e7743..6f7e579d7 100644 --- a/src/mocks/staffProfile.mock.js +++ b/src/mocks/staffProfile.mock.js @@ -48,7 +48,46 @@ export const mockResponse = { field_last_name: 'Smathers', field_meta_tags: null, field_name_first: 'William', - field_phone_number: '412-551-9651', + field_telephone: { + type: 'paragraph--phone_number', + id: 'a96f65e2-5a82-4b59-b249-25c634e93108', + drupal_internal__id: 163647, + drupal_internal__revision_id: 1561519, + langcode: 'en', + status: true, + created: '2024-11-25T18:00:06+00:00', + parent_id: '94', + parent_type: 'node', + parent_field_name: 'field_telephone', + behavior_settings: [], + default_langcode: true, + revision_translation_affected: null, + breadcrumbs: [], + content_translation_source: 'und', + content_translation_outdated: false, + content_translation_changed: '2024-11-25T18:00:06+00:00', + field_phone_extension: null, + field_phone_label: null, + field_phone_number: '412-360-1479', + field_phone_number_type: 'phone', + links: { + self: { + href: 'https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/jsonapi/paragraph/phone_number/a96f65e2-5a82-4b59-b249-25c634e93108?resourceVersion=id%3A1561519', + }, + }, + resourceIdObjMeta: { + target_revision_id: 1561519, + drupal_internal__target_id: 163647, + }, + paragraph_type: { + type: 'paragraphs_type--paragraphs_type', + id: '9c5d2698-f605-42f2-a516-15949b84d17f', + resourceIdObjMeta: { + drupal_internal__target_id: 'phone_number', + }, + }, + relationshipNames: ['paragraph_type'], + }, field_photo_allow_hires_download: false, field_suffix: 'Mr', field_body: null, diff --git a/src/templates/layouts/pressRelease/index.test.tsx b/src/templates/layouts/pressRelease/index.test.tsx index 738ecdb10..6ea78f2c6 100644 --- a/src/templates/layouts/pressRelease/index.test.tsx +++ b/src/templates/layouts/pressRelease/index.test.tsx @@ -2,13 +2,45 @@ import { render, screen } from '@testing-library/react' import { PressRelease } from './index' import { getByText } from '@testing-library/react' import { fireEvent } from '@testing-library/react' +import { getByTestId } from '@testing-library/dom' const contacts = [ { id: '96668498-d442-4b55-8b14-7ec90410f418', name: 'Vance Janes', description: 'Public Affairs Officer', - phone: '828-298-7911, ext. 4446', + numbers: [ + { + id: 'a93d21bb-3ee0-4ffe-9996-91f7c6e6bdc3', + type: 'phone', + number: '617-435-7809', + ext: null, + }, + { + id: 'a93d21bb-3ee0-4ffe-9996-91f7c6e6bdc4', + type: 'sms', + number: '617-435-7810', + ext: null, + }, + { + id: 'a93d21bb-3ee0-4ffe-9996-91f7c6e6bdc5', + type: 'tty', + number: '617-435-7811', + ext: null, + }, + { + id: 'a93d21bb-3ee0-4ffe-9996-91f7c6e6bdc6', + type: 'phone', + number: '617-435-7812', + ext: '111', + }, + { + id: 'a93d21bb-3ee0-4ffe-9996-91f7c6e6bdc6', + type: 'fax', + number: '617-435-7813', + ext: null, + }, + ], email: 'vance.janes@va.gov', }, ] @@ -109,13 +141,64 @@ describe(' with valid data', () => { expect( screen.getByText(`${contact.name}, ${contact.description}`) ).toBeInTheDocument() - expect(screen.getByText(contact.phone)).toBeInTheDocument() const emailLink = screen.getByTestId('press-email') expect(emailLink).toBeInTheDocument() expect(emailLink).toHaveAttribute('href', `mailto:${contact.email}`) + expect(screen.getByTestId('phone-0')).toBeInTheDocument() }) }) + test('renders contact phone', () => { + render() + const voice = screen.getByTestId('phone-0') + const sms = screen.getByTestId('phone-1') + const tty = screen.getByTestId('phone-2') + const ext = screen.getByTestId('phone-3') + const fax = screen.getByTestId('phone-4') + expect(voice).toBeInTheDocument() + expect(voice).toHaveAttribute('contact', data.contacts[0].numbers[0].number) + expect(voice).not.toHaveAttribute('sms') + expect(voice).not.toHaveAttribute('tty') + expect(voice).not.toHaveAttribute('extension') + expect(voice).toHaveAttribute('message-aria-describedby', 'Phone') + expect(screen.getByTestId('phone-label-0')).toHaveTextContent('Phone:') + expect(sms).toBeInTheDocument() + expect(sms).toHaveAttribute('contact', data.contacts[0].numbers[1].number) + expect(sms).toHaveAttribute('sms') + expect(sms).not.toHaveAttribute('tty') + expect(sms).not.toHaveAttribute('extension') + expect(sms).toHaveAttribute('message-aria-describedby', 'Phone') + expect(screen.getByTestId('phone-label-1')).toHaveTextContent('Phone:') + expect(tty).toBeInTheDocument() + expect(tty).toHaveAttribute('contact', data.contacts[0].numbers[2].number) + expect(tty).not.toHaveAttribute('sms') + expect(tty).toHaveAttribute('tty') + expect(tty).not.toHaveAttribute('extension') + expect(tty).toHaveAttribute('message-aria-describedby', 'Phone') + expect(screen.getByTestId('phone-label-2')).toHaveTextContent('Phone:') + expect(ext).toBeInTheDocument() + expect(ext).toHaveAttribute('contact', data.contacts[0].numbers[3].number) + expect(ext).not.toHaveAttribute('sms') + expect(ext).not.toHaveAttribute('tty') + expect(ext).toHaveAttribute('extension', data.contacts[0].numbers[3].ext) + expect(ext).toHaveAttribute('message-aria-describedby', 'Phone') + expect(screen.getByTestId('phone-label-3')).toHaveTextContent('Phone:') + expect(fax).toBeInTheDocument() + expect(fax).toHaveAttribute('contact', data.contacts[0].numbers[4].number) + expect(fax).not.toHaveAttribute('sms') + expect(fax).not.toHaveAttribute('tty') + expect(fax).not.toHaveAttribute('extension') + expect(fax).toHaveAttribute('message-aria-describedby', 'Fax') + expect(screen.getByTestId('phone-label-4')).toHaveTextContent('Fax:') + }) + + test('does not render numbers if null', () => { + const nullNumbers = { ...data } + nullNumbers.contacts[0].numbers = null + render() + expect(screen.queryByTestId('phone-0')).not.toBeInTheDocument() + }) + test('renders contacts when null', () => { data.contacts = [null] render() diff --git a/src/templates/layouts/pressRelease/index.tsx b/src/templates/layouts/pressRelease/index.tsx index b0e3822ac..ab802c027 100644 --- a/src/templates/layouts/pressRelease/index.tsx +++ b/src/templates/layouts/pressRelease/index.tsx @@ -77,9 +77,31 @@ export const PressRelease = ({

{`${contact?.name}${contact?.description ? `, ${contact?.description}` : ''}`}

-

- {contact?.phone} -

+ {contact?.numbers?.map((phone, index) => { + const label = phone.type === 'fax' ? 'Fax' : 'Phone' + return ( +

+ + {`${label}:`} + + +

+ ) + })} {contact?.email && (

{ linkToBio: true, path: 'http:va.gov', description: 'OEF Transition Patient Advocate', - phone: '412-551-9651', email: 'william.smathers@aol.com', } @@ -36,7 +35,6 @@ describe('transformStaffProfileData', () => { linkToBio: true, path: null, description: 'OEF Transition Patient Advocate', - phone: '412-551-9651', email: 'william.smathers@aol.com', } diff --git a/src/templates/layouts/staffProfile/dataService.tsx b/src/templates/layouts/staffProfile/dataService.tsx index b5f8dff4d..940da8cbd 100644 --- a/src/templates/layouts/staffProfile/dataService.tsx +++ b/src/templates/layouts/staffProfile/dataService.tsx @@ -31,7 +31,6 @@ export const transformStaffProfileData = function ( linkToBio: entity.field_staff_profile.field_complete_biography_create, path: entity.field_staff_profile.field_entity?.entityUrl.path || null, description: entity.field_staff_profile.field_description, - phone: entity.field_staff_profile.field_phone_number, email: entity.field_staff_profile.field_email_address, } } diff --git a/src/types/drupal/node.ts b/src/types/drupal/node.ts index f43879245..6c15c2789 100644 --- a/src/types/drupal/node.ts +++ b/src/types/drupal/node.ts @@ -284,7 +284,7 @@ export interface NodePersonProfile extends DrupalNode { /** Last name. */ field_last_name: string /** Phone number. */ - field_phone_number: string + field_telephone: ParagraphPhoneNumber /** A photo of the person. */ field_media: DrupalMediaImage /** The office or facility which this person is associated with. */ diff --git a/src/types/formatted/contactInfo.ts b/src/types/formatted/contactInfo.ts index aac860735..a392f516b 100644 --- a/src/types/formatted/contactInfo.ts +++ b/src/types/formatted/contactInfo.ts @@ -59,10 +59,16 @@ export type EmailContact = PublishedParagraph & { export type AdditionalContact = PhoneContact | EmailContact +export type Phone = { + id: string + type: 'phone' | 'tty' | 'sms' | 'fax' + number: string + ext: string +} export type PressContact = { id: string name: string description: string - phone: string + numbers: Phone[] email: string }