PluginProbe
Extendify / 3.1.0
Extendify v3.1.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / tests / playwright / HelpCenter / knowledge-base.spec.ts

knowledge-base.spec.ts in Extendify 3.1.0, at tests/playwright/HelpCenter/knowledge-base.spec.ts

106 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { expect, test } from '../fixtures';
2
3 const seededArticleTitles = [
4 'WordPress Block Editor',
5 'Blocks List',
6 'Adding a New Block',
7 'Block Pattern',
8 'Block Pattern Directory',
9 ];
10
11 const addingBlockArticle = {
12 slug: 'adding-a-new-block',
13 title: 'Adding a New Block',
14 content: '<p>How to add a new block to your post or page.</p>',
15 };
16
17 const codeBlockArticle = {
18 slug: 'code-block',
19 title: 'Code Block Article',
20 content: '<p>The Code block lets you display formatted code snippets.</p>',
21 };
22
23 const codeBlockSearchHit = {
24 id: 50,
25 cats: ['blocks'],
26 slug: 'code-block',
27 title: codeBlockArticle.title,
28 summary: 'A summary of the Code block article.',
29 };
30
31 test.beforeEach(async ({ admin, page, requestUtils }) => {
32 await requestUtils.login();
33
34 // Boot ping on focus, search POST per setSearchTerm ≥ 3 chars, single-
35 // article GET on article mount. Globs would alias the `?` — use regex.
36 await page.route(/\/api\/posts\?boot=true/, (route) =>
37 route.fulfill({ status: 200, json: {} }),
38 );
39 await page.route(/\/api\/posts\?.*search=/, (route) =>
40 route.fulfill({ status: 200, json: [codeBlockSearchHit] }),
41 );
42 await page.route(/\/api\/posts\/adding-a-new-block/, (route) =>
43 route.fulfill({ status: 200, json: addingBlockArticle }),
44 );
45 await page.route(/\/api\/posts\/code-block/, (route) =>
46 route.fulfill({ status: 200, json: codeBlockArticle }),
47 );
48
49 await admin.visitAdminPage('index.php');
50 await page.getByTestId('help-center-adminbar-button').click();
51 });
52
53 test('KB section and articles list render on the dashboard', async ({
54 page,
55 }) => {
56 await expect(page.getByTestId('help-center-kb-section')).toBeAttached();
57 await expect(
58 page.getByTestId('help-center-kb-articles-list').locator('li'),
59 ).toHaveCount(seededArticleTitles.length);
60 });
61
62 test('Clicking an article opens the article page with the fetched content', async ({
63 page,
64 }) => {
65 const fetched = page.waitForResponse(/\/api\/posts\/adding-a-new-block/);
66 await page
67 .getByTestId('help-center-kb-articles-list')
68 .locator('li')
69 .filter({ hasText: addingBlockArticle.title })
70 .first()
71 .locator('button')
72 .click();
73 await fetched;
74
75 await expect(page.getByTestId('kb-article-content')).toContainText(
76 addingBlockArticle.title,
77 );
78 });
79
80 test('Search returns results that open into an article', async ({ page }) => {
81 const searchInput = page.locator('#ext-help-center-search');
82
83 // `fill('code block')` on the dashboard's SearchForm fires one onChange
84 // that both stores the term and navigates to the full KB page; the KB
85 // page's useSearchArticles issues the POST on mount. The boot ping fires
86 // on HC modal mount (i.e. during beforeEach), so we can't wait for it
87 // here — `searched` is the next request the user-driven flow produces.
88 const searched = page.waitForResponse(/\/api\/posts\?.*search=/);
89 await searchInput.fill('code block');
90 await searched;
91
92 const fetched = page.waitForResponse(/\/api\/posts\/code-block/);
93 await page
94 .getByTestId('help-center-kb-articles-list')
95 .locator('li')
96 .filter({ hasText: codeBlockArticle.title })
97 .first()
98 .locator('button')
99 .click();
100 await fetched;
101
102 await expect(page.getByTestId('kb-article-content')).toContainText(
103 codeBlockArticle.title,
104 );
105 });
106