-
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.
Merge branch 'main' into VACMS-16432-banner-updates
- Loading branch information
Showing
10 changed files
with
195 additions
and
16 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
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
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,55 @@ | ||
import { render, screen } from '@testing-library/react' | ||
import { PreviewCrumb, UnpublishedBanner } from './index' | ||
|
||
const resource = { | ||
published: false, | ||
moderationState: 'draft', | ||
entityPath: | ||
'/oklahoma-city-health-care/stories/el-reno-high-school-continues-78-year-tradition-of-giving-gifts-to-veterans', | ||
entityId: '500', | ||
} | ||
|
||
describe('Preview renders with accurate data', () => { | ||
test('renders PreviewCrumb component', () => { | ||
render(<PreviewCrumb entityId={resource.entityId} />) | ||
|
||
expect(screen.getByRole('link')).toHaveAttribute( | ||
'href', | ||
`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/node/500/edit` | ||
) | ||
}) | ||
|
||
test('UnpublishedBanner renders with draft content', () => { | ||
render(<UnpublishedBanner resource={resource} />) | ||
|
||
expect(screen.getByRole('link')).toHaveAttribute( | ||
'href', | ||
`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/node/500/edit` | ||
) | ||
}) | ||
|
||
test('UnpublishedBanner renders with archived content', () => { | ||
const modResource = { | ||
...resource, | ||
moderationState: 'archived', | ||
} | ||
render(<UnpublishedBanner resource={modResource} />) | ||
|
||
expect(screen.getByRole('link')).toHaveAttribute( | ||
'href', | ||
`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/node/500/edit` | ||
) | ||
}) | ||
|
||
test('UnpublishedBanner does not render with a published revision', () => { | ||
const modResource = { | ||
...resource, | ||
published: true, | ||
} | ||
render(<UnpublishedBanner resource={modResource} />) | ||
|
||
expect( | ||
screen.queryByText('You are viewing a draft revision') | ||
).not.toBeInTheDocument() | ||
}) | ||
}) |
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,53 @@ | ||
/* These two components appear when viewing a page through the /api/preview route | ||
* using the Drupal CMS preview. | ||
*/ | ||
|
||
// In preview mode, this appears just above the page's breadcrumbs. | ||
export const PreviewCrumb = ({ entityId }) => { | ||
return ( | ||
<div className="usa-grid-full"> | ||
<div className="usa-width-one-whole"> | ||
<div className="vads-u-margin-top--2"> | ||
<a | ||
data-same-tab="" | ||
href={`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/node/${entityId}/edit`} | ||
> | ||
« Edit this page in the CMS (requires a CMS account with appropriate | ||
permissions) | ||
</a> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
// In preview mode, this appears as a small banner at the very top of the page when viewing draft or archived revisions. | ||
export const UnpublishedBanner = ({ resource }) => { | ||
if (resource.published) return null | ||
|
||
let modState | ||
switch (resource.moderationState) { | ||
case 'archived': | ||
modState = 'an archived' | ||
break | ||
case 'draft': | ||
case 'review': | ||
default: | ||
modState = 'a draft' | ||
} | ||
|
||
return ( | ||
<div className="vads-u-background-color--primary-alt-lightest vads-u-padding--1"> | ||
<div className="vads-l-grid-container medium-screen:vads-u-padding-x--0"> | ||
You are viewing {modState} revision of {resource?.entityPath}. | ||
<a | ||
data-same-tab="" | ||
href={`${process.env.NEXT_PUBLIC_DRUPAL_BASE_URL}/node/${resource?.entityId}/edit`} | ||
style={{ display: 'block' }} | ||
> | ||
Edit this page in the CMS. | ||
</a> | ||
</div> | ||
</div> | ||
) | ||
} |
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,17 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { PreviewCrumb } from './index' | ||
|
||
const meta: Meta<typeof PreviewCrumb> = { | ||
title: 'Common/Preview', | ||
component: PreviewCrumb, | ||
} | ||
export default meta | ||
|
||
type Story = StoryObj<typeof PreviewCrumb> | ||
|
||
export const PreviewBreadcrumbLink: Story = { | ||
args: { | ||
entityId: 500, | ||
}, | ||
} |
35 changes: 35 additions & 0 deletions
35
src/templates/common/preview/unpublishedPreview.stories.ts
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,35 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { UnpublishedBanner } from './index' | ||
|
||
const meta: Meta<typeof UnpublishedBanner> = { | ||
title: 'Common/Preview', | ||
component: UnpublishedBanner, | ||
} | ||
export default meta | ||
|
||
type Story = StoryObj<typeof UnpublishedBanner> | ||
|
||
export const Draft: Story = { | ||
args: { | ||
resource: { | ||
published: false, | ||
moderationState: 'draft', | ||
entityPath: | ||
'/oklahoma-city-health-care/stories/el-reno-high-school-continues-78-year-tradition-of-giving-gifts-to-veterans', | ||
entityId: '500', | ||
}, | ||
}, | ||
} | ||
|
||
export const Archived: Story = { | ||
args: { | ||
resource: { | ||
published: false, | ||
moderationState: 'archived', | ||
entityPath: | ||
'/oklahoma-city-health-care/stories/el-reno-high-school-continues-78-year-tradition-of-giving-gifts-to-veterans', | ||
entityId: '500', | ||
}, | ||
}, | ||
} |
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