Skip to content

Commit

Permalink
cool#8648 clipboard: fix desktop/writer/copy_paste_spec.js
Browse files Browse the repository at this point in the history
Once the patch from
<#8648 (comment)>
is applied to make CanvasTileLayer.js _onTextSelectionMsg() not fetch
the clipboard proactively, this test started to fail.

This happened because the test assumed that once a text selection is
created, we have the HTML for it, which is no longer the case.

Fix the problem by extending the dummy clipboard code to also handle
plain text and by adding a function which triggers the copy(), to
minimize the changes to the actual test code.

This is just a start, lots of other tests still need fixing, and once
the pattern is clear, common code should be extracted to
cypress_test/integration_tests/common/helper.js, probably.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I21ed1143470fa8026e133b0519e114a40fc0ed90
  • Loading branch information
vmiklos authored and caolanm committed Apr 9, 2024
1 parent 3a4c3d7 commit 286cd1c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion browser/src/layer/tile/CanvasTileLayer.js
Expand Up @@ -3256,7 +3256,7 @@ L.CanvasTileLayer = L.Layer.extend({
this._map.removeLayer(this._map._textInput._cursorHandler); // User selected a text, we remove the carret marker.
// Keep fetching the text selection during testing, for now: too many tests
// depend on this behavior currently.
if (navigator.clipboard.write && !L.Browser.cypressTest) {
if (navigator.clipboard.write && !(L.Browser.cypressTest && !this._map._clip._dummyClipboard.useAsyncWrite)) {
this._map._clip.setTextSelectionType('text');
} else {
if (this._selectionContentRequest) {
Expand Down
31 changes: 26 additions & 5 deletions cypress_test/integration_tests/desktop/writer/copy_paste_spec.js
Expand Up @@ -13,27 +13,46 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
helper.afterAll(testFileName, this.currentTest.state);
});

function setDummyClipboard() {
// Replaces the system clipboard with a dummy one. The specified type will be injected into
// the DOM for assertion purposes.
function setDummyClipboard(type) {
if (type === undefined) {
type = 'text/html';
}
cy.window().then(win => {
const app = win['0'].app;
const clipboard = app.map._clip;
clipboard._dummyClipboard = {
write: function(clipboardItems) {
const clipboardItem = clipboardItems[0];
clipboardItem.getType('text/html').then(blob => blob.text())
clipboardItem.getType(type).then(blob => blob.text())
.then(function (text) {
clipboard._dummyDiv.innerHTML = text;
if (type === 'text/html') {
clipboard._dummyDiv.innerHTML = text;
} else if (type == 'text/plain') {
clipboard._dummyPlainDiv.innerHTML = text;
}
});
return {
then: function(resolve/*, reject*/) {
resolve();
},
};
},

useAsyncWrite: true,
};
});
}

function copy() {
cy.window().then(win => {
const app = win['0'].app;
const clipboard = app.map._clip;
clipboard.filterExecCopyPaste('.uno:Copy');
});
}

it('Copy and Paste text.', function() {
before('copy_paste.odt');
// Select some text
Expand All @@ -59,9 +78,11 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
it('Copy plain text.', function() {
before('copy_paste_simple.odt');

setDummyClipboard('text/plain');
helper.selectAllText();
copy();

let expected = ' • first\n • second\n • third\n';
cy.cGet('#copy-plain-container').should('have.text', expected.replaceAll('\n', ''));
let expected = ' • first\n • second\n • third';
cy.cGet('#copy-plain-container').should('have.text', expected);
});
});

0 comments on commit 286cd1c

Please sign in to comment.