fix: duplicate search content when /README or / exists in the sidebar (#1403)

* fix: duplicate search content when `/readme` or `/` exists in the sidebar

* Update

* add test

* Reset local storage before each e2e test

* Reset Playwright context instead of page

* Update playwright dependencies

Co-authored-by: John Hildenbiddle <john@hildenbiddle.com>
This commit is contained in:
沈唁 2020-11-28 16:35:43 +08:00 committed by GitHub
parent bd662c421a
commit 7c3bf98df8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 1045 additions and 120 deletions

1117
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -85,13 +85,13 @@
"husky": "^3.1.0",
"jest": "^26.4.2",
"jest-image-snapshot": "^4.2.0",
"jest-playwright-preset": "^1.3.1",
"jest-playwright-preset": "^1.4.1",
"lerna": "^3.22.1",
"lint-staged": "^10.4.0",
"live-server": "^1.2.1",
"mkdirp": "^0.5.1",
"npm-run-all": "^4.1.5",
"playwright": "^1.4.1",
"playwright": "^1.6.2",
"prettier": "^1.19.1",
"rimraf": "^3.0.0",
"rollup": "^1.23.1",

View File

@ -236,8 +236,12 @@ export function init(config, vm) {
namespaceSuffix = matches[0];
}
}
paths.unshift(namespaceSuffix + '/');
} else {
const isExistHome = paths.indexOf(namespaceSuffix + '/') === -1;
const isExistReadme = paths.indexOf(namespaceSuffix + '/README') === -1;
if (isExistHome && isExistReadme) {
paths.unshift(namespaceSuffix + '/');
}
} else if (paths.indexOf('/') === -1 && paths.indexOf('/README') === -1) {
paths.unshift('/');
}

View File

@ -41,7 +41,7 @@ beforeAll(async () => {
});
beforeEach(async () => {
await global.jestPlaywright.resetPage();
await global.jestPlaywright.resetContext();
// Goto URL ()
// https://playwright.dev/#path=docs%2Fapi.md&q=pagegotourl-options

View File

@ -14,7 +14,6 @@ describe('Search Plugin Tests', function() {
This is the homepage.
`,
sidebar: `
- [Home page](/)
- [Test Page](test)
`,
},
@ -73,4 +72,37 @@ describe('Search Plugin Tests', function() {
await page.fill('input[type=search]', 'repository2');
await expect(page).toEqualText('.results-panel h2', 'GitHub Pages ignore2');
});
test('search only one homepage', async () => {
const docsifyInitConfig = {
markdown: {
sidebar: `
- [README](README)
- [Test Page](test)
`,
},
routes: {
'/README.md': `
# Hello World
This is the homepage.
`,
'/test.md': `
# Test Page
This is a custom route.
`,
},
scriptURLs: ['/lib/plugins/search.js'],
};
await docsifyInit(docsifyInitConfig);
await page.fill('input[type=search]', 'hello');
await expect(page).toHaveSelector('.matching-post');
expect(await page.$$eval('.matching-post', elms => elms.length)).toBe(1);
await expect(page).toEqualText('.results-panel h2', 'Hello World');
await page.click('.clear-button');
await page.fill('input[type=search]', 'test');
await expect(page).toEqualText('.results-panel h2', 'Test Page');
});
});