annotate core/tests/Drupal/Nightwatch/Commands/drupalCreateRole.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@17 1 /**
Chris@17 2 * Creates role with given permissions.
Chris@17 3 *
Chris@17 4 * @param {object} settings
Chris@17 5 * Settings object
Chris@17 6 * @param {array} settings.permissions
Chris@17 7 * The list of roles granted for the user.
Chris@17 8 * @param {string} [settings.name=null]
Chris@17 9 * The role name.
Chris@17 10 * @param {function} callback
Chris@17 11 * A callback which will be called, when creating the role is finished.
Chris@17 12 * @return {object}
Chris@17 13 * The drupalCreateRole command.
Chris@17 14 */
Chris@17 15 exports.command = function drupalCreateRole(
Chris@17 16 { permissions, name = null },
Chris@17 17 callback,
Chris@17 18 ) {
Chris@17 19 const self = this;
Chris@17 20 const roleName =
Chris@17 21 name ||
Chris@17 22 Math.random()
Chris@17 23 .toString(36)
Chris@17 24 .substring(2, 15);
Chris@17 25
Chris@17 26 let machineName;
Chris@17 27 this.drupalLoginAsAdmin(() => {
Chris@17 28 this.drupalRelativeURL('/admin/people/roles/add')
Chris@17 29 .setValue('input[name="label"]', roleName)
Chris@17 30 // Wait for the machine name to appear so that it can be used later to
Chris@17 31 // select the permissions from the permission page.
Chris@17 32 .expect.element('.user-role-form .machine-name-value')
Chris@17 33 .to.be.visible.before(2000);
Chris@17 34
Chris@17 35 this.perform(done => {
Chris@17 36 this.getText('.user-role-form .machine-name-value', element => {
Chris@17 37 machineName = element.value;
Chris@17 38 done();
Chris@17 39 });
Chris@17 40 })
Chris@17 41 .submitForm('#user-role-form')
Chris@17 42 .drupalRelativeURL('/admin/people/permissions')
Chris@17 43 .perform((client, done) => {
Chris@17 44 Promise.all(
Chris@17 45 permissions.map(
Chris@17 46 permission =>
Chris@17 47 new Promise(resolve => {
Chris@17 48 client.click(
Chris@17 49 `input[name="${machineName}[${permission}]"]`,
Chris@17 50 () => {
Chris@17 51 resolve();
Chris@17 52 },
Chris@17 53 );
Chris@17 54 }),
Chris@17 55 ),
Chris@17 56 ).then(() => {
Chris@17 57 done();
Chris@17 58 });
Chris@17 59 })
Chris@17 60 .submitForm('#user-admin-permissions');
Chris@17 61 }).perform(() => {
Chris@17 62 if (typeof callback === 'function') {
Chris@17 63 callback.call(self, machineName);
Chris@17 64 }
Chris@17 65 });
Chris@17 66
Chris@17 67 return this;
Chris@17 68 };