Skip to content
Snippets Groups Projects
Commit b2259986 authored by Simon Urli's avatar Simon Urli
Browse files

XWIKI-17005: Page created with partial names in case of slow server

  * Fix other possible cause of flickers, by checking that the events
    taken into account is the last one
  * Fix tests by simplifying the PO for field input
  * Add some listener on blur events so that we check those too
parent 29ed34ff
No related branches found
No related tags found
No related merge requests found
......@@ -141,9 +141,11 @@ public void testCreateUIInteraction()
// Clear the title, set a page name and check that the breadcrumb now uses the page name as a fallback.
createPage.getDocumentPicker().setTitle("");
createPage.getDocumentPicker().waitForName("");
createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/");
assertEquals("", createPage.getDocumentPicker().getName());
createPage.getDocumentPicker().setName(newName);
createPage.getDocumentPicker().waitForName(newName);
createPage.waitForLocationPreviewContent("/" + existingPageTitle + "/" + newName);
// Set a new parent space and check that the breadcrumb is updated.
......
......@@ -931,23 +931,10 @@ public String toString()
*/
public void setTextInputValue(WebElement textInputElement, String newTextValue)
{
if (StringUtils.isEmpty(newTextValue)) {
// Workaround for the fact that clear() fires the "change" event but not the "input" event and javascript
// listening to the "input" event will not be executed otherwise.
// Note 1: We're not using CTRL+A and the Delete because the key combination to select the full input
// depends on the OS (on Mac it's META+A for example).
// Note 2: Sending the END key didn't always work when I tested it on Mac (for some unknown reason)
textInputElement.click();
textInputElement.sendKeys(
StringUtils.repeat(Keys.ARROW_RIGHT.toString(), textInputElement.getAttribute("value").length()));
textInputElement.sendKeys(
StringUtils.repeat(Keys.BACK_SPACE.toString(), textInputElement.getAttribute("value").length()));
} else {
textInputElement.clear();
textInputElement.sendKeys(newTextValue);
// To be sure the right events are sent.
textInputElement.sendKeys(Keys.TAB);
}
textInputElement.clear();
textInputElement.sendKeys(newTextValue);
// To be sure the right events are sent.
textInputElement.sendKeys(Keys.TAB);
}
/**
......
......@@ -173,25 +173,31 @@ require(['jquery', 'xwiki-meta', 'xwiki-events-bridge'], function($, xm) {
var updateLocationAndNameFromTitleInput = function(event) {
// ensure the buttons are disabled before we got the name answer
disableButtons();
titleInputVal = titleInput.val();
// Update the name field.
getPageName(titleInput.val()).done(function(data) {
// we trigger a change so we can validate the name
nameInput.val(data.transformedName).trigger(('change'));
// Update the location preview.
updateLocationFromTitleInput();
getPageName(titleInputVal).done(function(data) {
// Ensure that the input didn't change while we were waiting the answer.
// It also protects the value if a previous request was slow to arrive.
if (titleInputVal === titleInput.val()) {
// we trigger a change so we can validate the name
nameInput.val(data.transformedName).trigger('change');
// Update the location preview.
updateLocationFromTitleInput();
}
// enable back the buttons
enableButtons();
}).fail(function (response) {
new XWiki.widgets.Notification(
"$services.localization.render('entitynamevalidation.nametransformation.error')",
'error'
);
// we trigger a change so we can validate the name
nameInput.val(titleInput.val()).trigger('change');
// Update the location preview.
updateLocationFromTitleInput();
if (titleInputVal === titleInput.val()) {
new XWiki.widgets.Notification(
"$services.localization.render('entitynamevalidation.nametransformation.error')",
'error'
);
// we trigger a change so we can validate the name
nameInput.val(titleInputVal).trigger('change');
// Update the location preview.
updateLocationFromTitleInput();
}
// enable back the buttons
enableButtons();
});
......@@ -292,12 +298,11 @@ require(['jquery', 'xwiki-meta', 'xwiki-events-bridge'], function($, xm) {
};
// Synchronize the location fields while the user types.
titleInput.on('input', updateLocationAndNameFromTitleInput);
// Ensure that everything's updated when users change fields (particulary useful in our tests)
titleInput.on('blur', updateLocationAndNameFromTitleInput);
// Blur ensure that everything's updated when users change fields (particulary useful in our tests)
titleInput.on('input blur', updateLocationAndNameFromTitleInput);
wikiField.change(updateLocationFromWikiField);
nameInput.on('input', updateLocationFromNameInput);
spaceReferenceInput.on('input xwiki:suggest:selected', updateLocationFromSpaceReference);
nameInput.on('input blur', updateLocationFromNameInput);
spaceReferenceInput.on('input blur xwiki:suggest:selected', updateLocationFromSpaceReference);
// Clean the output of the hierarchy macro when it should display a top level document.
if (!spaceReferenceInput.val()) {
......@@ -305,7 +310,7 @@ require(['jquery', 'xwiki-meta', 'xwiki-events-bridge'], function($, xm) {
}
// Update the location with whatever the initial value of the title is.
if (!nameInput.val()) {
if (nameInput.val() !== undefined && !nameInput.val()) {
updateLocationAndNameFromTitleInput();
} else {
updateLocationFromTitleInput();
......
......@@ -163,6 +163,7 @@ public void testCopyOverwritePage() throws Exception
documentPicker.waitForName(targetPageName);
documentPicker.waitForLocation(Arrays.asList("", targetSpaceName, targetPageName));
Assert.assertEquals(targetSpaceName, copyPage.getTargetSpaceName());
Assert.assertEquals(targetPageName, copyPage.getTargetPageName());
// Click copy button
......
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