Skip to content
Snippets Groups Projects
Unverified Commit c2cd3496 authored by Dorian OUAKLI's avatar Dorian OUAKLI Committed by GitHub
Browse files

XWIKI-22367: Clicking on Allow Realtime Collaboration in Source mode leads to...

XWIKI-22367: Clicking on Allow Realtime Collaboration in Source mode leads to unexpected result (#3311)
parent 5c8a71ff
No related branches found
No related tags found
No related merge requests found
...@@ -69,9 +69,19 @@ ...@@ -69,9 +69,19 @@
previousValue: null previousValue: null
}; };
editor.on('beforeSetMode', this.beforeSetMode.bind(this)); editor.on('beforeSetMode', this.beforeSetMode.bind(this));
editor.on('mode', this.mode.bind(this));
}); });
}, },
mode: function(event) {
// The user should not be able to join the realtime editing session while in source mode.
// We disable the allow realtime checkbox while in source mode, and enable it when we go back to wysiwyg.
const editor = event.editor;
const realtimeCheckbox = editor._realtimeInterface.getAllowRealtimeCheckbox();
realtimeCheckbox.prop('disabled', editor.mode !== 'wysiwyg');
},
beforeSetMode: function(event) { beforeSetMode: function(event) {
const newMode = event.data; const newMode = event.data;
......
...@@ -1427,6 +1427,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils ...@@ -1427,6 +1427,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils
// Switch to source mode and check that we are not in the realtime session anymore. // Switch to source mode and check that we are not in the realtime session anymore.
secondEditorToolbar.toggleSourceMode(); secondEditorToolbar.toggleSourceMode();
assertFalse(secondEditPage.isRealtimeEditing()); assertFalse(secondEditPage.isRealtimeEditing());
assertFalse(secondEditPage.canToggleRealtimeEditing());
// Check that we can still switch back to wysiwyg mode. // Check that we can still switch back to wysiwyg mode.
assertTrue(secondEditorToolbar.canToggleSourceMode()); assertTrue(secondEditorToolbar.canToggleSourceMode());
...@@ -1456,6 +1457,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils ...@@ -1456,6 +1457,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils
// Check that the second user re-joined the realtime editing session. // Check that the second user re-joined the realtime editing session.
assertTrue(secondEditPage.isRealtimeEditing()); assertTrue(secondEditPage.isRealtimeEditing());
assertTrue(secondEditPage.canToggleRealtimeEditing());
assertTrue(secondEditorToolbar.canToggleSourceMode()); assertTrue(secondEditorToolbar.canToggleSourceMode());
secondTextArea.waitUntilContentContains("four"); secondTextArea.waitUntilContentContains("four");
assertEquals("one\ntwo\nthree\nfour", secondTextArea.getText()); assertEquals("one\ntwo\nthree\nfour", secondTextArea.getText());
...@@ -1470,6 +1472,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils ...@@ -1470,6 +1472,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils
secondEditorToolbar.toggleSourceMode(); secondEditorToolbar.toggleSourceMode();
assertFalse(secondEditPage.isRealtimeEditing()); assertFalse(secondEditPage.isRealtimeEditing());
assertFalse(secondEditPage.canToggleRealtimeEditing());
// Check the contents of the source mode. // Check the contents of the source mode.
assertEquals("one\n\ntwo\n\nthree\n\nfour", secondEditor.getSourceTextArea().getAttribute("value")); assertEquals("one\n\ntwo\n\nthree\n\nfour", secondEditor.getSourceTextArea().getAttribute("value"));
...@@ -1499,6 +1502,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils ...@@ -1499,6 +1502,7 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils
// Check that the second user did not re-join the realtime editing session. // Check that the second user did not re-join the realtime editing session.
assertFalse(secondEditPage.isRealtimeEditing()); assertFalse(secondEditPage.isRealtimeEditing());
assertTrue(secondEditorToolbar.canToggleSourceMode()); assertTrue(secondEditorToolbar.canToggleSourceMode());
assertTrue(secondEditPage.canToggleRealtimeEditing());
assertEquals("one\ntwo\nthree\nfour\nfive", secondTextArea.getText()); assertEquals("one\ntwo\nthree\nfour\nfive", secondTextArea.getText());
// Join the realtime session again and wait to be in sync. // Join the realtime session again and wait to be in sync.
...@@ -1515,12 +1519,27 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils ...@@ -1515,12 +1519,27 @@ void editSource(TestUtils setup, TestReference testReference, MultiUserTestUtils
// Switch to source mode and back to wysiwyg edit mode. // Switch to source mode and back to wysiwyg edit mode.
secondEditorToolbar.toggleSourceMode(); secondEditorToolbar.toggleSourceMode();
assertFalse(secondEditPage.isRealtimeEditing()); assertFalse(secondEditPage.isRealtimeEditing());
assertFalse(secondEditPage.canToggleRealtimeEditing());
assertEquals("one\n\ntwo\n\nthree\n\nfour\n\nsix\n\nseven", assertEquals("one\n\ntwo\n\nthree\n\nfour\n\nsix\n\nseven",
secondEditor.getSourceTextArea().getAttribute("value")); secondEditor.getSourceTextArea().getAttribute("value"));
secondEditorToolbar.toggleSourceMode(); secondEditorToolbar.toggleSourceMode();
assertTrue(secondEditPage.canToggleRealtimeEditing());
// Check that the second user did not re-join the realtime editing session. // Check that the second user did not re-join the realtime editing session.
assertFalse(secondEditPage.isRealtimeEditing()); assertFalse(secondEditPage.isRealtimeEditing());
// Switch to source mode and back to wysiwyg again.
// We should stay out of the realtime editing session.
secondEditorToolbar.toggleSourceMode();
assertFalse(secondEditPage.isRealtimeEditing());
assertFalse(secondEditPage.canToggleRealtimeEditing());
assertEquals("one\n\ntwo\n\nthree\n\nfour\n\nsix\n\nseven",
secondEditor.getSourceTextArea().getAttribute("value"));
secondEditorToolbar.toggleSourceMode();
assertFalse(secondEditPage.isRealtimeEditing());
assertTrue(secondEditPage.canToggleRealtimeEditing());
// We keep the second user out of the realtime editing session now // We keep the second user out of the realtime editing session now
// and we do more tests with the first user. // and we do more tests with the first user.
......
...@@ -78,7 +78,18 @@ public boolean isRealtimeEditing() ...@@ -78,7 +78,18 @@ public boolean isRealtimeEditing()
{ {
return this.allowRealtimeCheckbox.isSelected(); return this.allowRealtimeCheckbox.isSelected();
} }
/**
* @return {code true} if it is possible to join or leave the editing session, {@code false} otherwise
* @since 15.10.12
* @since 16.4.2
* @since 16.7.0RC1
*/
public boolean canToggleRealtimeEditing()
{
return this.allowRealtimeCheckbox.isEnabled();
}
/** /**
* Leave the realtime editing session. * Leave the realtime editing session.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment