Skip to content

Commit

Permalink
Update test for server invalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
bosschaert committed Apr 19, 2024
1 parent e940e8e commit e874749
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
14 changes: 7 additions & 7 deletions blocks/edit/prose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,11 @@ export function createAwarenessStatusWidget(wsProvider, win) {
return daTitle;
}

export function handleYDocUpdates({
daTitle, editor, ydoc, path, schema, wsProvider, yXmlFragment, fnInitProse,
}, win = window, fnSetAEMDocInEditor = setAEMDocInEditor) {
export function handleYDocUpdates(
{ ydoc, schema, wsProvider, yXmlFragment },
win = window,
fnSetAEMDocInEditor = setAEMDocInEditor,
) {
let firstUpdate = true;
ydoc.on('update', (_, originWS) => {
if (firstUpdate) {
Expand Down Expand Up @@ -203,12 +205,10 @@ export default function initProse({ editor, path }) {
}

const wsProvider = new WebsocketProvider(server, roomName, ydoc, opts);
const daTitle = createAwarenessStatusWidget(wsProvider, window);
createAwarenessStatusWidget(wsProvider, window);

const yXmlFragment = ydoc.getXmlFragment('prosemirror');
handleYDocUpdates({
daTitle, editor, ydoc, path, schema, wsProvider, yXmlFragment, fnInitProse: initProse,
});
handleYDocUpdates({ ydoc, schema, wsProvider, yXmlFragment });

if (window.adobeIMS?.isSignedInUser()) {
window.adobeIMS.getProfile().then(
Expand Down
26 changes: 4 additions & 22 deletions test/unit/blocks/edit/proseCollab.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@ describe('Prose collab', () => {
});

it('Test YDoc server update callback', () => {
const daTitle = {
collabStatus: 'yeah',
collabUsers: 'some',
};
const editor = {};

const ydocMap = new Map();
ydocMap.set('svrinv', 'Some svrinv text');

Expand All @@ -137,33 +131,21 @@ describe('Prose collab', () => {
const wspCalls = [];
const wsp = { destroy: () => wspCalls.push('destroy') };

const initProseCalls = [];
const mockInitProse = () => initProseCalls.push('init');
const setDocInEditCalls = [];
const fnSetDocInEditor = (c) => setDocInEditCalls.push(c);

pi.handleYDocUpdates({
daTitle,
editor,
ydoc,
path: {},
schema: {},
wsProvider: wsp,
yXmlFragment: {},
fnInitProse: mockInitProse,
}, {}, () => {});
}, {}, fnSetDocInEditor);
expect(ydocOnCalls.length).to.equal(1);
expect(ydocOnCalls[0].n).to.equal('update');

expect(daTitle.collabStatus).to.equal('yeah', 'Precondition');
expect(daTitle.collabUsers).to.equal('some', 'Precondition');

// Calls server invalidation
ydocOnCalls[0].f();

expect(daTitle.collabStatus).to.be.undefined;
expect(daTitle.collabUsers).to.be.undefined;
expect(ydocCalls).to.deep.equal(['destroy']);
expect(wspCalls).to.deep.equal(['destroy']);
expect(initProseCalls).to.deep.equal(['init']);
expect(editor.innerHTML).to.equal('');
expect(setDocInEditCalls).to.deep.equal(['Some svrinv text']);
});
});

0 comments on commit e874749

Please sign in to comment.