docsify/test/e2e/search.test.js
John Hildenbiddle c49c39a4a2
refactor: Update test environments and lint configuration (#1736)
* Update test environments and lint configuration

Update Jest (unit + integration) and Playwright (e2e) test environments. Includes stability improvements for e2e tests using newer, more stable methods per the Playwright docs.

- Update Jest 26 => 27
- Update Jest-related libs (babel parser)
- Update Playwright 1.8 => Playwright Test 1.18
- Update GitHub CI (action versions, job parallelization, and matrices)
- Update ESLint 5 => 8
- Update ESLint-related libs (parser, prettier, Jest, Playwright)
- Fix test failures on M1-based Macs
- Fix e2e stability issues by replacing PW $ method calls
- Fix ESLint errors
- Fix incorrect CI flag on Jest runs (-ci => --ci)
- Refactor e2e test runner from Jest to Playwright Test
- Refactor e2e test files for Playwright Test
- Refactor fix-lint script name to lint:fix for consistency
- Refactor npm scripts order for readability
- Remove unnecessary configs and libs
- Remove example image snapshots
2022-01-30 21:40:21 -06:00

180 lines
5.2 KiB
JavaScript

const docsifyInit = require('../helpers/docsify-init');
const { test, expect } = require('./fixtures/docsify-init-fixture');
test.describe('Search Plugin Tests', () => {
test('search readme', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
This is the homepage.
`,
sidebar: `
- [Test Page](test)
`,
},
routes: {
'/test.md': `
# Test Page
This is a custom route.
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Hello World');
await page.click('.clear-button');
await searchFieldElm.fill('test');
await expect(resultsHeadingElm).toHaveText('Test Page');
});
test('search ignore title', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Hello World
This is the homepage.
`,
sidebar: `
- [Home page](/)
- [GitHub Pages](github)
`,
},
routes: {
'/github.md': `
# GitHub Pages
This is the GitHub Pages.
## GitHub Pages ignore1 <!-- {docsify-ignore} -->
There're three places to populate your docs for your Github repository1.
## GitHub Pages ignore2 {docsify-ignore}
There're three places to populate your docs for your Github repository2.
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('repository1');
await expect(resultsHeadingElm).toHaveText('GitHub Pages ignore1');
await page.click('.clear-button');
await searchFieldElm.fill('repository2');
await expect(resultsHeadingElm).toHaveText('GitHub Pages ignore2');
});
test('search only one homepage', async ({ page }) => {
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'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
const resultElm = page.locator('.matching-post');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('hello');
await expect(resultElm).toHaveCount(1);
await expect(resultsHeadingElm).toHaveText('Hello World');
await page.click('.clear-button');
await searchFieldElm.fill('test');
await expect(resultsHeadingElm).toHaveText('Test Page');
});
test('search ignore diacritical marks', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
# Qué es
docsify genera su sitio web de documentación sobre la marcha. A diferencia de GitBook, no genera archivos estáticos html. En cambio, carga y analiza de forma inteligente sus archivos de Markdown y los muestra como sitio web. Todo lo que necesita hacer es crear un index.html para comenzar y desplegarlo en GitHub Pages.
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('documentacion');
await expect(resultsHeadingElm).toHaveText('Que es');
await page.click('.clear-button');
await searchFieldElm.fill('estáticos');
await expect(resultsHeadingElm).toHaveText('Que es');
});
test('search when there is no title', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
homepage: `
This is some description. We assume autoHeader added the # Title. A long paragraph.
`,
sidebar: `
- [Changelog](changelog)
`,
},
routes: {
'/changelog.md': `
feat: Support search when there is no title
## Changelog Title
hello, this is a changelog
`,
},
scriptURLs: ['/lib/plugins/search.min.js'],
};
const searchFieldElm = page.locator('input[type=search]');
const resultsHeadingElm = page.locator('.results-panel h2');
await docsifyInit(docsifyInitConfig);
await searchFieldElm.fill('paragraph');
await expect(resultsHeadingElm).toHaveText('Home Page');
await page.click('.clear-button');
await searchFieldElm.fill('Support');
await expect(resultsHeadingElm).toHaveText('changelog');
await page.click('.clear-button');
await searchFieldElm.fill('hello');
await expect(resultsHeadingElm).toHaveText('Changelog Title');
});
});