Skip to content

Commit 886f0b1

Browse files
committed
Tests: Add collaboration server tests and remove legacy sync tests
Adds 67 PHPUnit tests for WP_HTTP_Polling_Collaboration_Server covering document sync, awareness, undo/redo, compaction, permissions, cursor mechanics, race conditions, cron cleanup, and the backward-compatible wp-sync/v1 route. Adds E2E tests for 3-user presence, sync, and undo/redo. Removes the old sync server tests. Updates REST schema setup and fixtures for the new collaboration endpoints.
1 parent b06269e commit 886f0b1

9 files changed

Lines changed: 3028 additions & 892 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/**
2+
* Tests for collaborative editing presence (awareness).
3+
*
4+
* Verifies that collaborator avatars, names, and leave events
5+
* propagate correctly between three concurrent users.
6+
*
7+
* @package WordPress
8+
* @since 7.0.0
9+
*/
10+
11+
/**
12+
* Internal dependencies
13+
*/
14+
import { test, expect, SYNC_TIMEOUT } from './fixtures';
15+
16+
test.describe( 'Collaboration - Presence', () => {
17+
test( 'All 3 collaborator avatars are visible', async ( {
18+
collaborationUtils,
19+
page,
20+
} ) => {
21+
await collaborationUtils.createCollaborativePost( {
22+
title: 'Presence Test - 3 Users',
23+
} );
24+
25+
const { page2, page3 } = collaborationUtils;
26+
27+
// Each user sees the collaborators list button (indicates others are present).
28+
await expect(
29+
page.getByRole( 'button', { name: /Collaborators list/ } )
30+
).toBeVisible( { timeout: SYNC_TIMEOUT } );
31+
32+
await expect(
33+
page2.getByRole( 'button', { name: /Collaborators list/ } )
34+
).toBeVisible( { timeout: SYNC_TIMEOUT } );
35+
36+
await expect(
37+
page3.getByRole( 'button', { name: /Collaborators list/ } )
38+
).toBeVisible( { timeout: SYNC_TIMEOUT } );
39+
} );
40+
41+
test( 'Collaborator names appear in popover', async ( {
42+
collaborationUtils,
43+
page,
44+
} ) => {
45+
await collaborationUtils.createCollaborativePost( {
46+
title: 'Presence Test - Names',
47+
} );
48+
49+
// User A opens the collaborators popover.
50+
const presenceButton = page.getByRole( 'button', {
51+
name: /Collaborators list/,
52+
} );
53+
await expect( presenceButton ).toBeVisible( {
54+
timeout: SYNC_TIMEOUT,
55+
} );
56+
await presenceButton.click();
57+
58+
// The popover should list both collaborators by name.
59+
// Use the presence list item class to avoid matching snackbar toasts.
60+
await expect(
61+
page.locator( '.editor-collaborators-presence__list-item-name', { hasText: 'Test Collaborator' } )
62+
).toBeVisible();
63+
64+
await expect(
65+
page.locator( '.editor-collaborators-presence__list-item-name', { hasText: 'Another Collaborator' } )
66+
).toBeVisible();
67+
} );
68+
69+
test( 'User C leaves, A and B see updated presence', async ( {
70+
collaborationUtils,
71+
page,
72+
} ) => {
73+
await collaborationUtils.createCollaborativePost( {
74+
title: 'Presence Test - Leave',
75+
} );
76+
77+
// Verify all 3 users see the collaborators button initially.
78+
await expect(
79+
page.getByRole( 'button', { name: /Collaborators list/ } )
80+
).toBeVisible( { timeout: SYNC_TIMEOUT } );
81+
82+
// Navigate User C away from the editor to stop their polling.
83+
// Avoids closing the context directly which corrupts Playwright state.
84+
await collaborationUtils.page3.goto( '/wp-admin/' );
85+
86+
// Wait for User C's awareness entry to expire on the server (30s timeout)
87+
// by watching the button label drop from 3 to 2 collaborators.
88+
const presenceButton = page.getByRole( 'button', {
89+
name: /Collaborators list/,
90+
} );
91+
await expect( presenceButton ).toHaveAccessibleName(
92+
/2 online/,
93+
{ timeout: 45000 }
94+
);
95+
96+
// Open the popover once, then verify the list contents.
97+
await presenceButton.click();
98+
99+
// "Another Collaborator" (User C) should no longer appear in the presence list.
100+
await expect(
101+
page.locator( '.editor-collaborators-presence__list-item-name', { hasText: 'Another Collaborator' } )
102+
).not.toBeVisible();
103+
104+
// "Test Collaborator" (User B) should still be listed.
105+
await expect(
106+
page.locator( '.editor-collaborators-presence__list-item-name', { hasText: 'Test Collaborator' } )
107+
).toBeVisible();
108+
} );
109+
} );

0 commit comments

Comments
 (0)