diff --git a/packages/lexical-playground/__tests__/e2e/Collaboration.spec.mjs b/packages/lexical-playground/__tests__/e2e/Collaboration.spec.mjs index 762ee82e94e..df5414b355f 100644 --- a/packages/lexical-playground/__tests__/e2e/Collaboration.spec.mjs +++ b/packages/lexical-playground/__tests__/e2e/Collaboration.spec.mjs @@ -230,4 +230,92 @@ test.describe('Collaboration', () => { focusPath: [1, 1, 0], }); }); + + test('Undo with two collaborators editing same paragraph', async ({ + isRichText, + page, + isCollab, + browserName, + }) => { + // test.skip(!isCollab || IS_MAC); + test.skip(!isCollab); + + // Left collaborator types two paragraphs of text + await focusEditor(page); + await page.keyboard.type('Line 1'); + await page.keyboard.press('Enter'); + await sleep(1050); // default merge interval is 1000, add 50ms as overhead due to CI latency. + await page.keyboard.type('This is a test. '); + + // Right collaborator types at the end of paragraph 2 + await sleep(1050); + await page + .frameLocator('iframe[name="right"]') + .locator('[data-lexical-editor="true"]') + .focus(); + await page.keyboard.press('ArrowDown'); // Move caret to end of paragraph 2 + await page.keyboard.press('ArrowDown'); + await page.keyboard.type('Word'); + + await assertHTML( + page, + html` +

+ Line 1 +

+

+ This is a test. Word +

+ `, + ); + + // Left collaborator undoes their second paragraph + await sleep(1050); + await page.frameLocator('iframe[name="left"]').getByLabel('Undo').click(); + + // Only left collaborator's text should have been undone + await assertHTML( + page, + html` +

+ Line 1 +

+

+ Word +

+ `, + ); + + // Left collaborator refreshes their page + await page.evaluate(() => { + document + .querySelector('iframe[name="left"]') + .contentDocument.location.reload(); + }); + + // Page content should be the same as before the refresh + await assertHTML( + page, + html` +

+ Line 1 +

+

+ Word +

+ `, + ); + }); });