-
Notifications
You must be signed in to change notification settings - Fork 111
chore: route manage subpages through a single module #529
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e86d30c
fix: highlight the snippets tab on the default manage view
lightbulbman 8b23bc8
chore: route manage subpages through a single edition-specific module
lightbulbman f9a3871
chore: localize the ai agent demo data independently of the table view
lightbulbman 6429dbf
test: cover the toolbar highlight for the default and unknown subpages
lightbulbman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,41 @@ | ||
| import { AiAgentDemo } from './AiAgentDemo/AiAgentDemo' | ||
| import { BlueprintsDemo } from './BlueprintsDemo/BlueprintsDemo' | ||
| import { CloudLibraryDemo } from './CloudLibraryDemo/CloudLibraryDemo' | ||
| import { CommunityCloud } from './CommunityCloud/CommunityCloud' | ||
| import { SnippetsTable } from './SnippetsTable' | ||
| import type React from 'react' | ||
|
|
||
| export const SUBPAGES = ['snippets', 'blueprints', 'cloud-community', 'cloud-library', 'ai-agent'] as const | ||
|
|
||
| export type SubpageName = typeof SUBPAGES[number] | ||
|
|
||
| export interface Subpage { | ||
| Component: React.FC | ||
|
|
||
| /** | ||
| * Marks a walkthrough tab. An 'announce' tab advertises itself as new until | ||
| * its walkthrough has been watched, which only a tab with a recorded demo | ||
| * can do; a 'quiet' tab is only ever labelled as a demo. | ||
| */ | ||
| demo?: 'announce' | 'quiet' | ||
|
|
||
| /** | ||
| * Marks a premium tab, which is chipped as such without a licence. | ||
| */ | ||
| isPro?: boolean | ||
| } | ||
|
|
||
| /** | ||
| * What each subpage of the manage screen renders, and how its toolbar tab | ||
| * advertises itself. | ||
| * | ||
| * The toolbar and the page body read the same entry, so a subpage is described | ||
| * once here rather than being kept in step across the two. | ||
| */ | ||
| export const SUBPAGE_ENTRIES: Record<SubpageName, Subpage> = { | ||
| 'snippets': { Component: SnippetsTable }, | ||
| 'blueprints': { Component: BlueprintsDemo, demo: 'announce' }, | ||
| 'cloud-community': { Component: CommunityCloud }, | ||
| 'cloud-library': { Component: CloudLibraryDemo, demo: 'quiet' }, | ||
| 'ai-agent': { Component: AiAgentDemo, demo: 'announce' }, | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,38 @@ | ||
| import { expect, test } from '@playwright/test' | ||
| import type { Page } from '@playwright/test' | ||
|
|
||
| const MANAGE_URL = '/wp-admin/admin.php?page=snippets' | ||
|
|
||
| // The manage screen resolves an absent or unrecognised `subpage` to the first | ||
| // subpage, so the toolbar must highlight whichever subpage actually rendered. | ||
| // Each case names a landmark of the body it expects, so a highlight that | ||
| // disagrees with the rendered page fails rather than passing on the query alone. | ||
| const CASES = [ | ||
| { name: 'no subpage parameter', query: '', active: 'snippets', body: '.wp-list-table' }, | ||
| { name: 'an unrecognised subpage', query: '&subpage=not-a-subpage', active: 'snippets', body: '.wp-list-table' }, | ||
| { name: 'a named subpage', query: '&subpage=cloud-community', active: 'cloud-community', body: '.community-cloud-nav' }, | ||
| ] | ||
|
|
||
| // The Settings tab is highlighted by its own page slug rather than a subpage, | ||
| // so it is excluded here. | ||
| const activeSubpageLinks = (page: Page) => | ||
| page.locator('.code-snippets-toolbar-lower a.active-link:not(.settings-link)') | ||
|
|
||
| test.describe('Toolbar active subpage', () => { | ||
| for (const { name, query, active, body } of CASES) { | ||
| test(`the highlighted tab matches the rendered page with ${name}`, async ({ page }) => { | ||
| await page.goto(`${MANAGE_URL}${query}`) | ||
| await expect(page.locator(body)).toBeVisible() | ||
|
|
||
| await expect(activeSubpageLinks(page)).toHaveCount(1) | ||
| await expect(activeSubpageLinks(page)).toHaveClass(new RegExp(`(^|\\s)${active}-link(\\s|$)`)) | ||
| }) | ||
| } | ||
|
|
||
| test('no lower-nav tab is highlighted away from the manage screen', async ({ page }) => { | ||
| await page.goto('/wp-admin/admin.php?page=snippets-settings') | ||
|
|
||
| await expect(page.locator('.code-snippets-toolbar-lower')).toBeVisible() | ||
| await expect(activeSubpageLinks(page)).toHaveCount(0) | ||
| }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.