Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing an infinite loop when discarding user changes #1068

Merged
merged 1 commit into from
Sep 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions html/internal_dashboard/js/admin_panel/SectionExistingUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,28 @@ XDMoD.ExistingUsers = Ext.extend(Ext.Panel, {
return false;
};

/**
* Reverts the User Settings ( E-Mail Address, User Type, Map To, Institution ) to their original values.
*/
var revertUserSettings = function () {
// eslint-disable-next-line no-use-before-define
var fieldValues = userSettings.getForm().getFieldValues();
for (var id in fieldValues) {
if (fieldValues.hasOwnProperty(id)) {
var field = Ext.getCmp(id);

// Only check a field if it's been rendered.
if (field.rendered) {
if (field.originalValue !== field.getValue()) {
field.setValue(field.originalValue);
}
}
}
}
};

self.resetDirtyState = function () {
revertUserSettings();
roleGrid.setDirtyState(false);
};

Expand Down
100 changes: 99 additions & 1 deletion tests/ui/test/specs/xdmod/internalDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,104 @@ describe('Internal Dashboard', function () {
expect(roles).to.equal('User');
});
});
describe('Make sure that updates to the newly created users Settings can be discarded', function () {
const settings = [
{
label: 'User Type',
type: 'text',
updated: 'Testing',
expected: 'External'
},
{
label: 'Map To',
type: 'text',
updated: 'Auk, Great',
expected: 'Unknown, Unknown'
},
{
label: 'Institution',
type: 'text',
updated: 'Unknown Organization',
expected: 'Screwdriver'
}
];
settings.forEach(function (value) {
describe(`Checking: ${value.label}`, function () {
it('Select the "Existing Users" tab', function () {
browser.waitForVisible(page.selectors.user_management.tabs.existing_users());
browser.waitAndClick(page.selectors.user_management.tabs.existing_users());
});
it('Ensure that the "Existing Users" table is displayed', function () {
browser.waitForVisible(page.selectors.existing_users.table.container);
});
it('Double click the users row in the `Existing Users` table', function () {
const usernameCol = page.selectors.existing_users.table.col_for_user('btest', 'Username');
browser.waitForValue(usernameCol);
browser.doubleClick(usernameCol);

browser.waitForVisible(page.selectors.create_manage_users.window);
browser.waitForVisible(page.selectors.create_manage_users.current_users.container);
});
it(`Change the "${value.label}" to "${value.updated}"`, function () {
const inputTrigger = page.selectors.create_manage_users.current_users.settings.inputTriggerByLabelText(value.label);
browser.waitForVisible(inputTrigger);
browser.click(inputTrigger);

const inputDropDown = page.selectors.combo.container;
browser.waitForVisible(inputDropDown);

const dropDownValue = page.selectors.combo.itemByText(value.updated);
browser.waitForVisible(dropDownValue);
browser.waitAndClick(dropDownValue);

browser.waitForInvisible(inputDropDown);

const input = page.selectors.create_manage_users.current_users.settings.inputByLabelText(value.label, value.type);
const updatedValue = browser.getValue(input);
expect(updatedValue).to.equal(value.updated);
});
it('Ensure that the user dirty message is shown', function () {
const dirtyMessage = page.selectors.create_manage_users.bottom_bar.messageByText('unsaved changes');
browser.waitForVisible(dirtyMessage);
});
it('Click the Close button', function () {
const closeButton = page.selectors.create_manage_users.current_users.button('Close');
browser.waitAndClick(closeButton);
});
it('Ensure that the Unsaved Changes modal is presented', function () {
browser.waitForVisible(page.selectors.modal.containerByTitle('Unsaved Changes'));
});
it('Discard Changes', function () {
const noButton = page.selectors.modal.buttonByText('Unsaved Changes', 'No');
browser.waitForVisible(noButton);
browser.click(noButton);

// We expect that the modal dialog will disappear
browser.waitForInvisible(page.selectors.modal.containerByTitle('Unsaved Changes'));
});
it('Edit the User again', function () {
const usernameCol = page.selectors.existing_users.table.col_for_user('btest', 'Username');
browser.waitForValue(usernameCol);
browser.doubleClick(usernameCol);

browser.waitForVisible(page.selectors.create_manage_users.window);
browser.waitForVisible(page.selectors.create_manage_users.current_users.container);
});
it(`Check that the ${value.label} is back to ${value.expected}`, function () {
const userTypeInput = page.selectors.create_manage_users.current_users.settings.inputByLabelText(value.label, value.type);

browser.waitForVisible(userTypeInput);
const userType = browser.getValue(userTypeInput);
expect(userType).to.equal(value.expected);
});
it('Close the Edit Existing User Modal', function () {
const closeButton = page.selectors.create_manage_users.current_users.button('Close');
browser.waitForVisible(closeButton);
browser.click(closeButton);
});
});
});
});
describe('Remove the newly created User', function () {
it('Ensure that were on the "Existing Users" tab', function () {
browser.waitForVisible(page.selectors.user_management.tabs.existing_users());
Expand Down Expand Up @@ -153,7 +251,7 @@ describe('Internal Dashboard', function () {
browser.click(deleteUserItem);
});
it('Confirm the deletion of the user', function () {
const yesDelete = page.selectors.buttonInModalDialog('Delete User', 'Yes');
const yesDelete = page.selectors.modal.buttonByText('Delete User', 'Yes');
browser.waitAndClick(yesDelete);

const deleteNotification = page.selectors.deleteSuccessNotification('btest');
Expand Down
46 changes: 36 additions & 10 deletions tests/ui/test/specs/xdmod/internalDashboard.page.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ class InternalDashboard {
},
create_user: function () {
return `${self.selectors.create_manage_users.window}//button[contains(@class, "admin_panel_btn_create_user")]`;
},
save_changes: function () {
return `${self.selectors.create_manage_users.window}//button[contains(text(), "Save Changes")]`;
}
},
current_users: {
Expand All @@ -125,10 +128,19 @@ class InternalDashboard {
deleteUser: {
container: '//div[contains(@class, "delete_user") and contains(@class, "x-window")]',
button: function (text) {
return `${self.selectors.modalDiaglogByTitle('Delete User')}//button[.="${text}"]`;
return `${self.selectors.modal.containerByTitle('Delete User')}//button[.="${text}"]`;
}
}
},
settings: {
container: '//div[@id="admin_panel_user_editor"]',
inputByLabelText: function (labelText, inputType) {
return `${self.selectors.create_manage_users.current_users.settings.container}//label[contains(text(), "${labelText}")]/parent::*//input[@type="${inputType}"]`;
},
inputTriggerByLabelText: function (labelText) {
return `${self.selectors.create_manage_users.current_users.settings.container}//label[contains(text(), "${labelText}")]/parent::*//img[contains(@class, "x-form-trigger")]`;
}
},
button: function (text) {
return `//div[@id="admin_tab_existing_user"]//button[.="${text}"]`;
}
Expand Down Expand Up @@ -170,34 +182,48 @@ class InternalDashboard {
dialog: function (text) {
return `//div[contains(@class, "x-window") and contains(@class, "x-notification")]//b[contains(@class, "user_management_message") and contains(text(), "${text}")]`;
}
},
bottom_bar: {
container: function () {
return `${self.selectors.create_manage_users.window}//div[contains(@class, "x-panel-bbar")]`;
},
messageByText: function (text) {
return `${self.selectors.create_manage_users.bottom_bar.container()}//span[contains(text(), "${text}")]`;
}
}
},
tabByText: function (name) {
return `//div[@id="dashboard-tabpanel"]//span[contains(@class, "x-tab-strip-text") and contains(text(), "${name}")]`;
},
combo: {
container: '//div[contains(@class, "x-combo-list")]',
container: '//div[contains(@class, "x-combo-list") and contains(@style, "visibility: visible")]',
itemByText: function (text) {
return `${self.selectors.combo.container}//div[contains(@class, "x-combo-list-item") and contains(text(), "${text}")]`;
}
},
createSuccessNotification: function (username) {
return self.selectors.modalDiaglogByTitle('User Management') +
return self.selectors.modal.containerByTitle('User Management') +
'//b[text()[1][contains(., "User")] and text()[2][contains(., "created successfully")]]/b[text() = "' +
username + '"]/ancestor::node()[1]';
},
deleteSuccessNotification: function (username) {
return self.selectors.modalDiaglogByTitle('User Management') +
return self.selectors.modal.containerByTitle('User Management') +
'//b[text()[1][contains(., "User")] and text()[2][contains(., "deleted from the portal")]]/b[text() = "' +
username + '"]/ancestor::node()[1]';
},
buttonInModalDialog: function (title, button) {
return `${self.selectors.modalDiaglogByTitle(title)}//button[contains(text(), "${button}")]`;
},
modalDiaglogByTitle: function (title) {
return '//div[contains(@class, "x-window")]//div[contains(@class, "x-window-header")]//span[contains(@class, "x-window-header-text") and text()="' + title + '"]/ancestor::node()[5]';
modal: {
containerByTitle: function (title) {
return `//div[contains(@class, "x-window")]//div[contains(@class, "x-window-header")]//span[contains(@class, "x-window-header-text") and text()="${title}"]/ancestor::node()[5]`;
},
buttonByText: function (modalTitle, buttonText) {
return `${self.selectors.modal.containerByTitle(modalTitle)}//button[contains(text(), "${buttonText}")]`;
},
tools: {
close: function (modalTitle) {
return `${self.selectors.modal.containerByTitle(modalTitle)}//div[contains(@class, "x-tool-close")]`;
}
}
}

};
}

Expand Down