Best JavaScript code snippet using devicefarmer-stf
DwtTabGroup.js
Source:DwtTabGroup.js
...280 */281DwtTabGroup.prototype.setFocusMember =282function(member, checkEnabled, skipNotify) {283 this.__checkRoot(); 284 if (!this.__checkEnabled(member, checkEnabled)) {285 return false;286 }287 var tg = this.__getTabGroupForMember(member);288 if (tg) {289 this.__currFocusMember = member;290// DBG.println("kbnav", "DwtTabGroup.setFocusMember: current focus member is now " + this.__currFocusMember);291 if (!skipNotify) {292 this.__notifyListeners(this.__currFocusMember);293 }294 return true; 295 }296 return false;297};298/**299 * This method sets and returns the next focus member in this tab group. If there is no next300 * member, sets and returns the first member in the tab group.301 * 302 * @param {boolean} [checkEnabled] if <code>true</code>, get the next enabled member303 * @param {boolean} [skipNotify] if <code>true</code>, notification is not fired. This flag304 * typically set by {@link Dwt} tab management framework when it is calling into this method305 * 306 * @return {DwtControl|HTMLElement} new focus member or <code>null</code> if there is no focus member or if the focus307 * member has not changed (i.e. only one member in the tabgroup)308 *309 * @throws DwtTabGroup.NOT_ROOT_TABGROUP310 */311DwtTabGroup.prototype.getNextFocusMember =312function(checkEnabled, skipNotify) {313 this.__checkRoot(); 314 return this.__setFocusMember(true, checkEnabled, skipNotify);315};316/**317 * This method sets and returns the previous focus member in this tab group. If there is no318 * previous member, sets and returns the last member in the tab group.319 * 320 * @param {boolean} [checkEnabled] if <code>true</code>, get the previously enabled member321 * @param {boolean} [skipNotify] if <code>true</code>, notification is not fired. This flag322 * typically set by Dwt tab management framework when it is calling into this method323 * 324 * @return {DwtControl|HTMLElement} new focus member or <code>null</code> if there is no focus member or if the focus325 * member has not changed (i.e. only one member in the tabgroup)326 *327 * @throws DwtTabGroup.NOT_ROOT_TABGROUP328 */329DwtTabGroup.prototype.getPrevFocusMember =330function(checkEnabled, skipNotify) {331 this.__checkRoot(); 332 return this.__setFocusMember(false, checkEnabled, skipNotify);333};334/**335 * Resets the the focus member to the first element in the tab group.336 * 337 * @param {boolean} [checkEnabled] if <code>true</code>, then pick a enabled member to which to set focus338 * @param {boolean} [skipNotify] if <code>true</code>, notification is not fired. This flag339 * typically set by Dwt tab management framework when it is calling into this method340 * 341 * @return {DwtControl|HTMLElement} the new focus member342 *343 * @throws DwtTabGroup.NOT_ROOT_TABGROUP344 */345DwtTabGroup.prototype.resetFocusMember =346function(checkEnabled, skipNotify) {347 this.__checkRoot();348 var focusMember = this.__getLeftMostMember(checkEnabled);349 if ((focusMember != this.__currFocusMember) && !skipNotify) {350 this.__notifyListeners(this.__currFocusMember);351 }352// DBG.println("kbnav", "DwtTabGroup.resetFocusMember: current focus member is now " + this.__currFocusMember);353 this.__currFocusMember = focusMember;354 355 return this.__currFocusMember;356};357DwtTabGroup.prototype.blockDefaultHandling =358function(block) {359 this.__blockDefaultHandling = blockDefaultHandling;360};361DwtTabGroup.prototype.isDefaultHandlingBlocked =362function(block) {363 return this.__blockDefaultHandling;364};365/**366 * Dumps the contents of the tab group.367 * 368 * @private369 */370DwtTabGroup.prototype.dump =371function(debugLevel) {372 if (!window.AjxDebug && window.DBG) { return; }373 this.__dump(this, debugLevel);374};375/**376 * Gets the size of the group.377 * 378 * @return {number} the size379 */380DwtTabGroup.prototype.size =381function() {382 return this.__members.size();383};384/**385 * Returns the previous member in the tag group.386 * 387 * @private388 */389DwtTabGroup.prototype.__getPrevMember =390function(member, checkEnabled) {391 var a = this.__members.getArray();392 // Start working from the member to the immediate left, then keep going left393 for (var i = this.__members.indexOf(member) - 1; i > -1; i--) {394 var prevMember = a[i];395 /* if sibling is not a tab group, then it is the previous child. If the396 * sibling is a tab group, get its rightmost member.*/397 if (!(prevMember instanceof DwtTabGroup)) {398 if (this.__checkEnabled(prevMember, checkEnabled)) {399 return prevMember;400 }401 } else {402 prevMember = prevMember.__getRightMostMember(checkEnabled);403 if (prevMember && this.__checkEnabled(prevMember, checkEnabled)) {404 return prevMember;405 }406 }407 }408 /* If we have fallen through to here it is because the tab group only has 409 * one member. So we roll up to the parent, unless we are at the root in 410 * which case we return null. */411 return this.__parent ? this.__parent.__getPrevMember(this, checkEnabled) : null;412};413/**414 * Returns true if the given member can accept focus, or if there is no need to check.415 * If we are checking, the member must be enabled and visible if it is a control, and416 * enabled otherwise. A member may also set the "noTab" flag to take itself out of the417 * tab hierarchy.418 * 419 * @private420 */421DwtTabGroup.prototype.__checkEnabled =422function(member, checkEnabled) {423 if (!checkEnabled) return true;424 if (!member || member.noTab) return false;425 if (member instanceof DwtControl) {426 return (member.getEnabled() && member.getVisible());427 } else {428 return !member.disabled && Dwt.getVisible(member);429 }430};431/**432 * Sets and returns the next member in the tag group.433 * 434 * @private435 */436DwtTabGroup.prototype.__getNextMember =437function(member, checkEnabled) {438 var a = this.__members.getArray();439 var sz = this.__members.size();440 // Start working from the member to the immediate left of <member> rightwards441 for (var i = this.__members.indexOf(member) + 1; i < sz; i++) {442 var nextMember = a[i];443 /* if sibling is not a tab group, then it is the next child. If the444 * sibling is a tab group, get its leftmost member.*/445 if (!(nextMember instanceof DwtTabGroup)) {446 if (this.__checkEnabled(nextMember, checkEnabled)) {447 return nextMember;448 }449 } else {450 nextMember = nextMember.__getLeftMostMember(checkEnabled);451 if (nextMember && this.__checkEnabled(nextMember, checkEnabled)) {452 return nextMember;453 }454 }455 }456 /* If we have fallen through to here it is because the tab group only has 457 * one member or we are at the end of the list. So we roll up to the parent, 458 * unless we are at the root in which case we return null. */459 return this.__parent ? this.__parent.__getNextMember(this, checkEnabled) : null;460};461/**462 * Finds the rightmost member of the tab group. Will recurse down463 * into contained tab groups if necessary.464 * @private465 */466DwtTabGroup.prototype.__getRightMostMember =467function(checkEnabled) {468 var a = this.__members.getArray();469 var member = null;470 471 /* Work backwards from the rightmost member. If the member is a tab group, then472 * recurse into it. If member is not a tab group, return it as it is the 473 * rightmost element. */474 for (var i = this.__members.size() - 1; i >= 0; i--) {475 member = a[i]476 if (!(member instanceof DwtTabGroup)) {477 if (this.__checkEnabled(member, checkEnabled)) break;478 } else {479 member = member.__getRightMostMember(checkEnabled);480 if (member && this.__checkEnabled(member, checkEnabled)) break;481 }482 }483 return (member && this.__checkEnabled(member, checkEnabled)) ? member : null;484};485/**486 * Finds the rightmost member of the tab group. Will recurse down487 * into contained tab groups if necessary.488 * @private489 */490DwtTabGroup.prototype.__getLeftMostMember =491function(checkEnabled) {492 var sz = this.__members.size();493 var a = this.__members.getArray();494 var member = null;495 /* Work forwards from the leftmost member. If the member is a tabgroup, then496 * recurse into it. If member is not a tabgroup, return it as it is the 497 * rightmost element */498 for (var i = 0; i < sz; i++) {499 member = a[i]500 if (!(member instanceof DwtTabGroup)) {501 if (this.__checkEnabled(member, checkEnabled)) break;502 } else {503 member = member.__getLeftMostMember(checkEnabled);504 if (member && this.__checkEnabled(member, checkEnabled)) break;505 }506 }507 return (member && this.__checkEnabled(member, checkEnabled)) ? member : null;508};509/**510 * Notifies focus change listeners.511 * @private512 */513DwtTabGroup.prototype.__notifyListeners =514function(newFocusMember) {515 // Only the root tab group will issue notifications516 var rootTg = this.__getRootTabGroup();517 if (rootTg.__evtMgr) {518 var evt = DwtTabGroup.__changeEvt;519 evt.reset();520 evt.tabGroup = this;521 evt.newFocusMember = newFocusMember;...
tabsHeader-accessibility.js
Source:tabsHeader-accessibility.js
...6describe('Rules: '+ruldId, function(){7 it('tabsHeader element without "aria-orientation" attribute with "horizontal" value should result in an error', function(){8 var code = `<ul class="tabs-navigation" role="tablist" data-bind="foreach: containersList">9 <li class="item">10 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 11 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>12 </a>13 </li>14 </ul>`;15 var messages = HTMLHint.verify(code, ruleOptions);16 expect(messages.length).to.be(1);17 });18 it('tabsHeader element with "aria-orientation" attribute with "horizontal" value should not result in an error', function(){19 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">20 <li class="item">21 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 22 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>23 </a>24 </li>25 </ul>`;26 var messages = HTMLHint.verify(code, ruleOptions);27 expect(messages.length).to.be(0);28 });29 it('tabsHeader element without "role" attribute with "tablist" value should result in an error', function(){30 var code = `<ul class="tabs-navigation" aria-orientation="horizontal" data-bind="foreach: containersList">31 <li class="item">32 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 33 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>34 </a>35 </li>36 </ul>`;37 var messages = HTMLHint.verify(code, ruleOptions);38 expect(messages.length).to.be(1);39 });40 it('tabsHeader element with "role" attribute with "tablist" value should not result in an error', function(){41 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">42 <li class="item">43 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 44 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>45 </a>46 </li>47 </ul>`;48 var messages = HTMLHint.verify(code, ruleOptions);49 expect(messages.length).to.be(0);50 });51 it('in tabsHeader li element with "data-bind" attribute should result in an error', function(){52 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">53 <li class="item" data-bind="moveToContainer: $data ,css:{'active-tab': $parent.isCurrentContainer(name)}"> 54 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span> 55 </li>56 </ul>`;57 var messages = HTMLHint.verify(code, ruleOptions);58 expect(messages.length).to.be(1);59 });60 it('in tabsHeader li element without "data-bind" attribute should not result in an error', function(){61 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">62 <li class="item">63 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 64 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>65 </a>66 </li>67 </ul>`;68 var messages = HTMLHint.verify(code, ruleOptions);69 expect(messages.length).to.be(0);70 });71 it('in tabsHeader A element without "role" attribute with "tab" value should result in an error', function(){72 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">73 <li class="item">74 <a href="#" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 75 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>76 </a>77 </li>78 </ul>`;79 var messages = HTMLHint.verify(code, ruleOptions);80 expect(messages.length).to.be(1);81 });82 it('in tabsHeader A element with "role" attribute with "tab" value should not result in an error', function(){83 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">84 <li class="item">85 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 86 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>87 </a>88 </li>89 </ul>`;90 var messages = HTMLHint.verify(code, ruleOptions);91 expect(messages.length).to.be(0);92 });93 it('in tabsHeader A element without "href" attribute with "#" value should result in an error', function(){94 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">95 <li class="item">96 <a role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 97 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>98 </a>99 </li>100 </ul>`;101 var messages = HTMLHint.verify(code, ruleOptions);102 expect(messages.length).to.be(1);103 });104 it('in tabsHeader A element with "href" attribute with "#" value should not result in an error', function(){105 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">106 <li class="item">107 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 108 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>109 </a>110 </li>111 </ul>`;112 var messages = HTMLHint.verify(code, ruleOptions);113 expect(messages.length).to.be(0);114 });115 116 it('in tabsHeader A element without "activateTab" value in data-bind attribute should result in an error', function(){117 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">118 <li class="item">119 <a href="#" role="tab" data-bind="moveToContainer: $data, css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 120 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>121 </a>122 </li>123 </ul>`;124 var messages = HTMLHint.verify(code, ruleOptions);125 expect(messages.length).to.be(1);126 });127 it('in tabsHeader A element with "activateTab" value in data-bind attribute should not result in an error', function(){128 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">129 <li class="item">130 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 131 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>132 </a>133 </li>134 </ul>`;135 var messages = HTMLHint.verify(code, ruleOptions);136 expect(messages.length).to.be(0);137 });138 it('in tabsHeader A element without "aria-selected" value in data-bind attribute should result in an error', function(){139 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">140 <li class="item">141 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-controls':('tabpanel_' + name())}"> 142 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>143 </a>144 </li>145 </ul>`;146 var messages = HTMLHint.verify(code, ruleOptions);147 expect(messages.length).to.be(1);148 });149 it('in tabsHeader A element with "aria-selected" value in data-bind attribute should not result in an error', function(){150 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">151 <li class="item">152 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 153 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>154 </a>155 </li>156 </ul>`;157 var messages = HTMLHint.verify(code, ruleOptions);158 expect(messages.length).to.be(0);159 });160 161 it('in tabsHeader A element with "aria-controls" value in data-bind attribute should result in an error', function(){162 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">163 <li class="item">164 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name)}"> 165 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>166 </a>167 </li>168 </ul>`;169 var messages = HTMLHint.verify(code, ruleOptions);170 expect(messages.length).to.be(1);171 });172 it('in tabsHeader A element with "aria-controls" value in data-bind attribute should not result in an error', function(){173 var code = `<ul class="tabs-navigation" role="tablist" aria-orientation="horizontal" data-bind="foreach: containersList">174 <li class="item">175 <a href="#" role="tab" data-bind="moveToContainer: $data ,activateTab:$parent.isCurrentContainer(name), css:{'active-tab': $parent.isCurrentContainer(name),'disable': !checkEnabled()}, attr: { 'disabled': !checkEnabled(),'aria-selected':$parent.isCurrentContainer(name),'aria-controls':('tabpanel_' + name())}"> 176 <span class="num" data-bind="text: $index()+1"></span><span class="title" data-bind="text: text "></span>177 </a>178 </li>179 </ul>`;180 var messages = HTMLHint.verify(code, ruleOptions);181 expect(messages.length).to.be(0);182 });...
memoryAdapter.test.js
Source:memoryAdapter.test.js
...149 next();150 });151 });152 it('should return disable if a group does not exist', function(done) {153 checkEnabled(fakeFeatureKey, groupKey, groupMemberAdmin, false, done);154 });155 it('should allow to register a group and default to enabled', function(done) {156 adapter.registerGroup(featureKey, groupKey, groupProp, groupValue, function(err) {157 expect(err).not.to.be.ok();158 async.parallel([159 checkEnabled(featureKey, groupKey, groupMemberAdmin, true),160 checkEnabled(featureKey, groupKey, groupMemberNonAdmin, false)161 ], function(err) {162 expect(err).not.to.be.ok();163 done();164 });165 });166 });167 it('should do nothing when trying to enable a feature that is already enabled', function(done) {168 adapter.enableGroup(featureKey, groupKey, function(err) {169 expect(err).not.to.be.ok();170 done();171 });172 });173 it('should disable a feature', function(done) {174 var test = function(next) {175 adapter.disableGroup(featureKey, groupKey, next);176 };177 async.series([178 checkEnabled(featureKey, groupKey, groupMemberAdmin, true),179 test,180 checkEnabled(featureKey, groupKey, groupMemberAdmin, false)181 ], function(err) {182 expect(err).not.to.be.ok();183 done();184 });185 });186 it('should enable a feature if a feature is disabled', function(done) {187 var test = function(next) {188 adapter.enableGroup(featureKey, groupKey, next);189 };190 async.series([191 checkEnabled(featureKey, groupKey, groupMemberAdmin, false),192 test,193 checkEnabled(featureKey, groupKey, groupMemberAdmin, true)194 ], function(err) {195 expect(err).not.to.be.ok();196 done();197 });198 });199 it('should return enabled if a boolean gate exist for the feature even if the group is disabled', function(done) {200 var disableGroup = function(next) {201 adapter.disableGroup(featureKey, groupKey, next);202 };203 var enableGroup = function(next) {204 adapter.enableGroup(featureKey, groupKey, next);205 };206 async.series([207 disableGroup,208 checkFeatureEnabled(featureKey, true),209 enableGroup210 ], function(err) {211 expect(err).not.to.be.ok();212 done();213 });214 });215 it('should return disabled if a boolean gate exist for the feature even if the group is enabled', function(done) {216 var enableFeature = function(next) {217 adapter.enable(featureKey, next);218 };219 var disableFeature = function(next) {220 adapter.disable(featureKey, next);221 };222 var enableGroup = function(next) {223 adapter.enableGroup(featureKey, groupKey, next);224 };225 async.series([226 enableGroup,227 disableFeature,228 checkFeatureEnabled(featureKey, false),229 enableFeature230 ], function(err) {231 expect(err).not.to.be.ok();232 done();233 });234 });235 });236 describe('user', function() {237 var allowedUser = {238 id: 1239 };240 var nonAllowedUser = {241 id: 5242 };243 var allowedUserKey = usersGenerator.generateKey(allowedUser);244 var nonAllowedUserKey = usersGenerator.generateKey(nonAllowedUser);245 var checkEnabled = _.curry(function(key, userKey, shouldBeEnabled, next) {246 adapter.isEnabledForUser(featureKey, userKey, function(err, enabled) {247 expect(err).not.to.be.ok();248 expect(enabled).to.be(shouldBeEnabled);249 next();250 });251 });252 it('should return disable if a user has not been added', function(done) {253 checkEnabled(fakeFeatureKey, allowedUserKey, false, done);254 });255 it('should allow to register a user and default to enabled', function(done) {256 adapter.registerUser(featureKey, allowedUserKey, function(err) {257 expect(err).not.to.be.ok();258 async.parallel([259 checkEnabled(featureKey, allowedUserKey, true),260 checkEnabled(featureKey, nonAllowedUserKey, false)261 ], function(err) {262 expect(err).not.to.be.ok();263 done();264 });265 });266 });267 it('should do nothing when trying to enable a feature that is already enabled', function(done) {268 adapter.registerUser(featureKey, allowedUserKey, function(err) {269 expect(err).not.to.be.ok();270 done();271 });272 });273 it('should disable a feature', function(done) {274 var test = function(next) {275 adapter.disableUser(featureKey, allowedUserKey, next);276 };277 async.series([278 checkEnabled(featureKey, allowedUserKey, true),279 test,280 checkEnabled(featureKey, allowedUserKey, false)281 ], function(err) {282 expect(err).not.to.be.ok();283 done();284 });285 });286 it('should enable a feature if a feature is disabled', function(done) {287 var test = function(next) {288 adapter.enableUser(featureKey, allowedUserKey, next);289 };290 async.series([291 checkEnabled(featureKey, allowedUserKey, false),292 test,293 checkEnabled(featureKey, allowedUserKey, true)294 ], function(err) {295 expect(err).not.to.be.ok();296 done();297 });298 });299 it('should return enabled if a boolean gate exist for the feature even if the group is disabled', function(done) {300 var disableUser = function(next) {301 adapter.disableUser(featureKey, allowedUserKey, next);302 };303 var enableUser = function(next) {304 adapter.enableUser(featureKey, allowedUserKey, next);305 };306 async.series([307 disableUser,...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2var stf = new devicefarmer.STF({3});4stf.checkEnabled('emulator-5554', function (err, enabled) {5if (err) {6console.log(err);7} else {8console.log(enabled);9}10});11var devicefarmer = require('devicefarmer-stf');12var stf = new devicefarmer.STF({13});14stf.checkEnabled('emulator-5554', function (err, enabled) {15if (err) {16console.log(err);17} else {18console.log(enabled);19}20});21var devicefarmer = require('devicefarmer-stf');22var stf = new devicefarmer.STF({23});24stf.checkEnabled('emulator-5554', function (err, enabled) {25if (err) {26console.log(err);27} else {28console.log(enabled);29}30});31var devicefarmer = require('devicefarmer-stf');32var stf = new devicefarmer.STF({33});34stf.checkEnabled('emulator-5554', function (err, enabled) {35if (err) {36console.log(err);37} else {38console.log(enabled);39}40});41var devicefarmer = require('devicefarmer-stf');42var stf = new devicefarmer.STF({43});44stf.checkEnabled('emulator-5554', function (err, enabled) {45if (err) {46console.log(err);47} else {48console.log(enabled);49}50});51var devicefarmer = require('devicefarmer-stf');52var stf = new devicefarmer.STF({53});
Using AI Code Generation
1var device = require('devicefarmer-stf-device');2var adb = require('adbkit');3var client = adb.createClient();4var device = new device.Device(client, 'emulator-5554');5device.checkEnabled(function(err, enabled) {6 if (err) {7 console.log(err);8 }9 console.log(enabled);10});11var device = require('devicefarmer-stf-device');12var adb = require('adbkit');13var client = adb.createClient();14var device = new device.Device(client, 'emulator-5554');15device.disable(function(err) {16 if (err) {17 console.log(err);18 }19});20var device = require('devicefarmer-stf-device');21var adb = require('adbkit');22var client = adb.createClient();23var device = new device.Device(client, 'emulator-5554');24device.enable(function(err) {25 if (err) {26 console.log(err);27 }28});29var device = require('devicefarmer-stf-device');30var adb = require('adbkit');31var client = adb.createClient();32var device = new device.Device(client, 'emulator-5554');33device.getInfo(function(err, info) {34 if (err) {35 console.log(err);36 }37 console.log(info);38});39var device = require('devicefarmer-stf-device');40var adb = require('adbkit');41var client = adb.createClient();42var device = new device.Device(client, 'emulator
Using AI Code Generation
1var DeviceFarmer = require('devicefarmer-stf-client');2var device = new DeviceFarmer.Device(client, 'device_id');3device.checkEnabled(function(err, result) {4 if (err) {5 console.error(err);6 return;7 }8 console.log(result);9});10var DeviceFarmer = require('devicefarmer-stf-client');11var device = new DeviceFarmer.Device(client, 'device_id');12device.checkEnabled(function(err, result) {13 if (err) {14 console.error(err);15 return;16 }17 console.log(result);18});19var DeviceFarmer = require('devicefarmer-stf-client');20var device = new DeviceFarmer.Device(client, 'device_id');21device.checkEnabled(function(err, result) {22 if (err) {23 console.error(err);24 return;25 }26 console.log(result);27});28var DeviceFarmer = require('devicefarmer-stf-client');29var device = new DeviceFarmer.Device(client, 'device_id');30device.checkEnabled(function(err, result) {31 if (err) {32 console.error(err);33 return;34 }35 console.log(result);36});37var DeviceFarmer = require('devicefarmer-stf-client');38var device = new DeviceFarmer.Device(client, 'device_id');39device.checkEnabled(function(err, result) {40 if (err) {41 console.error(err
Using AI Code Generation
1var df = require('devicefarmer-stf');2var device = new df.Device();3device.checkEnabled('deviceID', function(err, status) {4 if (err) {5 console.log("Error: " + err);6 } else {7 console.log("Status: " + status);8 }9});10var df = require('devicefarmer-stf');11var device = new df.Device();12device.checkEnabled('deviceID', function(err, status) {13 if (err) {14 console.log("Error: " + err);15 } else {16 console.log("Status: " + status);17 }18});19var df = require('devicefarmer-stf');20var device = new df.Device();21device.checkEnabled('deviceID', function(err, status) {22 if (err) {23 console.log("Error: " + err);24 } else {25 console.log("Status: " + status);26 }27});28var df = require('devicefarmer-stf');29var device = new df.Device();30device.checkEnabled('deviceID', function(err, status) {31 if (err) {32 console.log("Error: " + err);33 } else {34 console.log("Status: " + status);35 }36});37var df = require('devicefarmer-stf');38var device = new df.Device();39device.checkEnabled('deviceID', function(err, status) {40 if (err) {41 console.log("Error: " + err);42 } else {43 console.log("Status: " + status);44 }45});46var df = require('devicefarmer-stf');47var device = new df.Device();48device.checkEnabled('deviceID', function(err, status) {49 if (err) {50 console.log("Error: " + err);51 } else {52 console.log("Status: " + status);53 }54});
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf-client');2client.checkEnabled('1234567890abcdef').then(function(enabled) {3 console.log('enabled', enabled);4});5var devicefarmer = require('devicefarmer-stf-client');6client.checkEnabled('1234567890abcdef').then(function(enabled) {7 console.log('enabled', enabled);8});9var devicefarmer = require('devicefarmer-stf-client');10client.checkEnabled('1234567890abcdef').then(function(enabled) {11 console.log('enabled', enabled);12});13var devicefarmer = require('devicefarmer-stf-client');14client.checkEnabled('1234567890abcdef').then(function(enabled) {15 console.log('enabled', enabled);16});17var devicefarmer = require('devicefarmer-stf-client');18client.checkEnabled('1234567890abcdef').then(function(enabled) {19 console.log('enabled', enabled);20});21var devicefarmer = require('devicefarmer-stf-client');22client.checkEnabled('1234567890abcdef').then(function(enabled) {23 console.log('enabled', enabled);24});25var devicefarmer = require('devicefarmer-stf-client');26client.checkEnabled('1234567890abcdef').then(function(enabled) {27 console.log('enabled', enabled);28});
Using AI Code Generation
1var client = require('devicefarmer-stf-client');2var stf = new client();3stf.checkEnabled('4d00f4a9e9c5bdf7', function(err, result) {4 console.log(result);5});6{ enabled: false }7{ enabled: true }8{ enabled: false }9{ error: 'Device not found' }10{ error: 'Device not connected' }11{ error: 'Device not authorized' }12{ error: 'Device not available' }13{ error: 'Device not ready' }14{ error: 'Device not present' }15{ error: 'Device not using' }16{ error: 'Device not usable' }17{ error: 'Device not supported' }18{ error: 'Device not online' }19{ error: 'Device not free' }20{ error: 'Device not owned' }21{ error: 'Device not reserved' }22{ error: 'Device not found' }23{ error: 'Device not in use' }
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!