docsify/test/e2e/sidebar.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

72 lines
2.0 KiB
JavaScript

const docsifyInit = require('../helpers/docsify-init');
const { test, expect } = require('./fixtures/docsify-init-fixture');
// Suite
// -----------------------------------------------------------------------------
test.describe('Sidebar Tests', () => {
// Tests
// ---------------------------------------------------------------------------
test('Active Test', async ({ page }) => {
const docsifyInitConfig = {
markdown: {
sidebar: `
- [Test Space](test%20space)
- [Test _](test_foo)
- [Test -](test-foo)
- [Test .](test.foo)
- [Test >](test>foo)
- [Test](test)
`,
},
routes: {
'/test space.md': `
# Test Space
`,
'/test_foo.md': `
# Test _
`,
'/test-foo.md': `
# Test -
`,
'/test.foo.md': `
# Test .
`,
'/test>foo.md': `
# Test >
`,
'/test.md': `
# Test page
`,
},
};
const activeLinkElm = page.locator('.sidebar-nav li[class=active]');
await docsifyInit(docsifyInitConfig);
await page.click('a[href="#/test%20space"]');
await expect(activeLinkElm).toHaveText('Test Space');
expect(page.url()).toMatch(/\/test%20space$/);
await page.click('a[href="#/test_foo"]');
await expect(activeLinkElm).toHaveText('Test _');
expect(page.url()).toMatch(/\/test_foo$/);
await page.click('a[href="#/test-foo"]');
await expect(activeLinkElm).toHaveText('Test -');
expect(page.url()).toMatch(/\/test-foo$/);
await page.click('a[href="#/test.foo"]');
expect(page.url()).toMatch(/\/test.foo$/);
await expect(activeLinkElm).toHaveText('Test .');
await page.click('a[href="#/test>foo"]');
await expect(activeLinkElm).toHaveText('Test >');
expect(page.url()).toMatch(/\/test%3Efoo$/);
await page.click('a[href="#/test"]');
await expect(activeLinkElm).toHaveText('Test');
expect(page.url()).toMatch(/\/test$/);
});
});