Repository navigation
Expand file tree
/
Copy patheditor.spec.ts
More file actions
741 lines (595 loc) · 25 KB
/
Copy patheditor.spec.ts
File metadata and controls
741 lines (595 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
import { test, expect, type Page } from "playwright/test";
import { loggedInAsUserOne, articleContent } from "./utils";
// Test constants
const BASE_URL = process.env.E2E_BASE_URL || "http://localhost:3000";
const CREATE_URL = `${BASE_URL}/create`;
// Modifier key for keyboard shortcuts (Meta on Mac, Control on Windows/Linux)
const MOD_KEY = process.platform === "darwin" ? "Meta" : "Control";
// Selectors
//
// NOTE (post-relaunch): the editor no longer has Write/Link tabs. It opens
// straight into the article editor (title + TipTap body + tags + canonical +
// publish). Links are created from the compose modal, not here.
const SELECTORS = {
// Article editor
titleInput: 'input[placeholder="Article title"]',
editorContent: ".ProseMirror",
// Tags
tagInput: 'input[placeholder*="Add tags"], input[placeholder*="Add more"]',
// More Options
moreOptionsButton: 'button:has-text("More Options")',
excerptTextarea: "#excerpt",
canonicalUrlInput: "#canonicalUrl",
scheduleSwitch: "#schedule-switch",
datetimeInput: 'input[type="datetime-local"]',
// Actions
saveDraftButton: 'button:has-text("Save Draft")',
savedButton: 'button:has-text("Saved")',
publishButton: 'button:has-text("Publish")',
shareDraftButton: 'button:has-text("Share Draft")',
previewButton: 'button:has-text("Preview")',
editButton: 'button:has-text("Edit")',
// Modal buttons
letsDoThisButton: 'button:has-text("Let\'s do this!")',
maybeLaterButton: 'button:has-text("Maybe later")',
// Toolbar buttons
boldButton: 'button[title*="Bold"]',
italicButton: 'button[title*="Italic"]',
markdownModeButton: 'button:has-text("Switch to Markdown")',
switchToRichTextButton: 'button:has-text("Switch to Rich Text")',
};
// The TipTap body only mounts on the client, so its presence is the signal
// that the form has hydrated. Input typed before that point is discarded,
// which slower engines (WebKit on CI) hit when a test types straight away.
async function openEditor(page: Page) {
await page.goto(CREATE_URL);
await expect(page.locator(SELECTORS.editorContent)).toBeVisible({
timeout: 15000,
});
}
// ============================================
// UNAUTHENTICATED ACCESS TESTS
// ============================================
test.describe("Unauthenticated Editor Access", () => {
test("Should redirect to /get-started when accessing /create without auth", async ({
page,
}) => {
await page.goto(CREATE_URL);
await page.waitForURL(/.*get-started.*/);
expect(page.url()).toContain("get-started");
});
test("Should redirect from /create?tab=write without auth", async ({
page,
}) => {
await page.goto(`${CREATE_URL}?tab=write`);
await page.waitForURL(/.*get-started.*/);
expect(page.url()).toContain("get-started");
});
test("Should redirect from /create?tab=link without auth", async ({
page,
}) => {
await page.goto(`${CREATE_URL}?tab=link`);
await page.waitForURL(/.*get-started.*/);
expect(page.url()).toContain("get-started");
});
});
// ============================================
// ARTICLE EDITOR TESTS
// ============================================
test.describe("Article Editor", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test.describe("Basic Functionality", () => {
test("Should load the article editor by default", async ({ page }) => {
await openEditor(page);
// No tabs anymore — the editor opens straight into the article.
await expect(page.locator(SELECTORS.titleInput)).toBeVisible();
await expect(page.locator(SELECTORS.editorContent)).toBeVisible();
});
test("Should allow entering title text", async ({ page }) => {
await openEditor(page);
const title = "Test Article Title";
await page.locator(SELECTORS.titleInput).fill(title);
await expect(page.locator(SELECTORS.titleInput)).toHaveValue(title);
});
test("Should allow entering content in TipTap editor", async ({ page }) => {
await openEditor(page);
// Click into the editor and type
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("This is test content for the article.");
await expect(page.locator(SELECTORS.editorContent)).toContainText(
"This is test content",
);
});
});
test.describe("Toolbar Functionality", () => {
test("Should show toolbar with formatting buttons", async ({ page }) => {
await openEditor(page);
// Wait for toolbar to load
await page.waitForSelector(SELECTORS.editorContent);
// Check for common toolbar buttons - use more flexible selectors
await expect(
page
.locator('button[title*="Bold"], button[aria-label*="bold"]')
.first(),
).toBeVisible();
await expect(
page
.locator('button[title*="Italic"], button[aria-label*="italic"]')
.first(),
).toBeVisible();
});
test("Should apply bold formatting via keyboard shortcut", async ({
page,
isMobile,
}) => {
test.skip(isMobile, "Touch devices have no modifier-key shortcuts");
await openEditor(page);
// Type some text
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("bold text");
// Select all text using keyboard
await page.keyboard.press(`${MOD_KEY}+a`);
// Apply bold via keyboard shortcut
await page.keyboard.press(`${MOD_KEY}+b`);
// Check for bold formatting - TipTap uses <strong> tag
await expect(
page.locator(`${SELECTORS.editorContent} strong`),
).toBeVisible({
timeout: 5000,
});
});
test("Should apply italic formatting via keyboard shortcut", async ({
page,
isMobile,
}) => {
test.skip(isMobile, "Touch devices have no modifier-key shortcuts");
await openEditor(page);
// Type some text
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("italic text");
// Select all text using keyboard
await page.keyboard.press(`${MOD_KEY}+a`);
// Apply italic via keyboard shortcut
await page.keyboard.press(`${MOD_KEY}+i`);
// Check for italic formatting - TipTap uses <em> tag
await expect(page.locator(`${SELECTORS.editorContent} em`)).toBeVisible({
timeout: 5000,
});
});
});
test.describe("Markdown Mode", () => {
test("Should switch to markdown mode", async ({ page }) => {
await openEditor(page);
// Enter some content first
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("Some content");
// Click markdown mode button
await page.locator(SELECTORS.markdownModeButton).click();
// Should show switch to rich text button
await expect(
page.locator(SELECTORS.switchToRichTextButton),
).toBeVisible();
});
test("Should switch back to rich text mode", async ({ page }) => {
await openEditor(page);
// Enter content and switch to markdown
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("Test content");
await page.locator(SELECTORS.markdownModeButton).click();
// Switch back to rich text
await page.locator(SELECTORS.switchToRichTextButton).click();
// Should show the editor again
await expect(page.locator(SELECTORS.editorContent)).toBeVisible();
});
});
test.describe("Preview Mode", () => {
test("Should toggle to preview mode", async ({ page }) => {
await openEditor(page);
// Enter title and content
await page.locator(SELECTORS.titleInput).fill("Preview Test Title");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("Preview content here");
// Click preview button
await page.locator(SELECTORS.previewButton).click();
// Should show Edit button instead of Preview
await expect(page.locator(SELECTORS.editButton)).toBeVisible();
// Should display the title in preview
await expect(page.locator("h1")).toContainText("Preview Test Title");
});
test("Should return to edit mode from preview", async ({ page }) => {
await openEditor(page);
// Enter content and go to preview
await page.locator(SELECTORS.titleInput).fill("Test Title");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("Content");
await page.locator(SELECTORS.previewButton).click();
// Click Edit to return
await page.locator(SELECTORS.editButton).click();
// Should show the editor again
await expect(page.locator(SELECTORS.editorContent)).toBeVisible();
});
});
});
// ============================================
// TAGS INPUT TESTS
// ============================================
test.describe("Tags Input", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should show tags input section", async ({ page }) => {
await openEditor(page);
await expect(page.locator('text="Tags"')).toBeVisible();
await expect(page.locator(SELECTORS.tagInput)).toBeVisible();
});
test("Should add tag on Enter key", async ({ page }) => {
await openEditor(page);
// First click on the tag input area to focus it
await page.locator(SELECTORS.tagInput).first().fill("javascript");
await page.keyboard.press("Enter");
// Tag should be visible as a badge (lowercase)
await expect(page.locator('text="javascript"')).toBeVisible();
});
test("Should add tag on comma", async ({ page }) => {
await openEditor(page);
await page.locator(SELECTORS.tagInput).first().fill("react,");
// Tag should be visible (lowercase)
await expect(page.locator('text="react"')).toBeVisible();
});
test("Should remove tag with X button", async ({ page }) => {
await openEditor(page);
// Add a tag
await page.locator(SELECTORS.tagInput).first().fill("typescript");
await page.keyboard.press("Enter");
// Verify tag exists (lowercase)
await expect(page.locator('text="typescript"')).toBeVisible();
// Click the remove button on the tag (lowercase in aria-label)
await page.locator('button[aria-label="Remove typescript tag"]').click();
// Tag should be gone
await expect(page.locator('text="typescript"')).toBeHidden();
});
test("Should enforce max 5 tags limit", async ({ page }) => {
await openEditor(page);
// Add 5 tags
const tags = ["tag1", "tag2", "tag3", "tag4", "tag5"];
for (const tag of tags) {
await page.locator(SELECTORS.tagInput).first().fill(tag);
await page.keyboard.press("Enter");
// Wait for tag to be added
await expect(page.locator(`text="${tag}"`)).toBeVisible();
}
// Try to add a 6th tag - input should be hidden
await expect(page.locator('input[placeholder*="Add tags"]')).toBeHidden();
await expect(page.locator('input[placeholder*="Add more"]')).toBeHidden();
});
test("Should prevent duplicate tags", async ({ page }) => {
await openEditor(page);
// Add a tag twice
await page.locator(SELECTORS.tagInput).first().fill("duplicate");
await page.keyboard.press("Enter");
await expect(page.locator('text="duplicate"')).toBeVisible();
await page.locator(SELECTORS.tagInput).first().fill("duplicate");
await page.keyboard.press("Enter");
// Should only have one instance of the tag (lowercase)
const tagCount = await page.locator('span:has-text("duplicate")').count();
expect(tagCount).toBe(1);
});
});
// ============================================
// MORE OPTIONS ACCORDION TESTS
// ============================================
test.describe("More Options Accordion", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should show More Options button", async ({ page }) => {
await openEditor(page);
await expect(page.locator(SELECTORS.moreOptionsButton)).toBeVisible();
});
test("Should expand accordion on click", async ({ page }) => {
await openEditor(page);
// Click to expand
await page.locator(SELECTORS.moreOptionsButton).click();
// Excerpt field should be visible
await expect(page.locator(SELECTORS.excerptTextarea)).toBeVisible();
});
test("Should allow entering excerpt text", async ({ page }) => {
await openEditor(page);
await page.locator(SELECTORS.moreOptionsButton).click();
const excerptText = "This is a custom excerpt for the article.";
await page.locator(SELECTORS.excerptTextarea).fill(excerptText);
await expect(page.locator(SELECTORS.excerptTextarea)).toHaveValue(
excerptText,
);
});
test("Should allow entering canonical URL", async ({ page }) => {
await openEditor(page);
await page.locator(SELECTORS.moreOptionsButton).click();
const canonicalUrl = "https://mysite.com/original-post";
await page.locator(SELECTORS.canonicalUrlInput).fill(canonicalUrl);
await expect(page.locator(SELECTORS.canonicalUrlInput)).toHaveValue(
canonicalUrl,
);
});
test("Should not offer scheduling controls (moderator-only feature)", async ({
page,
}) => {
// User-facing scheduling was removed — only admin.moderatePost schedules.
// Guard against the toggle quietly returning to the editor.
await openEditor(page);
await page.locator(SELECTORS.moreOptionsButton).click();
await expect(page.locator(SELECTORS.canonicalUrlInput)).toBeVisible();
await expect(page.locator(SELECTORS.scheduleSwitch)).toHaveCount(0);
await expect(page.locator(SELECTORS.datetimeInput)).toHaveCount(0);
});
});
// ============================================
// PUBLISH BUTTON VALIDATION TESTS
// ============================================
test.describe("Publish Button Validation", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test.describe("Article Validation", () => {
test("Publish button should be disabled when title is empty", async ({
page,
}) => {
await openEditor(page);
// Add only body content (more than 10 chars)
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"This is some body content that is long enough for testing",
);
// Wait a moment for state to update
await page.waitForTimeout(500);
// Both nav and action bar Publish buttons should be disabled
const navPublishButton = page.locator('nav button:has-text("Publish")');
await expect(navPublishButton).toBeDisabled();
});
test("Publish button should be disabled when body is empty", async ({
page,
}) => {
await openEditor(page);
// Add only title (more than 5 chars)
await page.locator(SELECTORS.titleInput).fill("My Article Title Here");
// Wait a moment for state to update
await page.waitForTimeout(500);
// Nav Publish button should be disabled
const navPublishButton = page.locator('nav button:has-text("Publish")');
await expect(navPublishButton).toBeDisabled();
});
test("Publish button should be disabled when title is too short", async ({
page,
}) => {
await openEditor(page);
// Title less than 5 chars
await page.locator(SELECTORS.titleInput).fill("Hi");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"This is enough body content here for testing purposes",
);
// Wait a moment for state to update
await page.waitForTimeout(500);
// Nav Publish button should be disabled
const navPublishButton = page.locator('nav button:has-text("Publish")');
await expect(navPublishButton).toBeDisabled();
});
test("Publish button should be enabled when title and body are valid", async ({
page,
}) => {
await openEditor(page);
// Valid title (5+ chars)
await page.locator(SELECTORS.titleInput).fill("Valid Title Here");
// Valid body (10+ chars)
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"This is valid body content with more text for testing",
);
// Wait a moment for state to update
await page.waitForTimeout(500);
// Nav Publish button should be enabled
const navPublishButton = page.locator('nav button:has-text("Publish")');
await expect(navPublishButton).toBeEnabled();
});
});
});
// ============================================
// DRAFT MANAGEMENT TESTS
// ============================================
test.describe("Draft Management", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should show Save Draft button when content exists", async ({
page,
}) => {
await openEditor(page);
// Enter valid content
await page.locator(SELECTORS.titleInput).fill("Draft Article Title");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("This is draft body content here for testing");
// Wait for state to update
await page.waitForTimeout(500);
// Save Draft button should be visible in action bar
await expect(page.locator(SELECTORS.saveDraftButton)).toBeVisible();
});
test("Should show saved time indicator after auto-save", async ({ page }) => {
await openEditor(page);
// Enter valid content - title first
await page.locator(SELECTORS.titleInput).fill("Draft Article Title");
// Then body content - this triggers auto-save after debounce
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"This is draft body content for testing auto save indicator feature",
);
// Wait for auto-save to trigger and URL to update (debounce is 1500ms + save time)
await page.waitForURL(/.*create\/[a-z0-9]+/, { timeout: 20000 });
// Saved time should appear in nav after auto-save completes (look for timestamp format)
await expect(page.locator("nav").locator("text=/Saved .+\\d/")).toBeVisible(
{ timeout: 10000 },
);
});
test("Should show Share Draft button after auto-save", async ({ page }) => {
await openEditor(page);
// Enter valid content - title first
await page.locator(SELECTORS.titleInput).fill("Test Draft for Sharing");
// Then body content - this triggers auto-save after debounce
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"Content for testing share draft feature auto save test",
);
// Wait for auto-save to trigger and URL to update (debounce is 1500ms + save time)
await page.waitForURL(/.*create\/[a-z0-9]+/, { timeout: 20000 });
// Share Draft button should appear after save
await expect(page.locator(SELECTORS.shareDraftButton)).toBeVisible({
timeout: 10000,
});
});
test("Auto-save should update URL with post ID", async ({ page }) => {
await openEditor(page);
// Enter valid content that meets auto-save requirements
await page.locator(SELECTORS.titleInput).fill("Auto Save Test Title");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"Auto save content that is long enough to trigger save functionality",
);
// Wait for auto-save to trigger and URL to update (debounce is 1500ms)
await page.waitForURL(/.*create\/[a-z0-9]+/, { timeout: 20000 });
expect(page.url()).toMatch(/create\/[a-z0-9]+/);
});
});
// ============================================
// PUBLISH FLOW TESTS
// ============================================
test.describe("Publish Flow", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should show confirmation modal for article", async ({ page }) => {
await openEditor(page);
await page.waitForLoadState("domcontentloaded");
// Wait for title input to be visible
await expect(page.locator(SELECTORS.titleInput)).toBeVisible({
timeout: 15000,
});
// Enter valid content
await page.locator(SELECTORS.titleInput).fill("Article to Publish");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(articleContent);
// Wait for auto-save to complete before opening modal
await expect(page.locator("nav >> text=/Saved .*/")).toBeVisible({
timeout: 15000,
});
await page.waitForTimeout(300); // Allow state to settle
// Wait for Publish button to be enabled
const publishButton = page.locator('nav button:has-text("Publish")');
await expect(publishButton).toBeEnabled({ timeout: 10000 });
await publishButton.click();
// Modal should appear with whimsical content
await expect(page.locator('text="Ready to launch?"')).toBeVisible({
timeout: 5000,
});
await expect(page.locator(SELECTORS.letsDoThisButton)).toBeVisible();
await expect(page.locator(SELECTORS.maybeLaterButton)).toBeVisible();
});
test("Should close modal on 'Maybe later'", async ({ page }) => {
await openEditor(page);
// Enter valid content
await page.locator(SELECTORS.titleInput).fill("Test Modal Close");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(
"Content for modal close test with enough text for testing",
);
// Wait for auto-save to complete before opening modal
await expect(page.locator("nav >> text=/Saved .*/")).toBeVisible({
timeout: 15000,
});
await page.waitForTimeout(500);
// Wait for Publish button to be enabled, then open modal
const publishButton = page.locator('nav button:has-text("Publish")');
await expect(publishButton).toBeEnabled({ timeout: 10000 });
await publishButton.click();
await expect(page.locator('text="Ready to launch?"')).toBeVisible({
timeout: 5000,
});
// Wait for modal animation to settle, then click Maybe later
const maybeLaterBtn = page.locator(SELECTORS.maybeLaterButton);
await expect(maybeLaterBtn).toBeVisible({ timeout: 5000 });
await page.waitForTimeout(300); // Allow animation to settle
await maybeLaterBtn.click();
// Modal should close
await expect(page.locator('text="Ready to launch?"')).toBeHidden();
});
test("Should publish and redirect to article page", async ({ page }) => {
await openEditor(page);
// Enter valid content
const title = `E2E Publish Test ${Date.now()}`;
await page.locator(SELECTORS.titleInput).fill(title);
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type(articleContent);
// Wait for auto-save to complete before publishing (check nav "Saved" timestamp)
await expect(page.locator("nav >> text=/Saved .*/")).toBeVisible({
timeout: 15000,
});
await page.waitForTimeout(500);
// Publish
const publishButton = page.locator('nav button:has-text("Publish")');
await expect(publishButton).toBeEnabled({ timeout: 10000 });
await publishButton.click();
await expect(page.locator(SELECTORS.letsDoThisButton)).toBeVisible({
timeout: 5000,
});
await page.locator(SELECTORS.letsDoThisButton).click();
// After confirming, the editor redirects. The e2e env runs with the
// auto-moderation gate ON (MODERATION_ENABLED=true), so a freshly
// published draft is routed to `in_review` and the author is sent to
// their drafts ("Sent for review"). When the gate is OFF the post goes
// live and redirects to the published article. Accept either terminal
// state so the publish flow is exercised end-to-end regardless of env.
await page.waitForURL(
(url) =>
/\/e2e-test-user-one-111\/e2e-publish-test/.test(url.pathname) ||
url.pathname.startsWith("/my-posts"),
{ timeout: 20000 },
);
if (page.url().includes("/my-posts")) {
// Moderation gate ON — post went to review.
await expect(page).toHaveURL(/my-posts/);
} else {
// Moderation gate OFF — post is live, article heading is shown.
await expect(page.getByRole("heading", { name: title })).toBeVisible({
timeout: 10000,
});
}
});
});
// ============================================
// MOBILE RESPONSIVE TESTS
// ============================================
test.describe("Mobile Responsive Tests", () => {
test.beforeEach(async ({ page }) => {
await loggedInAsUserOne(page);
});
test("Should show editor on mobile viewport", async ({ page }) => {
// Set mobile viewport
await page.setViewportSize({ width: 375, height: 812 });
await openEditor(page);
// Editor should be visible
await expect(page.locator(SELECTORS.titleInput)).toBeVisible();
await expect(page.locator(SELECTORS.editorContent)).toBeVisible();
});
test("Publish button should be visible on mobile", async ({ page }) => {
await page.setViewportSize({ width: 375, height: 812 });
await openEditor(page);
// Enter content
await page.locator(SELECTORS.titleInput).fill("Mobile Test Title");
await page.locator(SELECTORS.editorContent).click();
await page.keyboard.type("Mobile test content here for testing purposes");
// Wait for state to update
await page.waitForTimeout(500);
// Publish button in nav should be visible
await expect(page.locator('nav button:has-text("Publish")')).toBeVisible();
});
});