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

fix(plugin-api-docgen): search index should include generated API doc #1716

Merged
merged 3 commits into from
Dec 27, 2024
Merged
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
7 changes: 7 additions & 0 deletions e2e/tests/api-docgen.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { expect, test } from '@playwright/test';
import path from 'node:path';
import { getPort, killProcess, runDevCommand } from '../utils/runCommands';
import { searchInPage } from '../utils/search';

const fixtureDir = path.resolve(__dirname, '../fixtures');

Expand Down Expand Up @@ -47,4 +48,10 @@ test.describe('api-docgen test', async () => {
expect(tableContent).toContain('-');
expect(tableContent).toContain("'default'");
});

test('search index should include api-docgen result', async ({ page }) => {
await page.goto(`http://localhost:${appPort}`);
const suggestItems = await searchInPage(page, 'disabled');
expect(suggestItems.length).toBe(1);
});
});
26 changes: 26 additions & 0 deletions e2e/utils/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { Page } from '@playwright/test';
import assert from 'node:assert';

async function getSearchButton(page: Page) {
const searchButton = await page.$('.rspress-nav-search-button');
return searchButton;
}

/**
* @returns suggestItems domList
*/
export async function searchInPage(page: Page, searchText: string) {
const searchButton = await getSearchButton(page);
assert(searchButton);

await searchButton.click();

const searchInput = await page.$('.rspress-search-panel-input');
assert(searchInput);
const isEditable = await searchInput.isEditable();
assert(isEditable);
await searchInput.focus();
await page.keyboard.type(searchText);
await page.waitForTimeout(500);
return await page.$$('.rspress-search-suggest-item');
}
5 changes: 3 additions & 2 deletions packages/plugin-api-docgen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ export function pluginApiDocgen(options?: PluginOptions): RspressPlugin {
return;
}
while (matchResult !== null) {
const [matchContent, moduleName] = matchResult;
const matchContent = matchResult[0];
const moduleName = matchResult[2] ?? matchResult[5] ?? '';
const apiDoc =
apiDocMap[moduleName] || apiDocMap[`${moduleName}-${lang}`];
apiDocMap[moduleName] ?? apiDocMap[`${moduleName}-${lang}`] ?? '';
content = content.replace(matchContent, apiDoc);
matchResult = new RegExp(apiCompRegExp).exec(content);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/theme-default/src/components/Search/SearchPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,10 +468,10 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
<SvgWrapper icon={SearchSvg} />
</label>
<input
className={styles.input}
className={`rspress-search-panel-input ${styles.input}`}
ref={searchInputRef}
placeholder={searchPlaceholderText}
aria-label="Search"
aria-label="SearchPanelInput"
autoComplete="off"
autoFocus
onChange={e => handleQueryChange(e.target.value)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function SuggestItem({
return (
<li
key={suggestion.link}
className={`${styles.suggestItem} ${isCurrent ? styles.current : ''}`}
className={`rspress-search-suggest-item ${styles.suggestItem} ${isCurrent ? styles.current : ''}`}
onMouseEnter={setCurrentSuggestionIndex}
onMouseMove={onMouseMove}
ref={selfRef}
Expand Down
Loading