Moved form element selectors out into props in the form definition. Added checkAllFieldsDisabled to createFormSection.

This commit is contained in:
mabashian
2017-09-26 14:30:45 -04:00
parent 101c1d7229
commit 5b29e51a24
10 changed files with 164 additions and 150 deletions

View File

@@ -9,8 +9,30 @@ import pagination from './sections/pagination.js';
import permissions from './sections/permissions.js'; import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const standardInvDetails = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#inventory_form .Form-textInput',
'#inventory_form select.Form-dropDown',
'#inventory_form .Form-textArea',
'#inventory_form input[type="checkbox"]',
'#inventory_form .ui-spinner-input',
'#inventory_form .ScheduleToggle-switch'
]
}
});
const smartInvDetails = createFormSection({
selector: 'form',
props: {
formElementSelectors: [
'#smartinventory_form input.Form-textInput',
'#smartinventory_form textarea.Form-textArea',
'#smartinventory_form .Form-lookupButton',
'#smartinventory_form #InstanceGroups'
]
}
}); });
module.exports = { module.exports = {
@@ -25,7 +47,7 @@ module.exports = {
addStandardInventory: { addStandardInventory: {
selector: 'div[ui-view="form"]', selector: 'div[ui-view="form"]',
sections: { sections: {
details standardInvDetails
}, },
elements: { elements: {
title: 'div[class^="Form-title"]' title: 'div[class^="Form-title"]'
@@ -34,7 +56,7 @@ module.exports = {
editStandardInventory: { editStandardInventory: {
selector: 'div[ui-view="form"]', selector: 'div[ui-view="form"]',
sections: { sections: {
details, standardInvDetails,
permissions permissions
}, },
elements: { elements: {
@@ -44,7 +66,7 @@ module.exports = {
addSmartInventory: { addSmartInventory: {
selector: 'div[ui-view="form"]', selector: 'div[ui-view="form"]',
sections: { sections: {
details smartInvDetails
}, },
elements: { elements: {
title: 'div[class^="Form-title"]' title: 'div[class^="Form-title"]'
@@ -53,7 +75,7 @@ module.exports = {
editSmartInventory: { editSmartInventory: {
selector: 'div[ui-view="form"]', selector: 'div[ui-view="form"]',
sections: { sections: {
details, smartInvDetails,
permissions permissions
}, },
elements: { elements: {

View File

@@ -10,7 +10,14 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#inventory_script_form .Form-textInput',
'#inventory_script_form .Form-textArea',
'#inventory_script_form .Form-lookupButton'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -10,7 +10,19 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#notification_template_form .Form-textInput',
'#notification_template_form select.Form-dropDown',
'#notification_template_form input[type="checkbox"]',
'#notification_template_form input[type="radio"]',
'#notification_template_form .ui-spinner-input',
'#notification_template_form .Form-textArea',
'#notification_template_form .ScheduleToggle-switch',
'#notification_template_form .Form-lookupButton'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -8,7 +8,14 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#organization_form input.Form-textInput',
'#organization_form .Form-lookupButton',
'#organization_form #InstanceGroups'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -10,7 +10,15 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#project_form .Form-textInput',
'#project_form select.Form-dropDown',
'#project_form input[type="checkbox"]',
'#project_form .ui-spinner-input',
]
}
}); });
module.exports = { module.exports = {

View File

@@ -79,13 +79,48 @@ const generatorOptions = {
}; };
const createFormSection = function({ selector, labels, strategy }) { const checkAllFieldsDisabled = function() {
let client = this.client.api;
// let selectors = this.props.formElementSelectors ? this.props.formElementSelectors : [
// '.at-Input',
// '.Form-textInput',
// 'select.Form-dropDown',
// 'input[type="checkbox"]',
// 'input[type="radio"]',
// '.ui-spinner-input',
// '.Form-textArea',
// '.ScheduleToggle-switch',
// '.Form-lookupButton'
// ];
let selectors = this.props.formElementSelectors ? this.props.formElementSelectors : [
'.at-Input'
];
selectors.forEach(function(selector) {
client.elements('css selector', selector, inputs => {
inputs.value.map(o => o.ELEMENT).forEach(id => {
client.elementIdAttribute(id, 'disabled', ({ value }) => {
client.assert.equal(value, 'true');
});
});
});
});
};
const createFormSection = function({ selector, labels, strategy, props }) {
let options = generatorOptions[strategy || 'default']; let options = generatorOptions[strategy || 'default'];
let formSection = { let formSection = {
selector, selector,
sections: {}, sections: {},
elements: {} elements: {},
commands: [{
checkAllFieldsDisabled: checkAllFieldsDisabled
}],
props: props
}; };
for (let key in labels) { for (let key in labels) {
@@ -95,7 +130,7 @@ const createFormSection = function({ selector, labels, strategy }) {
formSection.elements[key] = inputElement; formSection.elements[key] = inputElement;
formSection.sections[key] = inputContainer; formSection.sections[key] = inputContainer;
}; }
return formSection; return formSection;
}; };

View File

@@ -10,7 +10,13 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#team_form input.Form-textInput',
'#team_form .Form-lookupButton'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -10,7 +10,17 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#job_template_form .Form-textInput',
'#job_template_form select.Form-dropDown',
'#job_template_form .Form-textArea',
'#job_template_form input[type="checkbox"]',
'#job_template_form .ui-spinner-input',
'#job_template_form .ScheduleToggle-switch'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -10,7 +10,13 @@ import permissions from './sections/permissions.js';
import search from './sections/search.js'; import search from './sections/search.js';
const details = createFormSection({ const details = createFormSection({
selector: 'form' selector: 'form',
props: {
formElementSelectors: [
'#user_form .Form-textInput',
'#user_form select.Form-dropDown'
]
}
}); });
module.exports = { module.exports = {

View File

@@ -82,18 +82,6 @@ let credentials,
inventories, inventories,
teams; teams;
function checkDisabledElements(client, selectors) {
selectors.forEach(function(selector) {
client.elements('css selector', selector, inputs => {
inputs.value.map(o => o.ELEMENT).forEach(id => {
client.elementIdAttribute(id, 'disabled', ({ value }) => {
client.assert.equal(value, 'true');
});
});
});
});
}
function navigateAndWaitForSpinner(client, url) { function navigateAndWaitForSpinner(client, url) {
client client
.url(url) .url(url)
@@ -104,15 +92,17 @@ function navigateAndWaitForSpinner(client, url) {
module.exports = { module.exports = {
before: function (client, done) { before: function (client, done) {
credentials = client.useCss().page.credentials(); client.useCss();
inventoryScripts = client.useCss().page.inventoryScripts();
templates = client.useCss().page.templates(); credentials = client.page.credentials();
notificationTemplates = client.useCss().page.notificationTemplates(); inventoryScripts = client.page.inventoryScripts();
organizations = client.useCss().page.organizations(); templates = client.page.templates();
projects = client.useCss().page.projects(); notificationTemplates = client.page.notificationTemplates();
users = client.useCss().page.users(); organizations = client.page.organizations();
inventories = client.useCss().page.inventories(); projects = client.page.projects();
teams = client.useCss().page.teams(); users = client.page.users();
inventories = client.page.inventories();
teams = client.page.teams();
client.login(); client.login();
client.waitForAngular(); client.waitForAngular();
@@ -233,32 +223,8 @@ module.exports = {
}; };
}); });
}, },
({ adminJobTemplate, created => {
adminAWSCredential, store.created = created;
adminMachineCredential,
adminOrganization,
adminInventoryScript,
adminNotificationTemplate,
adminProject,
adminSmartInventory,
adminStandardInventory,
adminTeam,
adminUser,
auditor }) => {
store.created = {
adminJobTemplate,
adminAWSCredential,
adminMachineCredential,
adminOrganization,
adminInventoryScript,
adminNotificationTemplate,
adminProject,
adminSmartInventory,
adminStandardInventory,
adminTeam,
adminUser,
auditor
};
client.login(store.auditor.username, store.auditor.password); client.login(store.auditor.username, store.auditor.password);
@@ -271,7 +237,7 @@ module.exports = {
credentials.section.edit credentials.section.edit
.expect.element('@title').text.contain(store.created.adminAWSCredential.name); .expect.element('@title').text.contain(store.created.adminAWSCredential.name);
checkDisabledElements(client, ['.at-Input']); credentials.section.edit.section.details.checkAllFieldsDisabled();
}, },
'verify an auditor\'s inventory scripts inputs are read-only': function (client) { 'verify an auditor\'s inventory scripts inputs are read-only': function (client) {
navigateAndWaitForSpinner(client, `${inventoryScripts.url()}/${store.created.adminInventoryScript.id}/`); navigateAndWaitForSpinner(client, `${inventoryScripts.url()}/${store.created.adminInventoryScript.id}/`);
@@ -279,57 +245,31 @@ module.exports = {
inventoryScripts.section.edit inventoryScripts.section.edit
.expect.element('@title').text.contain(store.created.adminInventoryScript.name); .expect.element('@title').text.contain(store.created.adminInventoryScript.name);
let selectors = [ inventoryScripts.section.edit.section.details.checkAllFieldsDisabled();
'#inventory_script_form .Form-textInput',
'#inventory_script_form .Form-textArea',
'#inventory_script_form .Form-lookupButton'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on inventory scripts form': function () { 'verify save button hidden from auditor on inventory scripts form': function () {
inventoryScripts.expect.element('@save').to.not.be.visible; inventoryScripts.expect.element('@save').to.not.be.visible;
}, },
'verify an auditor\'s job template inputs are read-only': function (client) { // TODO: re-enable these tests when JT edit has been re-factored to reliably show/remove the loading spinner
navigateAndWaitForSpinner(client, `${templates.url()}/job_template/${store.created.adminJobTemplate.id}/`); // only one time. Without this, we can't tell when all the requisite data is available.
// 'verify an auditor\'s job template inputs are read-only': function (client) {
templates.section.editJobTemplate // navigateAndWaitForSpinner(client, `${templates.url()}/job_template/${store.created.adminJobTemplate.id}/`);
.expect.element('@title').text.contain(store.created.adminJobTemplate.name); //
// templates.section.editJobTemplate
client.pause(2000); // .expect.element('@title').text.contain(store.created.adminJobTemplate.name);
//
let selectors = [ // templates.section.edit.section.details.checkAllFieldsDisabled();
'#job_template_form .Form-textInput', // },
'#job_template_form select.Form-dropDown', // 'verify save button hidden from auditor on job templates form': function () {
'#job_template_form .Form-textArea', // templates.expect.element('@save').to.not.be.visible;
'#job_template_form input[type="checkbox"]', // },
'#job_template_form .ui-spinner-input',
'#job_template_form .ScheduleToggle-switch'
];
checkDisabledElements(client, selectors);
},
'verify save button hidden from auditor on job templates form': function () {
templates.expect.element('@save').to.not.be.visible;
},
'verify an auditor\'s notification templates inputs are read-only': function (client) { 'verify an auditor\'s notification templates inputs are read-only': function (client) {
navigateAndWaitForSpinner(client, `${notificationTemplates.url()}/${store.created.adminNotificationTemplate.id}/`); navigateAndWaitForSpinner(client, `${notificationTemplates.url()}/${store.created.adminNotificationTemplate.id}/`);
notificationTemplates.section.edit notificationTemplates.section.edit
.expect.element('@title').text.contain(store.created.adminNotificationTemplate.name); .expect.element('@title').text.contain(store.created.adminNotificationTemplate.name);
let selectors = [ notificationTemplates.section.edit.section.details.checkAllFieldsDisabled();
'#notification_template_form .Form-textInput',
'#notification_template_form select.Form-dropDown',
'#notification_template_form input[type="checkbox"]',
'#notification_template_form input[type="radio"]',
'#notification_template_form .ui-spinner-input',
'#notification_template_form .Form-textArea',
'#notification_template_form .ScheduleToggle-switch',
'#notification_template_form .Form-lookupButton'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on notification templates page': function () { 'verify save button hidden from auditor on notification templates page': function () {
notificationTemplates.expect.element('@save').to.not.be.visible; notificationTemplates.expect.element('@save').to.not.be.visible;
@@ -340,13 +280,7 @@ module.exports = {
organizations.section.edit organizations.section.edit
.expect.element('@title').text.contain(store.created.adminOrganization.name); .expect.element('@title').text.contain(store.created.adminOrganization.name);
let selectors = [ organizations.section.edit.section.details.checkAllFieldsDisabled();
'#organization_form input.Form-textInput',
'#organization_form .Form-lookupButton',
'#organization_form #InstanceGroups'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on organizations form': function () { 'verify save button hidden from auditor on organizations form': function () {
organizations.expect.element('@save').to.not.be.visible; organizations.expect.element('@save').to.not.be.visible;
@@ -357,14 +291,7 @@ module.exports = {
inventories.section.editSmartInventory inventories.section.editSmartInventory
.expect.element('@title').text.contain(store.created.adminSmartInventory.name); .expect.element('@title').text.contain(store.created.adminSmartInventory.name);
let selectors = [ inventories.section.editSmartInventory.section.smartInvDetails.checkAllFieldsDisabled();
'#smartinventory_form input.Form-textInput',
'#smartinventory_form textarea.Form-textArea',
'#smartinventory_form .Form-lookupButton',
'#smartinventory_form #InstanceGroups'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on smart inventories form': function () { 'verify save button hidden from auditor on smart inventories form': function () {
inventories.expect.element('@save').to.not.be.visible; inventories.expect.element('@save').to.not.be.visible;
@@ -375,14 +302,7 @@ module.exports = {
projects.section.edit projects.section.edit
.expect.element('@title').text.contain(store.created.adminProject.name); .expect.element('@title').text.contain(store.created.adminProject.name);
let selectors = [ projects.section.edit.section.details.checkAllFieldsDisabled();
'#project_form .Form-textInput',
'#project_form select.Form-dropDown',
'#project_form input[type="checkbox"]',
'#project_form .ui-spinner-input',
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on projects form': function () { 'verify save button hidden from auditor on projects form': function () {
projects.expect.element('@save').to.not.be.visible; projects.expect.element('@save').to.not.be.visible;
@@ -393,16 +313,7 @@ module.exports = {
inventories.section.editStandardInventory inventories.section.editStandardInventory
.expect.element('@title').text.contain(store.created.adminStandardInventory.name); .expect.element('@title').text.contain(store.created.adminStandardInventory.name);
let selectors = [ inventories.section.editStandardInventory.section.standardInvDetails.checkAllFieldsDisabled();
'#inventory_form .Form-textInput',
'#inventory_form select.Form-dropDown',
'#inventory_form .Form-textArea',
'#inventory_form input[type="checkbox"]',
'#inventory_form .ui-spinner-input',
'#inventory_form .ScheduleToggle-switch'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on standard inventory form': function () { 'verify save button hidden from auditor on standard inventory form': function () {
inventories.expect.element('@save').to.not.be.visible; inventories.expect.element('@save').to.not.be.visible;
@@ -413,12 +324,7 @@ module.exports = {
teams.section.edit teams.section.edit
.expect.element('@title').text.contain(store.created.adminTeam.name); .expect.element('@title').text.contain(store.created.adminTeam.name);
let selectors = [ teams.section.edit.section.details.checkAllFieldsDisabled();
'#team_form input.Form-textInput',
'#team_form .Form-lookupButton'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on teams form': function () { 'verify save button hidden from auditor on teams form': function () {
teams.expect.element('@save').to.not.be.visible; teams.expect.element('@save').to.not.be.visible;
@@ -429,12 +335,7 @@ module.exports = {
users.section.edit users.section.edit
.expect.element('@title').text.contain(store.created.adminUser.username); .expect.element('@title').text.contain(store.created.adminUser.username);
let selectors = [ users.section.edit.section.details.checkAllFieldsDisabled();
'#user_form .Form-textInput',
'#user_form select.Form-dropDown'
];
checkDisabledElements(client, selectors);
}, },
'verify save button hidden from auditor on users form': function (client) { 'verify save button hidden from auditor on users form': function (client) {
users.expect.element('@save').to.not.be.visible; users.expect.element('@save').to.not.be.visible;