cool#8648 clipboard: fix desktop/writer/copy_paste_spec.js
Once the patch from <https://github.com/CollaboraOnline/online/issues/8648#issuecomment-2037278091> 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
This commit is contained in:
parent
3a4c3d7c36
commit
286cd1ccf7
2 changed files with 27 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -13,16 +13,25 @@ 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*/) {
|
||||
|
@ -30,10 +39,20 @@ describe(['tagdesktop', 'tagnextcloud', 'tagproxy'], 'Clipboard operations.', fu
|
|||
},
|
||||
};
|
||||
},
|
||||
|
||||
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
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue