-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add events query/formatter/layout (#264)
- Loading branch information
Showing
19 changed files
with
1,470 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { test, expect } = require('../utils/next-test') | ||
|
||
test.describe('Event Page', () => { | ||
test('Event page renders with correct title and details', async ({ | ||
page, | ||
}) => { | ||
await page.goto('/central-iowa-health-care/events/52265/') | ||
await expect(page.locator('h1')).toHaveText('Pickleball Club') // Replace with actual event title | ||
await expect(page.locator('.va-introtext')).toContainText('Pickleball') // Replace with actual event description | ||
}) | ||
|
||
test('Should render without a11y errors', async ({ | ||
page, | ||
makeAxeBuilder, | ||
}) => { | ||
await page.goto('/central-iowa-health-care/events/52265/') | ||
|
||
const accessibilityScanResults = await makeAxeBuilder().analyze() | ||
|
||
expect(accessibilityScanResults.violations).toEqual([]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ body { | |
margin-top: 0; | ||
padding-top: 1.25rem; | ||
} | ||
|
||
.recurring-event { | ||
max-width: 140px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
QueryData, | ||
QueryFormatter, | ||
QueryOpts, | ||
QueryParams, | ||
} from 'next-drupal-query' | ||
import { drupalClient } from '@/lib/drupal/drupalClient' | ||
import { queries } from '.' | ||
import { NodeEvent } from '@/types/dataTypes/drupal/node' | ||
import { Event } from '@/types/dataTypes/formatted/event' | ||
import { GetServerSidePropsContext } from 'next' | ||
import { MediaImage } from '@/types/dataTypes/formatted/media' | ||
|
||
export const params: QueryParams<null> = () => { | ||
return queries | ||
.getParams() | ||
.addInclude([ | ||
'field_media', | ||
'field_media.image', | ||
'field_listing', | ||
'field_administration', | ||
'field_facility_location', | ||
]) | ||
} | ||
|
||
// Define the option types for the data loader. | ||
export type EventDataOpts = QueryOpts<{ | ||
id: string | ||
context?: GetServerSidePropsContext | ||
}> | ||
|
||
export const data: QueryData<EventDataOpts, NodeEvent> = async ( | ||
opts | ||
): Promise<NodeEvent> => { | ||
const entity = opts?.context?.preview | ||
? // need to use getResourceFromContext for unpublished revisions | ||
await drupalClient.getResourceFromContext<NodeEvent>( | ||
'node--event', | ||
opts.context, | ||
{ | ||
params: params().getQueryObject(), | ||
} | ||
) | ||
: // otherwise just lookup by uuid | ||
await drupalClient.getResource<NodeEvent>('node--event', opts.id, { | ||
params: params().getQueryObject(), | ||
}) | ||
return entity | ||
} | ||
|
||
export const formatter: QueryFormatter<NodeEvent, Event> = ( | ||
entity: NodeEvent | ||
) => { | ||
return { | ||
id: entity.id, | ||
entityId: entity.drupal_internal__nid, | ||
entityPath: entity.path.alias, | ||
type: entity.type, | ||
published: entity.status, | ||
title: entity.title, | ||
image: queries.formatData('media--image', { | ||
entity: entity.field_media, | ||
cropType: '2_1_large', | ||
}) as MediaImage, | ||
date: entity.created, | ||
breadcrumbs: entity.breadcrumbs, | ||
socialLinks: { | ||
path: entity.path.alias, | ||
title: entity.title, | ||
}, | ||
metatags: entity.metatag, | ||
listing: entity.field_listing.path.alias, | ||
additionalInfo: entity.field_additional_information_abo, | ||
address: entity.field_address, | ||
locationHumanReadable: entity.field_location_humanreadable, | ||
eventCTA: entity.field_event_cta, | ||
cost: entity.field_event_cost, | ||
datetimeRange: entity.field_datetime_range_timezone, | ||
facilityLocation: entity.field_facility_location, | ||
body: entity.field_body, | ||
locationType: entity.field_location_type, | ||
description: entity.field_description, | ||
link: entity.field_link, | ||
urlOfOnlineEvent: entity.field_url_of_an_online_event, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`node--event formatData outputs formatted data 1`] = ` | ||
{ | ||
"additionalInfo": null, | ||
"address": { | ||
"address_line1": "9000 Douglas Ave", | ||
"address_line2": "", | ||
"administrative_area": "IA", | ||
"country_code": "US", | ||
"langcode": "en", | ||
"locality": "Urbandale", | ||
}, | ||
"body": { | ||
"format": "rich_text", | ||
"processed": "<p>Pickleball Club</p> | ||
<p>Meets Thursdays from 9 to 11 a.m. </p> | ||
<p>Contact Kay Queck (515) 214-4578</p>", | ||
"value": "<p>Pickleball Club</p> | ||
<p>Meets Thursdays from 9 to 11 a.m. </p> | ||
<p>Contact Kay Queck (515) 214-4578</p> | ||
", | ||
}, | ||
"breadcrumbs": [ | ||
{ | ||
"options": [], | ||
"title": "Home", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "VA Central Iowa health care", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "Events", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care/events", | ||
}, | ||
{ | ||
"options": [], | ||
"title": "Pickleball Club", | ||
"uri": "https://content-build-medc0xjkxm4jmpzxl3tfbcs7qcddsivh.ci.cms.va.gov/central-iowa-health-care/events/52265", | ||
}, | ||
], | ||
"cost": "Free", | ||
"date": "2022-12-30T14:49:05+00:00", | ||
"datetimeRange": [ | ||
{ | ||
"duration": 120, | ||
"end_value": "2023-09-07T16:00:00+00:00", | ||
"rrule": 180, | ||
"rrule_index": 1, | ||
"timezone": "America/Chicago", | ||
"value": "2023-09-07T14:00:00+00:00", | ||
}, | ||
{ | ||
"duration": 120, | ||
"end_value": "2023-09-14T16:00:00+00:00", | ||
"rrule": 180, | ||
"rrule_index": 2, | ||
"timezone": "America/Chicago", | ||
"value": "2023-09-14T14:00:00+00:00", | ||
}, | ||
], | ||
"description": "Pickleball ", | ||
"entityId": 52265, | ||
"entityPath": "/central-iowa-health-care/events/52265", | ||
"eventCTA": null, | ||
"facilityLocation": null, | ||
"id": "16349f16-be65-46e3-9660-1d3d598a4a0b", | ||
"image": null, | ||
"link": null, | ||
"listing": "/central-iowa-health-care/events", | ||
"locationHumanReadable": "Walker Johnston Park", | ||
"locationType": "non_facility", | ||
"metatags": null, | ||
"published": true, | ||
"socialLinks": { | ||
"path": "/central-iowa-health-care/events/52265", | ||
"title": "Pickleball Club", | ||
}, | ||
"title": "Pickleball Club", | ||
"type": "node--event", | ||
"urlOfOnlineEvent": null, | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { NodeEvent } from '@/types/dataTypes/drupal/node' | ||
import { queries } from '@/data/queries' | ||
import mockData from '@/mocks/event.mock.json' | ||
|
||
const nodeEventMock: NodeEvent = mockData | ||
|
||
describe('node--event formatData', () => { | ||
let windowSpy | ||
|
||
beforeEach(() => { | ||
windowSpy = jest.spyOn(window, 'window', 'get') | ||
}) | ||
|
||
afterEach(() => { | ||
windowSpy.mockRestore() | ||
}) | ||
|
||
test('outputs formatted data', () => { | ||
windowSpy.mockImplementation(() => undefined) | ||
const formattedData = queries.formatData('node--event', nodeEventMock) | ||
expect(formattedData).toMatchSnapshot() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.