Best JavaScript code snippet using testcafe
roles_test.js
Source:roles_test.js  
...33  describe("ãã¼ã«ç»é²", function(){34    describe("save", function(){35      it("ãã¼ã«åãæå®ãããç»é²ã«å¤±æ", function(done){36        expect(function(){37          new ncmb.Role();38        }).to.throw(Error);39        expect(function(){40          new ncmb.Role({});41        }).to.throw(Error);42        expect(function(){43          new ncmb.Role(undefined);44        }).to.throw(Error);45        expect(function(){46          new ncmb.Role(null);47        }).to.throw(Error);48        expect(function(){49          new ncmb.Role("");50        }).to.throw(Error);51        done();52      });53      context("åå¨ããªããã¼ã«åãæå®ããç»é²ã«æå", function(){54        var newRole = null;55        it("callback ã§åå¾ã§ãã", function(done){56          if(ncmb.stub){57            newRole = new ncmb.Role("new_role_name");58          }else{59            newRole = new ncmb.Role("new_role_name_callback");60          }61          newRole.save(function(err, obj){62            if(err){63              done(err);64            }else{65              expect(obj.objectId).to.exist;66              callback_id = obj.objectId;67              done();68            }69          });70        });71        it("promise ã§åå¾ã§ãã", function(done){72          if(ncmb.stub){73            newRole = new ncmb.Role("new_role_name");74          }else{75            newRole = new ncmb.Role("new_role_name_promise");76          }77          newRole.save()78              .then(function(obj){79                expect(obj.objectId).to.exist;80                promise_id = obj.objectId;81                done();82              })83              .catch(function(err){84                done(err);85              });86        });87      });88      context("åå¨ãããã¼ã«åãæå®ããç»é²ã«å¤±æ", function(){89        var newRole = null;90        var existRole = null;91        before(function(done){92          newRole   = new ncmb.Role("new_exist_role_name");93          existRole = new ncmb.Role("new_exist_role_name");94          if(!ncmb.stub){95            newRole.save()96                   .then(function(){97                     done();98                   })99                   .catch(function(){100                     done(new Error("åå¦çã«å¤±æãã¾ããã"));101                   });102          }else{103            done();104          }105        });106        it("callback ã§åå¾ã§ãã", function(done){107          existRole.save(function(err, obj){108            if(err){109              expect(err).to.be.an.instanceof(Error);110              done();111            }else{112              done(new Error("失æãã¹ã"));113            }114          });115        });116        it("promise ã§åå¾ã§ãã", function(done){117          existRole.save()118              .then(function(obj){119                done(new Error("失æãã¹ã"));120              })121              .catch(function(err){122                expect(err).to.be.an.instanceof(Error);123                done();124              });125        });126      });127    });128  });129  describe("ãã¼ã«æ´æ°", function(){130    describe("update", function(){131      context("åå¨ãããã¼ã«IDãæå®ããæ´æ°ã«æå", function(done){132        var updateRole = null;133        before(function(done){134          updateRole = new ncmb.Role("updated_role_name");135          if(!ncmb.stub){136            updateRole.save()137                      .then(function(obj){138                        expect(obj.objectId).to.exist;139                        done();140                      })141                      .catch(function(){142                        done(new Error("åå¦çã«å¤±æãã¾ããã"));143                      });144          }else{145            updateRole.objectId = "update_role_id"146            done();147          }148        });149        it("callback ã§åå¾ã§ãã", function(done){150          updateRole.update(function(err, obj){151            if(err){152              done(err);153            }else{154              expect(obj.updateDate).to.exist;155              done();156            }157          });158        });159        it("promise ã§åå¾ã§ãã", function(done){160          updateRole.update()161              .then(function(obj){162                expect(obj.updateDate).to.exist;163                done();164              })165              .catch(function(err){166                done(err);167              });168        });169      });170      context("åå¨ããªããã¼ã«IDãæå®ããæ´æ°ã«å¤±æ", function(){171        var noExistRole = null;172        before(function(){173          noExistRole = new ncmb.Role("updated_role_name", {objectId:"no_exist_role_id"});174        });175        it("callback ã§åå¾ã§ãã", function(done){176          noExistRole.update(function(err, obj){177            if(err){178              expect(err.code).to.be.eql('E404001');179              done();180            }else{181              done(new Error("error ãè¿ãããªããã°ãªããªã"));182            }183          });184        });185        it("promise ã§åå¾ã§ãã", function(done){186          noExistRole.update()187              .then(function(obj){188                done(new Error("error ãè¿ãããªããã°ãªããªã"));189              })190              .catch(function(err){191                expect(err).to.be.an.instanceof(Error);192                done();193              });194        });195      });196      context("objectIdããªãå ´åãæ´æ°ã«å¤±æ", function(){197        var noExistRole = null;198        before(function(){199          noExistRole = new ncmb.Role("updated_role_name");200        });201        it("callback ã§åå¾ã§ãã", function(done){202          noExistRole.update(function(err, obj){203            if(err){204              expect(err).to.be.an.instanceof(Error);205              done();206            }else{207              done(new Error("error ãè¿ãããªããã°ãªããªã"));208            }209          });210        });211        it("promise ã§åå¾ã§ãã", function(done){212          noExistRole.update()213              .then(function(obj){214                done(new Error("error ãè¿ãããªããã°ãªããªã"));215              })216              .catch(function(err){217                expect(err).to.be.an.instanceof(Error);218                done();219              });220        });221      });222    });223  });224  describe("ãã¼ã«åé¤", function(){225    describe("delete", function(){226      var roleName = "deleted_role_name";227      context("åå¨ãããã¼ã«åãæå®ããåé¤ã«æåãã¦", function(done){228        var deleteRole = null;229        beforeEach(function(done){230          deleteRole = new ncmb.Role(roleName);231          if(ncmb.stub){232            deleteRole.objectId = "delete_role_id";233            done();234          }else{235            deleteRole.save()236                      .then(function(obj){237                        expect(obj.objectId).to.exist;238                        done();239                      })240                      .catch(function(){241                        done(new Error("åå¦çã«å¤±æãã¾ããã"));242                      });243          }244        });245        it("callback ã§åå¾ã§ãã", function(done){246          deleteRole.delete(function(err, obj){247            if(err){248              done(err);249            }else{250              done();251            }252          });253        });254        it("promise ã§åå¾ã§ãã", function(done){255          deleteRole.delete()256              .then(function(){257                done();258              })259              .catch(function(err){260                done(err);261              });262        });263      });264      context("åå¨ããªãIDãæå®ããåé¤ã«å¤±æãã¦", function(){265        var noExistRole = null;266        before(function(){267          noExistRole = new ncmb.Role(roleName, {objectId: "no_exist_role_id"});268        });269        it("callback ã§åå¾ã§ãã", function(done){270          noExistRole.delete(function(err, obj){271            if(err){272              expect(err).to.be.an.instanceof(Error);273              done();274            }else{275              done(new Error("error ãè¿ãããªããã°ãªããªã"));276            }277          });278        });279        it("promise ã§åå¾ã§ãã", function(done){280          noExistRole.delete()281              .then(function(obj){282                done(new Error("error ãè¿ãããªããã°ãªããªã"));283              })284              .catch(function(err){285                expect(err).to.be.an.instanceof(Error);286                done();287              });288        });289      });290      context("objectIdãè¨å®ããã¦ããªãã¨ããåé¤ã«å¤±æãã¦", function(){291        var noExistRole = null;292        before(function(){293          noExistRole = new ncmb.Role(roleName);294        });295        it("callback ã§åé¤ã¨ã©ã¼ãåå¾ã§ãã", function(done){296          noExistRole.delete(function(err, obj){297            if(err){298              expect(err).to.be.an.instanceof(Error);299              done();300            }else{301              done(new Error("error ãè¿ãããªããã°ãªããªã"));302            }303          });304        });305        it("promise ã§åé¤ã¨ã©ã¼ãåå¾ã§ãã", function(done){306          noExistRole.delete()307              .then(function(obj){308                done(new Error("error ãè¿ãããªããã°ãªããªã"));309              })310              .catch(function(err){311                expect(err).to.be.an.instanceof(Error);312                done();313              });314        });315      });316    });317  });318  describe("åä¼å¡ã®è¿½å ", function(){319    var role = null;320    describe("addUser", function(){321      var user = null;322      var user2 = null;323      before(function(done){324        user = new ncmb.User({userName:userName1, password:userPassword1});325        user2 = new ncmb.User({userName:userName2, password:userPassword2});326        if(!ncmb.stub){327          var acl = new ncmb.Acl();328          acl.setPublicReadAccess(true);329          user.set("acl", acl);330          user2.set("acl", acl);331        }332        user.save()333            .then(function(obj){334              expect(obj.objectId).to.exist;335              belong_user1_id = obj.objectId;336              return user2.save();337            })338            .then(function(obj){339              expect(obj.objectId).to.exist;340              belong_user2_id = obj.objectId;341              done();342            })343            .catch(function(){344              done(new Error("åå¦çã«å¤±æãã¾ããã"));345            });346      })347      context("追å ããã¦ã¼ã¶ãæå®ãã¦ç»é²ããçµæãåå¾ãã", function(){348        it("callback ã§åå¾ã§ãã", function(done){349          if(ncmb.stub){350            role = new ncmb.Role("mainRole");351          }else{352            role = new ncmb.Role("addUserCallback");353          }354          role.addUser(user)355              .save(function(err, obj){356                if(err){357                  done(err);358                }else{359                  expect(obj.objectId).to.exist;360                  add_user_id = obj.objectId;361                  ncmb.User362                      .relatedTo(obj, "belongUser")363                      .fetchAll()364                      .then(function(obj){365                        expect(obj.length).to.be.eql(1);366                        expect(obj[0].userName).to.be.eql(user.userName);367                        done();368                      })369                      .catch(function(err){370                        done(err);371                      });372                }373              });374        });375        it("promise ã§åå¾ã§ãã", function(done){376          if(ncmb.stub){377            role = new ncmb.Role("mainRole");378          }else{379            role = new ncmb.Role("addUserPromise");380          }381          role.addUser(user)382              .save()383              .then(function(obj){384                expect(obj.objectId).to.exist;385                return ncmb.User386                           .relatedTo(obj, "belongUser")387                           .fetchAll();388              })389              .then(function(obj){390                expect(obj.length).to.be.eql(1);391                expect(obj[0].userName).to.be.eql(user.userName);392                done();393              })394              .catch(function(err){395                done(err);396              });397        });398      });399      context("追å ããã¦ã¼ã¶ãé
åã§æå®ãã¦ç»é²ããçµæãåå¾ãã", function(){400        it("callback ã§åå¾ã§ãã", function(done){401          if(ncmb.stub){402            role = new ncmb.Role("mainRole");403          }else{404            role = new ncmb.Role("addUserArrayallback");405          }406          role.addUser([user,user2])407              .save(function(err, obj){408                if(err){409                  done(err);410                }else{411                  expect(obj.objectId).to.exist;412                  ncmb.User413                      .relatedTo(obj, "belongUser")414                      .fetchAll()415                      .then(function(obj){416                        expect(obj.length).to.be.eql(2);417                        done();418                      })419                      .catch(function(err){420                        done(err);421                      });422                }423              });424        });425        it("promise ã§åå¾ã§ãã", function(done){426          if(ncmb.stub){427            role = new ncmb.Role("mainRole");428          }else{429            role = new ncmb.Role("addUserArrayPromise");430          }431          role.addUser([user,user2])432              .save()433              .then(function(obj){434                expect(obj.objectId).to.exist;435                return ncmb.User436                           .relatedTo(obj, "belongUser")437                           .fetchAll();438              })439              .then(function(obj){440                expect(obj.length).to.be.eql(2);441                done();442              })443              .catch(function(err){444                done(err);445              });446        });447      });448      context("追å ããã¦ã¼ã¶ãé£ç¶ã§æå®ãã¦ç»é²ããçµæãåå¾ãã", function(){449        it("callback ã§åå¾ã§ãã", function(done){450          if(ncmb.stub){451            role = new ncmb.Role("mainRole");452          }else{453            role = new ncmb.Role("addMultiUserCallback");454          }455          role.addUser(user)456              .addUser(user2)457              .save(function(err, obj){458                if(err){459                  done(err);460                }else{461                  expect(obj.objectId).to.exist;462                  ncmb.User463                      .relatedTo(obj, "belongUser")464                      .fetchAll()465                      .then(function(obj){466                        expect(obj.length).to.be.eql(2);467                        done();468                      })469                      .catch(function(err){470                        done(err);471                      });472                }473              });474        });475        it("promise ã§åå¾ã§ãã", function(done){476          if(ncmb.stub){477            role = new ncmb.Role("mainRole");478          }else{479            role = new ncmb.Role("addMultiUserPromise");480          }481          role.addUser(user)482              .addUser(user2)483              .save()484              .then(function(obj){485                expect(obj.objectId).to.exist;486                return ncmb.User487                           .relatedTo(obj, "belongUser")488                           .fetchAll();489              })490              .then(function(obj){491                expect(obj.length).to.be.eql(2);492                done();493              })494              .catch(function(err){495                done(err);496              });497        });498      });499    });500  });501  describe("åãã¼ã«ã®è¿½å ", function(){502    var role = null;503    var subrole = null;504    var subrole2 = null;505    describe("addRole", function(){506      before(function(done){507        subrole = new ncmb.Role("subRole");508        subrole2 = new ncmb.Role("subRole2");509        subrole.save()510               .then(function(obj){511                 expect(obj.objectId).to.exist;512                 belong_role1_id = obj.objectId;513                 return subrole2.save();514               })515               .then(function(obj){516                 expect(obj.objectId).to.exist;517                 belong_role2_id = obj.objectId;518                 done();519               })520               .catch(function(){521                 done(new Error("åå¦çã«å¤±æãã¾ããã"));522               });523      });524      context("追å ãããã¼ã«ãæå®ãã¦ç»é²ããçµæãåå¾ãã", function(){525        it("callback ã§åå¾ã§ãã", function(done){526          if(ncmb.stub){527            role = new ncmb.Role("mainRole");528          }else{529            role = new ncmb.Role("addRoleCallback");530          }531          role.addRole(subrole)532              .save(function(err, obj){533                if(err){534                  done(err);535                }else{536                  expect(obj.objectId).to.exist;537                  add_role_id = obj.objectId;538                  ncmb.Role539                  .relatedTo(obj, "belongRole")540                  .fetchAll()541                  .then(function(obj){542                    expect(obj.length).to.be.eql(1);543                    expect(obj[0].roleName).to.be.eql(subrole.roleName);544                    done()545                  })546                  .catch(function(err){547                    done(err);548                  });549                }550              });551        });552        it("promise ã§åå¾ã§ãã", function(done){553          if(ncmb.stub){554            role = new ncmb.Role("mainRole");555          }else{556            role = new ncmb.Role("addRolePromise");557          }558          role.addRole(subrole)559              .save()560              .then(function(obj){561                expect(obj.objectId).to.exist;562                return ncmb.Role563                           .relatedTo(obj, "belongRole")564                           .fetchAll();565              })566              .then(function(obj){567                expect(obj.length).to.be.eql(1);568                expect(obj[0].roleName).to.be.eql(subrole.roleName);569                done()570              })571              .catch(function(err){572                done(err);573              });574        });575      });576      context("追å ããåãã¼ã«ãé
åã§æå®ãã¦ç»é²ããçµæãåå¾ãã", function(){577        it("callback ã§åå¾ã§ãã", function(done){578          if(ncmb.stub){579            role = new ncmb.Role("mainRole");580          }else{581            role = new ncmb.Role("addRoleArrayCallback");582          }583          role.addRole([subrole,subrole2])584              .save(function(err, obj){585                if(err){586                  done(err);587                }else{588                  expect(obj.objectId).to.exist;589                  ncmb.Role590                      .relatedTo(obj, "belongRole")591                      .fetchAll()592                      .then(function(obj){593                        expect(obj.length).to.be.eql(2);594                        done();595                      })596                      .catch(function(err){597                        done(err);598                      });599                }600              });601        });602        it("promise ã§åå¾ã§ãã", function(done){603          if(ncmb.stub){604            role = new ncmb.Role("mainRole");605          }else{606            role = new ncmb.Role("addRoleArrayPromise");607          }608          role.addRole([subrole,subrole2])609              .save()610              .then(function(obj){611                expect(obj.objectId).to.exist;612                return ncmb.Role613                           .relatedTo(obj, "belongRole")614                           .fetchAll();615              })616              .then(function(obj){617                expect(obj.length).to.be.eql(2);618                done();619              })620              .catch(function(err){621                done(err);622              });623        });624      });625      context("追å ããåãã¼ã«ãé£ç¶ã§æå®ãã¦ç»é²ããçµæãåå¾ãã", function(){626        it("callback ã§åå¾ã§ãã", function(done){627          if(ncmb.stub){628            role = new ncmb.Role("mainRole");629          }else{630            role = new ncmb.Role("addMultiRoleCallback");631          }632          role.addRole(subrole)633              .addRole(subrole2)634              .save(function(err, obj){635                if(err){636                  done(err);637                }else{638                  expect(obj.objectId).to.exist;639                  ncmb.Role640                      .relatedTo(obj, "belongRole")641                      .fetchAll()642                      .then(function(obj){643                        expect(obj.length).to.be.eql(2);644                        done();645                      })646                      .catch(function(err){647                        done(err);648                      });649                }650              });651        });652        it("promise ã§åå¾ã§ãã", function(done){653          if(ncmb.stub){654            role = new ncmb.Role("mainRole");655          }else{656            role = new ncmb.Role("addMultiRolePromise");657          }658          role.addRole(subrole)659              .addRole(subrole2)660              .save()661              .then(function(obj){662                expect(obj.objectId).to.exist;663                return ncmb.Role664                           .relatedTo(obj, "belongRole")665                           .fetchAll();666              })667              .then(function(obj){668                expect(obj.length).to.be.eql(2);669                done();670              })671              .catch(function(err){672                done(err);673              });674        });675      });676    });677  });678  describe("åä¼å¡ã®åå¾", function(){679    context("fetchUser", function(){680      context("ãã¼ã«ãæã¤åä¼å¡ãæ¤ç´¢ããçµæã", function(){681        var role = null;682        before(function(){683          role = new ncmb.Role("mainRole");684          if(ncmb.stub){685            role.objectId = "role_id";686          }else{687            role.objectId = add_user_id;688          }689        });690        it("callback ã§åå¾ã§ãã", function(done){691          role.fetchUser(function(err, obj){692                if(err){693                  done(err);694                }else{695                  expect(obj.length).to.be.eql(1);696                  done();697                }698              });699        });700        it("promise ã§åå¾ã§ãã", function(done){701          role.fetchUser()702              .then(function(obj){703                expect(obj.length).to.be.eql(1);704                done();705              })706              .catch(function(err){707                done(err);708              });709        });710      });711    });712  });713  describe("åãã¼ã«ã®åå¾", function(){714    context("fetchRole", function(){715      context("ãã¼ã«ãæã¤åãã¼ã«ãæ¤ç´¢ããçµæã", function(){716        var role = null;717        before(function(){718          role = new ncmb.Role("mainRole");719          if(ncmb.stub){720            role.objectId = "role_id";721          }else{722            role.objectId = add_role_id;723          }724        });725        it("callback ã§åå¾ã§ãã", function(done){726          role.fetchRole(function(err, obj){727                if(err){728                  done(err);729                }else{730                  expect(obj.length).to.be.eql(1);731                  done();732                }733              });734        });735        it("promise ã§åå¾ã§ãã", function(done){736          role.fetchRole()737              .then(function(obj){738                expect(obj.length).to.be.eql(1);739                done();740              })741              .catch(function(err){742                done(err);743              });744        });745      });746    });747  });748  describe("åä¼å¡ã®åé¤", function(){749    var role = null;750    describe("removeUser", function(){751      context("åé¤ããã¦ã¼ã¶ãæå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){752        var user = null;753        before(function(){754          user = new ncmb.User({userName:userName1, password:userPassword1});755          user.objectId = belong_user1_id;756        });757        it("callback ã§åå¾ã§ãã", function(done){758          if(ncmb.stub){759            role = new ncmb.Role("mainRole");760          }else{761            role = new ncmb.Role("removeUserCallback");762          }763          role.addUser(user)764              .save()765              .then(function(obj){766                obj.removeUser(user)767                   .update(function(err, obj){768                     if(err){769                       done(err);770                     }else{771                       expect(obj.updateDate).to.exist;772                       done();773                     }774                   });775              })776              .catch(function(err){777                done(err);778              });779        });780        it("promise ã§åå¾ã§ãã", function(done){781          if(ncmb.stub){782            role = new ncmb.Role("mainRole");783          }else{784            role = new ncmb.Role("removeUserPromise");785          }786          role.addUser(user)787              .save()788              .then(function(obj){789                obj.removeUser(user);790                return obj.update();791              })792              .then(function(obj){793                expect(obj.updateDate).to.exist;794                done();795              })796              .catch(function(err){797                done(err);798              });799        });800      });801      context("åé¤ããã¦ã¼ã¶ãé
åã§æå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){802        var user = null;803        var user2 = null;804        before(function(){805          user = new ncmb.User({userName:userName1, password:userPassword1});806          user2 = new ncmb.User({userName:userName2, password:userPassword2});807          if(!ncmb.stub){808            user.objectId = belong_user1_id;809            user2.objectId = belong_user2_id;810          }811        });812        it("callback ã§åå¾ã§ãã", function(done){813          if(ncmb.stub){814            role = new ncmb.Role("mainRole");815          }else{816            role = new ncmb.Role("removeUserArrayCallback");817          }818          role.addUser([user,user2])819              .save()820              .then(function(obj){821                obj.removeUser([user,user2])822                   .update(function(err, obj){823                     if(err){824                       done(err);825                     }else{826                       expect(obj.updateDate).to.exist;827                       done();828                     }829                   });830              })831              .catch(function(err){832                done(err);833              });834        });835        it("promise ã§åå¾ã§ãã", function(done){836          if(ncmb.stub){837            role = new ncmb.Role("mainRole");838          }else{839            role = new ncmb.Role("removeUserArrayPromise");840          }841          role.addUser([user,user2])842              .save()843              .then(function(obj){844                obj.removeUser([user,user2]);845                return obj.update();846              })847              .then(function(obj){848                expect(obj.updateDate).to.exist;849                done();850              })851              .catch(function(err){852                done(err);853              });854        });855      });856      context("åé¤ããã¦ã¼ã¶ãé£ç¶ã§æå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){857        var user = null;858        var user2 = null;859        before(function(){860          user = new ncmb.User({userName:userName1, password:userPassword1});861          user2 = new ncmb.User({userName:userName2, password:userPassword2});862          user.objectId = belong_user1_id;863          user2.objectId = belong_user2_id;864        });865        it("callback ã§åå¾ã§ãã", function(done){866          if(ncmb.stub){867            role = new ncmb.Role("mainRole");868          }else{869            role = new ncmb.Role("removeMultiUserCallback");870          }871          role.addUser([user,user2])872              .save()873              .then(function(obj){874                obj.removeUser(user)875                   .removeUser(user2)876                   .update(function(err, obj){877                     if(err){878                       done(err);879                     }else{880                       expect(obj.updateDate).to.exist;881                       done();882                     }883                   });884              })885              .catch(function(err){886                done(err);887              });888        });889        it("promise ã§åå¾ã§ãã", function(done){890          if(ncmb.stub){891            role = new ncmb.Role("mainRole");892          }else{893            role = new ncmb.Role("removeMultiUserPromise");894          }895          role.addUser([user,user2])896              .save()897              .then(function(obj){898                obj.removeUser(user)899                   .removeUser(user2);900                return obj.update();901              })902              .then(function(obj){903                expect(obj.updateDate).to.exist;904                done();905              })906              .catch(function(err){907                done(err);908              });909        });910      });911    });912  });913  describe("åãã¼ã«ã®åé¤", function(){914    var role = null;915    describe("removeRole", function(){916      context("åé¤ãããã¼ã«ãæå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){917        var subrole = null;918        before(function(){919          subrole = new ncmb.Role("subRole");920          subrole.objectId = belong_role1_id;921        });922        it("callback ã§åå¾ã§ãã", function(done){923          if(ncmb.stub){924            role = new ncmb.Role("mainRole");925          }else{926            role = new ncmb.Role("removeRoleCallback");927          }928          role.addRole(subrole)929              .save()930              .then(function(obj){931                obj.removeRole(subrole)932                   .update(function(err, obj){933                     if(err){934                       done(err);935                     }else{936                       expect(obj.updateDate).to.exist;937                       done();938                     }939                   });940              })941              .catch(function(err){942                done(err);943              });944        });945        it("promise ã§åå¾ã§ãã", function(done){946          if(ncmb.stub){947            role = new ncmb.Role("mainRole");948          }else{949            role = new ncmb.Role("removeRolePromise");950          }951          role.addRole(subrole)952              .save()953              .then(function(obj){954                obj.removeRole(subrole);955                return obj.update();956              })957              .then(function(obj){958                expect(obj.updateDate).to.exist;959                done();960              })961              .catch(function(err){962                done(err);963              });964        });965      });966      context("åé¤ãããã¼ã«ãé
åã§æå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){967        var subrole = null;968        var subrole2 = null;969        before(function(){970          subrole = new ncmb.Role("subRole");971          subrole2 = new ncmb.Role("subRole2");972          subrole.objectId = belong_role1_id;973          subrole2.objectId = belong_role2_id;974        });975        it("callback ã§åå¾ã§ãã", function(done){976          if(ncmb.stub){977            role = new ncmb.Role("mainRole");978          }else{979            role = new ncmb.Role("removeRoleArrayCallback");980          }981          role.addRole([subrole,subrole2])982              .save()983              .then(function(obj){984                obj.removeRole([subrole,subrole2])985                   .update(function(err, obj){986                     if(err){987                       done(err);988                     }else{989                       expect(obj.updateDate).to.exist;990                       done();991                     }992                   });993              })994              .catch(function(err){995                done(err);996              });997        });998        it("promise ã§åå¾ã§ãã", function(done){999          if(ncmb.stub){1000            role = new ncmb.Role("mainRole");1001          }else{1002            role = new ncmb.Role("removeRoleArrayPromise");1003          }1004          role.addRole([subrole,subrole2])1005              .save()1006              .then(function(obj){1007                obj.removeRole([subrole,subrole2]);1008                return obj.update();1009              })1010              .then(function(obj){1011                expect(obj.updateDate).to.exist;1012                done();1013              })1014              .catch(function(err){1015                done(err);1016              });1017        });1018      });1019      context("åé¤ãããã¼ã«ãé£ç¶ã§æå®ãã¦æ´æ°ããçµæãåå¾ãã", function(){1020        var subrole = null;1021        var subrole2 = null;1022        before(function(){1023          subrole = new ncmb.Role("subRole");1024          subrole2 = new ncmb.Role("subRole2");1025          subrole.objectId = belong_role1_id;1026          subrole2.objectId = belong_role2_id;1027        });1028        it("callback ã§åå¾ã§ãã", function(done){1029          if(ncmb.stub){1030            role = new ncmb.Role("mainRole");1031          }else{1032            role = new ncmb.Role("removeMultiRoleCallback");1033          }1034          role.addRole([subrole,subrole2])1035              .save()1036              .then(function(obj){1037                obj.removeRole(subrole)1038                   .removeRole(subrole2)1039                   .update(function(err, obj){1040                     if(err){1041                       done(err);1042                     }else{1043                       expect(obj.updateDate).to.exist;1044                       done();1045                     }1046                   });1047              })1048              .catch(function(err){1049                done(err);1050              });1051        });1052        it("promise ã§åå¾ã§ãã", function(done){1053          if(ncmb.stub){1054            role = new ncmb.Role("mainRole");1055          }else{1056            role = new ncmb.Role("removeRoleMultiPromise");1057          }1058          role.addRole([subrole,subrole2])1059              .save()1060              .then(function(obj){1061                obj.removeRole(subrole)1062                   .removeRole(subrole2);1063                return obj.update();1064              })1065              .then(function(obj){1066                expect(obj.updateDate).to.exist;1067                done();1068              })1069              .catch(function(err){1070                done(err);1071              });1072        });1073      });1074    });1075  });1076});Roles.test.js
Source:Roles.test.js  
...15    const ROLE = web3.utils.soliditySha3(roleName);16    const OTHER_ROLE = web3.utils.soliditySha3('OTHER_ROLE');17    describe('default admin', function () {18      it('deployer has default admin role', async function () {19        expect(await this.contract.hasRole(DEFAULT_ADMIN_ROLE, admin)).to.equal(true);20      });21      it('other roles\'s admin is the default admin role', async function () {22        expect(await this.contract.getRoleAdmin(ROLE)).to.equal(DEFAULT_ADMIN_ROLE);23      });24      it('default admin role\'s admin is itself', async function () {25        expect(await this.contract.getRoleAdmin(DEFAULT_ADMIN_ROLE)).to.equal(DEFAULT_ADMIN_ROLE);26      });27    });28    describe('granting', function () {29      it('admin can grant role to other accounts', async function () {30        const receipt = await this.contract.grantRole(ROLE, authorized, { from: admin });31        expectEvent(receipt, 'RoleGranted', { account: authorized, role: ROLE, sender: admin });32        expect(await this.contract.hasRole(ROLE, authorized)).to.equal(true);33      });34      it('non-admin cannot grant role to other accounts', async function () {35        await expectRevert(36          this.contract.grantRole(ROLE, authorized, { from: other }),37          'AccessControl: sender must be an admin to grant',38        );39      });40      it('accounts can be granted a role multiple times', async function () {41        await this.contract.grantRole(ROLE, authorized, { from: admin });42        const receipt = await this.contract.grantRole(ROLE, authorized, { from: admin });43        expectEvent.notEmitted(receipt, 'RoleRevoked');44      });45    });46    describe('revoking', function () {47      it('roles that are not had can be revoked', async function () {48        expect(await this.contract.hasRole(ROLE, authorized)).to.equal(false);49        const receipt = await this.contract.revokeRole(ROLE, authorized, { from: admin });50        expectEvent.notEmitted(receipt, 'RoleRevoked');51      });52      context('with granted role', function () {53        beforeEach(async function () {54          await this.contract.grantRole(ROLE, authorized, { from: admin });55        });56        it('admin can revoke role', async function () {57          const receipt = await this.contract.revokeRole(ROLE, authorized, { from: admin });58          expectEvent(receipt, 'RoleRevoked', { account: authorized, role: ROLE, sender: admin });59          expect(await this.contract.hasRole(ROLE, authorized)).to.equal(false);60        });61        it('non-admin cannot revoke role', async function () {62          await expectRevert(63            this.contract.revokeRole(ROLE, authorized, { from: other }),64            'AccessControl: sender must be an admin to revoke',65          );66        });67        it('a role can be revoked multiple times', async function () {68          await this.contract.revokeRole(ROLE, authorized, { from: admin });69          const receipt = await this.contract.revokeRole(ROLE, authorized, { from: admin });70          expectEvent.notEmitted(receipt, 'RoleRevoked');71        });72      });73    });74    describe('renouncing', function () {75      it('roles that are not had can be renounced', async function () {76        const receipt = await this.contract.renounceRole(ROLE, authorized, { from: authorized });77        expectEvent.notEmitted(receipt, 'RoleRevoked');78      });79      context('with granted role', function () {80        beforeEach(async function () {81          await this.contract.grantRole(ROLE, authorized, { from: admin });82        });83        it('bearer can renounce role', async function () {84          const receipt = await this.contract.renounceRole(ROLE, authorized, { from: authorized });85          expectEvent(receipt, 'RoleRevoked', { account: authorized, role: ROLE, sender: authorized });86          expect(await this.contract.hasRole(ROLE, authorized)).to.equal(false);87        });88        it('only the sender can renounce their roles', async function () {89          await expectRevert(90            this.contract.renounceRole(ROLE, authorized, { from: admin }),91            'AccessControl: can only renounce roles for self',92          );93        });94        it('a role can be renounced multiple times', async function () {95          await this.contract.renounceRole(ROLE, authorized, { from: authorized });96          const receipt = await this.contract.renounceRole(ROLE, authorized, { from: authorized });97          expectEvent.notEmitted(receipt, 'RoleRevoked');98        });99      });100    });101    describe('enumerating', function () {102      it('role bearers can be enumerated', async function () {103        await this.contract.grantRole(ROLE, authorized, { from: admin });104        await this.contract.grantRole(ROLE, otherAuthorized, { from: admin });105        const memberCount = await this.contract.getRoleMemberCount(ROLE);106        memberCount.should.be.bignumber.equal('3'); // two added above plus admin107        const bearers = [];108        for (let i = 0; i < memberCount; ++i) {109          bearers.push(await this.contract.getRoleMember(ROLE, i));110        }111        expect(bearers).to.have.members([admin, authorized, otherAuthorized]);112      });113    });114    describe('setting role admin', function () {115      beforeEach(async function () {116        const receipt = await this.contract.setRoleAdmin(ROLE, OTHER_ROLE);117        expectEvent(receipt, 'RoleAdminChanged', {118          role: ROLE,119          previousAdminRole: DEFAULT_ADMIN_ROLE,120          newAdminRole: OTHER_ROLE,121        });122        await this.contract.grantRole(OTHER_ROLE, otherAdmin, { from: admin });123      });124      it('a role\'s admin role can be changed', async function () {125        expect(await this.contract.getRoleAdmin(ROLE)).to.equal(OTHER_ROLE);126      });127      it('the new admin can grant roles', async function () {128        const receipt = await this.contract.grantRole(ROLE, authorized, { from: otherAdmin });129        expectEvent(receipt, 'RoleGranted', { account: authorized, role: ROLE, sender: otherAdmin });130      });131      it('the new admin can revoke roles', async function () {132        await this.contract.grantRole(ROLE, authorized, { from: otherAdmin });133        const receipt = await this.contract.revokeRole(ROLE, authorized, { from: otherAdmin });134        expectEvent(receipt, 'RoleRevoked', { account: authorized, role: ROLE, sender: otherAdmin });135      });136      it('a role\'s previous admins no longer grant roles', async function () {137        await expectRevert(138          this.contract.grantRole(ROLE, authorized, { from: admin }),139          'AccessControl: sender must be an admin to grant',140        );141      });142      it('a role\'s previous admins no longer revoke roles', async function () {143        await expectRevert(144          this.contract.revokeRole(ROLE, authorized, { from: admin }),145          'AccessControl: sender must be an admin to revoke',146        );147      });148    });149    describe('testing modifier', function () {150      beforeEach(async function () {151        await this.contract.grantRole(ROLE, authorized, { from: admin });152      });153      context('from authorized account', function () {154        const from = authorized;155        it('allows access', async function () {156          await this.contract[`only${roleName}Mock`]({ from });157        });158      });159      context('from unauthorized account', function () {160        const from = other;161        it('reverts', async function () {162          await expectRevert(163            this.contract[`only${roleName}Mock`]({ from }),164            `Roles: caller does not have the ${roleName} role`,165          );...utils.test.js
Source:utils.test.js  
...326    id: '1',327    role: 'AccountAdmin',328    base_role_type: 'AccountMembership'329  }330  expect(roleIsCourseBaseRole(accountBaserole)).toBeFalsy()331  expect(roleIsBaseRole(accountBaserole)).toBeTruthy()...automation_predicate.js
Source:automation_predicate.js  
...32    return node.role == role;33  };34};35/** @type {AutomationPredicate.Unary} */36AutomationPredicate.checkBox = AutomationPredicate.withRole(RoleType.CHECK_BOX);37/** @type {AutomationPredicate.Unary} */38AutomationPredicate.comboBox = AutomationPredicate.withRole(RoleType.COMBO_BOX);39/** @type {AutomationPredicate.Unary} */40AutomationPredicate.heading = AutomationPredicate.withRole(RoleType.HEADING);41/** @type {AutomationPredicate.Unary} */42AutomationPredicate.inlineTextBox =43    AutomationPredicate.withRole(RoleType.INLINE_TEXT_BOX);44/** @type {AutomationPredicate.Unary} */45AutomationPredicate.link = AutomationPredicate.withRole(RoleType.LINK);46/** @type {AutomationPredicate.Unary} */47AutomationPredicate.table = AutomationPredicate.withRole(RoleType.TABLE);48/**49 * @param {!AutomationNode} node50 * @return {boolean}51 */52AutomationPredicate.button = function(node) {53  return /button/i.test(node.role);54};55/**56 * @param {!AutomationNode} node57 * @return {boolean}58 */59AutomationPredicate.editText = function(node) {60  return node.state.editable && node.parent && !node.parent.state.editable;61};...roles.js
Source:roles.js  
1import * as actionTypes from './actionTypes';2import axios from '../../server/axios-server';3//////////////////// Create ////////////////////4export const createRoleStart = () => {5	return {6		type: actionTypes.CREATE_ROLE7	};8};9export const createRoleSuccess = (message, role) => {10	return {11		type: actionTypes.CREATE_ROLE_SUCCESS,12		message: message,13		role: role14	};15};16export const createRoleFail = (error) => {17	return {18		type: actionTypes.CREATE_ROLE_FAIL,19		error: error20	};21};22export const createRole = (name, label) => {	23	return dispatch => {24		dispatch(createRoleStart());25		axios.post('/createRole', { name: name, label: label })26 			.then(res => {27				dispatch(createRoleSuccess(res.data.message, res.data.data));28			})29			.catch(err => {30				dispatch(createRoleFail(err));31			})32	};33};34//////////////////// Delete ////////////////////35export const deleteRoleStart = () => {36	return {37		type: actionTypes.DELETE_ROLE38	};39};40export const deleteRoleSuccess = (message, role) => {41	return {42		type: actionTypes.DELETE_ROLE_SUCCESS,43		message: message,44		roleId: roleId45	};46};47export const deleteRoleFail = (error) => {48	return {49		type: actionTypes.DELETE_ROLE_FAIL,50		error: error51	};52};53export const deleteRole = (roleId) => {54	return dispatch => {55		dispatch(deleteRoleStart());56		axios.post('/deleteRole', { roleId: roleId })57 			.then(res => {58				dispatch(deleteRoleSuccess(res.data.message, res.data.data));59			})60			.catch(err => {61				dispatch(deleteRoleFail(err));62			})63	};64};65//////////////////// Fetch One ////////////////////66export const fetchRoleStart = () => {67	return {68		type: actionTypes.FETCH_ROLE69	};70};71export const fetchRoleSuccess = (message, role) => {72	return {73		type: actionTypes.FETCH_ROLE_SUCCESS,74		message: message,75		role: role76	};77};78export const fetchRoleFail = (error) => {79	return {80		type: actionTypes.FETCH_ROLE_FAIL,81		error: error82	};83};84export const fetchRole = (roleId) => {85	return dispatch => {86		dispatch(fetchRoleStart());87		axios.get('/getRole?roleId=' + roleId)88 			.then(res => {89				dispatch(fetchRoleSuccess(res.data.message, res.data.data));90			})91			.catch(err => {92				dispatch(fetchRoleFail(err));93			})94	};95};96//////////////////// Fetch Some ////////////////////97export const fetchRolesStart = () => {98	return {99		type: actionTypes.FETCH_ROLES100	};101};102export const fetchRolesSuccess = (message, roles) => {103	return {104		type: actionTypes.FETCH_ROLES_SUCCESS,105		message: message,106		roles: roles107	};108};109export const fetchRolesFail = (error) => {110	return {111		type: actionTypes.FETCH_ROLES_FAIL,112		error: error113	};114};115export const fetchRoles = (page, perPage) => {116	return dispatch => {117		dispatch(fetchRolesStart());118		axios.get('/getRoles?page=' + page + '&perPage=' + perPage)119 			.then(res => {120				dispatch(fetchRolesSuccess(res.data.message, res.data.data));121			})122			.catch(err => {123				dispatch(fetchRolesFail(err));124			})125	};126};127//////////////////// Find Role by Name ////////////////////128export const findRoleByNameStart = () => {129	return {130		type: actionTypes.FIND_ROLE_BY_NAME131	};132};133export const findRoleByNameSuccess = (message, role) => {134	return {135		type: actionTypes.FIND_ROLE_BY_NAME_SUCCESS,136		message: message,137		role: role138	};139};140export const findRoleByNameFail = (error) => {141	return {142		type: actionTypes.FIND_ROLE_BY_NAME_FAIL,143		error: error144	};145};146export const findRoleByName = (name) => {147	return dispatch => {148		dispatch(findRoleByNameStart());149		axios.get('/findRoleByName?name=' + name)150 			.then(res => {151				dispatch(findRoleByNameSuccess(res.data.message, res.data.data));152			})153			.catch(err => {154				dispatch(findRoleByNameFail(err));155			})156	};157};158//////////////////// Find Role by Label ////////////////////159export const findRoleByLabelStart = () => {160	return {161		type: actionTypes.FIND_ROLE_BY_LABEL162	};163};164export const findRoleByLabelSuccess = (message, role) => {165	return {166		type: actionTypes.FIND_ROLE_BY_LABEL_SUCCESS,167		message: message,168		role: role169	};170};171export const findRoleByLabelFail = (error) => {172	return {173		type: actionTypes.FIND_ROLE_BY_LABEL_FAIL,174		error: error175	};176};177export const findRoleByLabel = (label) => {178	return dispatch => {179		dispatch(findRoleByLabelStart());180		axios.get('/findRoleByLabel?label=' + label)181 			.then(res => {182				dispatch(findRoleByLabelSuccess(res.data.message, res.data.data));183			})184			.catch(err => {185				dispatch(findRoleByLabelFail(err));186			})187	};188};189//////////////////// Add SubRole to Role ////////////////////190export const addSubRoleToRoleStart = () => {191	return {192		type: actionTypes.ADD_SUBROLE_TO_ROLE_START193	};194};195export const addSubRoleToRoleSuccess = (message, role) => {196	return {197		type: actionTypes.ADD_SUBROLE_TO_ROLE_SUCCESS,198		message: message,199		role: role200	};201};202export const addSubRoleToRoleFail = (error) => {203	return {204		type: actionTypes.ADD_SUBROLE_TO_ROLE_FAIL,205		error: error206	};207};208export const addSubRoleToRole = (roleId, subRoleId) => {209	return dispatch => {210		dispatch(addSubRoleToRoleStart());211		axios.post('/addSubRoleToRole', { roleId: roleId, subRoleId: subRoleId})212 			.then(res => {213				dispatch(addSubRoleToRoleSuccess(res.data.message, res.data.data));214			})215			.catch(err => {216				dispatch(addSubRoleToRoleFail(err));217			})218	};219};220//////////////////// Remove SubRole from Role ////////////////////221export const removeSubRoleFromRoleStart = () => {222	return {223		type: actionTypes.REMOVE_SUBROLE_FROM_ROLE_START224	};225};226export const removeSubRoleFromRoleSuccess = (message, role) => {227	return {228		type: actionTypes.REMOVE_SUBROLE_FROM_ROLE_SUCCESS,229		message: message,230		role: role231	};232};233export const removeSubRoleFromRoleFail = (error) => {234	return {235		type: actionTypes.REMOVE_SUBROLE_FROM_ROLE_FAIL,236		error: error237	};238};239export const removeSubRoleFromRole = (roleId, subRoleId) => {240	return dispatch => {241		dispatch(removeSubRoleFromRoleStart());242		axios.post('/removeSubRoleFromRole', { roleId: roleId, subRoleId: subRoleId})243 			.then(res => {244				dispatch(removeSubRoleFromRoleSuccess(res.data.message, res.data.data));245			})246			.catch(err => {247				dispatch(removeSubRoleFromRoleFail(err));248			})249	};...UserRepository.js
Source:UserRepository.js  
...91        if (roleIndex !== -1) {92            throw Error("Role existed");93        }94        RoleRepository.findRoleById(roleId).then(role => {95            user.addRole(role);96            user.save();97            return user;98        });99    });100}101exports.removeUserRole = (userId, roleId) => {102    return User.findOne({include: Role, where: {id: userId}}).then(user => {103        const roleIndex = user.roles.findIndex(role => role.id === roleId);104        if (roleIndex === -1) {105            throw Error("Role is not associated to the user");106        }107        user.removeRole(user.roles[roleIndex]);108        user.save();109        return user;110    });111}112exports.updateUserVerificationHashByEmail = (email, verification_hash) => {113    return User.findOne(114        {where: {email: email}}).then(user => {115        user.verification_hash = verification_hash;116        user.save();117        return user;118    });119}120exports.updatePasswordByEmail = (email, password) => {121    return User.findOne({where: {email: email}}).then(user => {...utils.js
Source:utils.js  
...42    (roleOne.base_role_type === roleTwo.base_role_type &&43      parseInt(roleOne.id, 10) <= parseInt(roleTwo.id, 10))44  )45}46export function roleIsBaseRole(role) {47  return roleIsCourseBaseRole(role) || role.role === 'AccountAdmin'48}49export function roleIsCourseBaseRole(role) {50  return role.role === role.base_role_type51}52/*53 * Takes a list of roles and a role to role to insert into the list54 *55 * @returns56 * List of sorted roles57 */58export function roleSortedInsert(roles, roleToInsert) {59  const orderedRoles = roles.slice()60  const index = orderedRoles.findIndex(baseRole => baseRole.role === roleToInsert.base_role_type)61  // Get the role of the matched index62  let nextIndex = index + 163  let nextRole = orderedRoles[nextIndex]64  // Runs as long as there is another role in the array65  // and the role matches the role we are checking66  while (nextRole) {67    if (roleComparisonFunction(roleToInsert, nextRole)) {68      // if role to be placed needs to be before the currentRole we push69      // everything over70      orderedRoles.splice(nextIndex, 0, roleToInsert)71      return orderedRoles72    } else {73      nextIndex++74      nextRole = orderedRoles[nextIndex]75    }76  }77  orderedRoles.splice(nextIndex, 0, roleToInsert)78  return orderedRoles79}80/*81 * Sorts an array of roles based on role type82 */83export function getSortedRoles(roles, accountAdmin) {84  const nonBaseRoles = roles.filter(role => !roleIsBaseRole(role))85  let orderedRoles = roles.filter(roleIsBaseRole) // Grabs all the base roles for the start86  nonBaseRoles.forEach(roleToBePlaced => {87    orderedRoles = roleSortedInsert(orderedRoles, roleToBePlaced)88  })89  // Make sure Account Admin is always the first-displayed role90  if (typeof accountAdmin !== 'undefined') {91    orderedRoles.splice(orderedRoles.indexOf(accountAdmin), 1)92    orderedRoles.unshift(accountAdmin)93  }94  return orderedRoles...role-manager.js
Source:role-manager.js  
...9	req.addRole = function(role) {10		if (_.isArray(role)) {11			role.forEach(12				function(item) {13					req.addRole(item);14				}15			)16		} else if (_.indexOf(req.currentRoles, role) === -1) {17			req.currentRoles.push(role);18		}19	};20	/**21	 * Remove a current requester role22	 * @param role23	 */24	req.removeRole = function(role) {25		let index =_.indexOf(req.currentRoles, req.role);26		if (index !== -1) {27			req.currentRoles.splice(index, 1);28		}29	};30	/**31	 * Add one or more roles allowed for this request32	 * @param role33	 */34	req.allowRole = function(role) {35		if (_.isString(role)) {36			if (_.indexOf(req.allowedRoles, role) === -1) {37				req.allowedRoles.push(role);38			}39		} else if (_.isArray(role)) {40			role.forEach(41				function(item) {42					req.allowRole(item);43				}44			)45		}46	};47	/**48	 * Remove an allowed role from this request49	 * @param role50	 */51	req.disallowRole = function (role) {52		let index =_.indexOf(req.allowedRoles, req.role);53		if (index !== -1) {54			req.allowedRoles.splice(index, 1);55		}56	};...Using AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#login', 'TestUser')3        .typeText('#password', 'testpass')4        .click('#sign-in');5});6test('My test', async t => {7        .useRole(regularUser)8        .click('#some-button');9});10import { Role } from 'testcafe';11        .typeText('#login', 'TestUser')12        .typeText('#password', 'testpass')13        .click('#sign-in');14});15test('My test', async t => {16        .useRole(regularUser)17        .click('#some-button');18});19import { Role } from 'testcafe';20        .typeText('#login', 'TestUser')21        .typeText('#password', 'testpass')22        .click('#sign-in');23});24test('Using AI Code Generation
1import { Role } from 'testcafe';2import { Selector } from 'testcafe';3import { ClientFunction } from 'testcafe';4import { RequestLogger } from 'testcafe';5import { RequestMock } from 'testcafe';6import { RequestHook } from 'testcafe';7import { RequestLogger } from 'testcafe';8import { RequestMock } from 'testcafe';9import { RequestHook } from 'testcafe';10import { RequestLogger } from 'testcafe';11import { RequestMock } from 'testcafe';12import { RequestHook } from 'testcafe';13import { RequestLogger } from 'testcafe';14import { RequestMock } from 'testcafe';15import { RequestHook } from 'testcafe';16import { RequestLogger } from 'testcafe';17import { RequestMock } from 'testcafe';18import { RequestHook } from 'testcafe';19import { RequestLogger } from 'testcafe';20import { RequestMock } from 'testcafe';21import { RequestHook } from 'testcafe';22import { RequestLogger } from 'testcafe';Using AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#username', 'admin')3        .typeText('#password', 'admin')4        .click('#login');5}, { preserveUrl: true });6test('Login', async t => {7        .useRole(admin)8        .expect(Selector('#login').visible).notOk();9});10import { Role } from 'testcafe';11        .typeText('#username', 'admin')12        .typeText('#password', 'admin')13        .click('#login');14}, { preserveUrl: true });15test('Login', async t => {16        .useRole(admin)17        .expect(Selector('#login').visible).notOk();18});19import { Role } from 'testcafe';20        .typeText('#username', 'admin')21        .typeText('#password', 'admin')22        .click('#login');23}, { preserveUrl: true });24test('Login', async t => {25        .useRole(admin)26        .expect(Selector('#login').visible).notOk();27});28import { Role } from 'testcafe';29        .typeText('#username', 'admin')30        .typeText('#password', 'admin')31        .click('#login');32}, { preserveUrl: true });33test('Login', async t => {34        .useRole(admin)35        .expect(Selector('#login').visible).notOk();Using AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#login', 'admin')3        .typeText('#password', 'admin')4        .click('#sign-in');5});6import { Role } from 'testcafe';7        .typeText('#login', 'admin')8        .typeText('#password', 'admin')9        .click('#sign-in');10});11import { Role } from 'testcafe';12        .typeText('#login', 'admin')13        .typeText('#password', 'admin')14        .click('#sign-in');15});16import { Role } from 'testcafe';17        .typeText('#login', 'admin')18        .typeText('#password', 'admin')19        .click('#sign-in');20});21import { Role } from 'testcafe';22        .typeText('#login', 'admin')23        .typeText('#password', 'admin')24        .click('#sign-in');25});26import { Role } from 'testcafe';27        .typeText('#login', 'admin')28        .typeText('#password', 'admin')29        .click('#sign-in');30});31import { Role } from 'testcafe';32        .typeText('#login', 'admin')33        .typeText('#password', 'admin')34        .click('#signUsing AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#username', 'username')3        .typeText('#password', 'password')4        .click('#login');5});6import { ClientFunction } from 'testcafe';7const getLocation = ClientFunction(() => document.location.href);8import { Selector } from 'testcafe';9const usernameInput = Selector('#username');10const passwordInput = Selector('#password');11const loginButton = Selector('#login');12test('Login Test', async t => {13        .useRole(userRole)14        .expect(usernameInput.exists).notOk()15        .expect(passwordInput.exists).notOk()16        .expect(loginButton.exists).notOk();17});18 1 failed (1s)19          1 |import { Role } from 'testcafe';20          4 |        .typeText('#username', 'username')21          5 |        .typeText('#password', 'password')22          6 |        .click('#login');23          7 |});24          8 |import { ClientFunction } from 'testcafe';25          9 |const getLocation = ClientFunction(() => document.location.href);Using AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#username', 'admin')3        .typeText('#password', 'admin')4        .click('#loginButton');5}, { preserveUrl: true });6import { ClientFunction } from 'testcafe';7const getLocation = ClientFunction(() => document.location.href);8test('My first test', async t => {9        .useRole(login)10});Using AI Code Generation
1import { Role } from 'testcafe';2        .typeText('#username', 'admin')3        .typeText('#password', 'password')4        .click('#login-button');5}, { preserveUrl: true });6test('My first test', async t => {7        .useRole(adminRole)8        .click('#some-button')9        .expect(Selector('#some-element').innerText).eql('some text');10});11import { Role } from 'testcafe';12        .typeText('#username', 'admin')13        .typeText('#password', 'password')14        .click('#login-button');15}, { preserveUrl: true });16test('My first test', async t => {17        .useRole(adminRole)18        .click('#some-button')19        .expect(Selector('#some-element').innerText).eql('some text');20});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!!
