|
7 | 7 |
|
8 | 8 | import { test, expect, type Page } from "@playwright/test"; |
9 | 9 | import path from "path"; |
| 10 | +import { mockAppApis } from "@app/tests/helpers/api-stubs"; |
10 | 11 |
|
11 | 12 | const FIXTURES_DIR = path.join(__dirname, "../test-fixtures"); |
12 | 13 | const SAMPLE_PDF = path.join(FIXTURES_DIR, "sample.pdf"); |
13 | 14 |
|
14 | | -// --------------------------------------------------------------------------- |
15 | | -// Endpoint availability map — all conversion endpoints enabled |
16 | | -// --------------------------------------------------------------------------- |
17 | | -const MOCK_ENDPOINTS_AVAILABILITY = Object.fromEntries( |
18 | | - [ |
19 | | - "pdf-to-img", |
20 | | - "img-to-pdf", |
21 | | - "pdf-to-word", |
22 | | - "file-to-pdf", |
23 | | - "pdf-to-text", |
24 | | - "pdf-to-html", |
25 | | - "pdf-to-xml", |
26 | | - "pdf-to-csv", |
27 | | - "pdf-to-xlsx", |
28 | | - "pdf-to-pdfa", |
29 | | - "pdf-to-pdfx", |
30 | | - "pdf-to-presentation", |
31 | | - "pdf-to-markdown", |
32 | | - "pdf-to-cbz", |
33 | | - "pdf-to-cbr", |
34 | | - "pdf-to-epub", |
35 | | - "html-to-pdf", |
36 | | - "svg-to-pdf", |
37 | | - "markdown-to-pdf", |
38 | | - "eml-to-pdf", |
39 | | - "cbz-to-pdf", |
40 | | - "cbr-to-pdf", |
41 | | - ].map((k) => [k, { enabled: true }]), |
42 | | -); |
43 | | - |
44 | | -// --------------------------------------------------------------------------- |
45 | | -// Helper: mock all standard app APIs needed to load the main UI |
46 | | -// --------------------------------------------------------------------------- |
47 | | -async function mockAppApis(page: Page) { |
48 | | - // Backend probe — must return UP so Landing shows app in anonymous mode |
49 | | - await page.route("**/api/v1/info/status", (route) => |
50 | | - route.fulfill({ json: { status: "UP" } }), |
51 | | - ); |
52 | | - |
53 | | - // App config — enableLogin:false puts the app in anonymous mode |
54 | | - await page.route("**/api/v1/config/app-config", (route) => |
55 | | - route.fulfill({ |
56 | | - json: { |
57 | | - enableLogin: false, |
58 | | - languages: ["en-GB"], |
59 | | - defaultLocale: "en-GB", |
60 | | - }, |
61 | | - }), |
62 | | - ); |
63 | | - |
64 | | - // Auth — fallback if anything calls auth/me |
65 | | - await page.route("**/api/v1/auth/me", (route) => |
66 | | - route.fulfill({ |
67 | | - json: { |
68 | | - id: 1, |
69 | | - username: "testuser", |
70 | | - email: "test@example.com", |
71 | | - roles: ["ROLE_USER"], |
72 | | - }, |
73 | | - }), |
74 | | - ); |
75 | | - |
76 | | - // Endpoint availability — queried by ConvertSettings |
77 | | - await page.route("**/api/v1/config/endpoints-availability", (route) => |
78 | | - route.fulfill({ json: MOCK_ENDPOINTS_AVAILABILITY }), |
79 | | - ); |
80 | | - |
81 | | - // Single-endpoint check — queried by Convert.tsx for the execute button |
82 | | - await page.route("**/api/v1/config/endpoint-enabled*", (route) => |
83 | | - route.fulfill({ json: true }), |
84 | | - ); |
85 | | - |
86 | | - // Group-enabled check |
87 | | - await page.route("**/api/v1/config/group-enabled*", (route) => |
88 | | - route.fulfill({ json: true }), |
89 | | - ); |
90 | | - |
91 | | - // Footer info — non-critical |
92 | | - await page.route("**/api/v1/ui-data/footer-info", (route) => |
93 | | - route.fulfill({ json: {} }), |
94 | | - ); |
95 | | - |
96 | | - // Proprietary endpoints — silence proxy errors in the Vite dev server |
97 | | - await page.route("**/api/v1/proprietary/**", (route) => |
98 | | - route.fulfill({ json: {} }), |
99 | | - ); |
100 | | -} |
101 | | - |
102 | 15 | // --------------------------------------------------------------------------- |
103 | 16 | // Helper: dismiss the tour tooltip that can intercept clicks on firefox/webkit |
104 | 17 | // --------------------------------------------------------------------------- |
|
0 commit comments