libreoffice-online/cypress_test/integration_tests/common/repair_document_helper.js
Skyler Grey fd0c49a0be Make the repair document dialog into a JSDialog
- The repair document dialog is a leaflet dialog
- As this dialog is online-side only, I'll use the JSDialog builder
  directly rather than writing a UI file
- Most of the code to build the dialogs is already very adaptable from
  looking at the protocol of existing JSDialogs that come from the
  server & where the code goes, however a small change had to be made to
  dialog modifications to allow us a callback function, as otherwise we
  would send off to the server whenever we pressed on a list item
- Finally, if there's no list to show, we'll show a bit of text saying
  that there's nothing, as otherwise it looks like an empty/broken dialog
- If we're on mobile, we'll need to use the alternative helper (the one
  that handles mobile wizard building)
- Fix a cypress test for writer (although impress and calc seem to have
  tests for this too that aren't implemented: this should be handled in
  a follow-up PR)
- Fix mobile tests

Signed-off-by: Skyler Grey <skyler.grey@collabora.com>
Change-Id: Iab9e943a428e66b05e28819c2ee1001a2deffd2c
2022-09-08 12:52:19 +05:30

53 lines
1.7 KiB
JavaScript

'use strict';
/* global cy require */
var mobileHelper = require('./mobile_helper');
/**
* Opens the document repair dialog in the given frame
*
* @param {string|undefined} frameId - The ID of the frame to execute in, or undefined if you're not running in a framed environment
* @param {boolean} mobile - True if this is a mobile test, otherwise false
* @returns {void}
*/
function openRepairDialog(frameId = undefined, mobile = false) {
if (mobile) {
return mobileHelper.selectHamburgerMenuItem(['Edit', 'Repair']);
}
cy.customGet('#menu-editmenu', frameId)
.click()
.customGet('#menu-repair', frameId)
.click();
}
/**
* Rolls back past the last change matching the selector using the repair document dialog
*
* @param {string} selector - Something to identify the change you want to rollback past. Can be the comment (i.e. 'Typing "World"') or another field (i.e. 'Undo'). The first change that matches this selector will be picked
* @param {string|undefined} frameId - The ID of the frame to execute in, or undefined if you're not running in a framed environment
* @param {boolean} mobile - True if this is a mobile test, otherwise false
* @returns {void}
*/
function rollbackPastChange(selector, frameId = undefined, mobile = false) {
openRepairDialog(frameId, mobile);
cy.customGet('#DocumentRepairDialog', frameId).should('exist');
const versions = cy.customGet('#versions', frameId);
versions
.contains('.ui-listview-entry', selector)
.click();
if (mobile) {
cy.customGet('#ok.ui-pushbutton.mobile-wizard', frameId).click();
} else {
cy.customGet('#ok.ui-pushbutton.jsdialog', frameId).click();
}
}
module.exports = {
openRepairDialog,
rollbackPastChange,
};