Skip to content

Commit

Permalink
cool#8648 clipboard: fix desktop/calc/clipboard_spec.js
Browse files Browse the repository at this point in the history
Move two functions from desktop/writer/copy_paste_spec.js to
common/helper.js, this way desktop/calc/clipboard_spec.js can do an
explicit Copy and then it passes even with the async copy.

Signed-off-by: Miklos Vajna <vmiklos@collabora.com>
Change-Id: I7874f0ac00a4237a90015b0fbcd67dcfd2e9ad68
  • Loading branch information
vmiklos authored and caolanm committed Apr 10, 2024
1 parent 94c9153 commit 803df01
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 43 deletions.
43 changes: 43 additions & 0 deletions cypress_test/integration_tests/common/helper.js
Expand Up @@ -1212,6 +1212,47 @@ function clickAt(aliasName, double = false) {
cy.log('<< clickAt - end');
}

// Replaces the system clipboard with a dummy one for copy purposes. The copy content for the
// specified type will be injected into the DOM, so the caller can assert it.
function setDummyClipboardForCopy(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(type).then(blob => blob.text())
.then(function (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,
};
});
}

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

module.exports.loadTestDoc = loadTestDoc;
module.exports.checkIfDocIsLoaded = checkIfDocIsLoaded;
module.exports.assertCursorAndFocus = assertCursorAndFocus;
Expand Down Expand Up @@ -1258,3 +1299,5 @@ module.exports.assertFocus = assertFocus;
module.exports.loadTestDocNoIntegration = loadTestDocNoIntegration;
module.exports.getBlinkingCursorPosition = getBlinkingCursorPosition;
module.exports.clickAt = clickAt;
module.exports.setDummyClipboardForCopy = setDummyClipboardForCopy;
module.exports.copy = copy;
2 changes: 2 additions & 0 deletions cypress_test/integration_tests/desktop/calc/clipboard_spec.js
Expand Up @@ -80,6 +80,8 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Calc clipboard tests.', fu
// Without the accompanying fix in place, this test would have failed with:
// expected **#copy-paste-container table td:nth-of-type(1)** to have text **'5'**, but the text was **''**
// i.e. a popup dialog was shown, instead of working, like with Ctrl-V.
helper.setDummyClipboardForCopy();
helper.copy();
cy.cGet('#copy-paste-container table td:nth-of-type(1)').should('have.text', '5');
});

Expand Down
46 changes: 3 additions & 43 deletions cypress_test/integration_tests/desktop/writer/copy_paste_spec.js
Expand Up @@ -13,46 +13,6 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
helper.afterAll(testFileName, this.currentTest.state);
});

// 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(type).then(blob => blob.text())
.then(function (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 @@ -67,7 +27,7 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
cy.cGet('body').rightclick(XPos, YPos);
});

setDummyClipboard();
helper.setDummyClipboardForCopy();

cy.cGet('body').contains('.context-menu-link', 'Copy')
.click();
Expand All @@ -78,9 +38,9 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
it('Copy plain text.', function() {
before('copy_paste_simple.odt');

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

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

0 comments on commit 803df01

Please sign in to comment.