Best JavaScript code snippet using devicefarmer-stf
api.js
Source:api.js
1angular.module('mngr').factory('api',function(data, models, ui, $q, mngrSecureFirebase, md5, $window) {2 var api = {3 link: function (url) {4 $window.location='#'+url;5 },6 bind:function(type, id, scope){7// data[type].fire.$child(id).$bind(scope, type+id);8 },9 create:function(type, model){10 var defer = $q.defer();11 var date = Date.now();12 model.created = date;13 model.updated = date;14 console.log('create '+type+': '+JSON.stringify(model));15 data[type].fire.$add(model).then(function(result){16 if(model.users){17 // it's added, update all the associated users18 data[type].fire.$addToUsers(result.id, model.users);19 }20 defer.resolve(result);21 }, function(error){ defer.reject(error); });22 return defer.promise;23 },24 save:function(type, id){25 var time = Date.now();26 console.log('At '+time+', saving '+type+ ': '+id);27 var child = data[type].fire.$child(id);28 if(child && child.users) {29 // if there are users in the record, compare the new user value with the one in the db30 // this is so we can adjust the user's data queues appropriately31 var dbChild = data[type].fire.$getRef().child(id);32 dbChild.once('value', function(snapshot){33 var addUsers = null;34 var removeUsers = null;35 if(snapshot.val() && snapshot.val().users && child.users){36 addUsers = {};37 removeUsers = snapshot.val().users;38 // anything not found in the new child.users value will stay in the removeUsers39 // conversely, anything found in the new child.users that is not in the db value (removeUsers), will be added40 angular.forEach(child.users, function(value, userID){41 if(!removeUsers[userID]){42 // not there yet, add it43 addUsers[userID] = value;44 }45 else{46 // it is there, take it out of the removal list47 delete removeUsers[userID];48 }49 });50 }51 // save the record52 data[type].fire.$save(id).then(function(){53 // then update the user data queues54 if(addUsers && Object.keys(addUsers).length){55 data[type].fire.$addToUsers(id, addUsers);56 }57 if(removeUsers && Object.keys(removeUsers).length){58 data[type].fire.$removeFromUsers(id, removeUsers);59 }60 });61 });62 }63 else{64 // don't need to deal with users for this record65 data[type].fire.$save(id);66 }67 // always want to save the updated time68 data[type].fire.$child(id).$update({updated: time});69 },70 set:function(type, id, model){71 //ecodocs inits an object and creates a child with provided id.72 /**var object={};73 object[id] = model;74 data[type].fire.$set(object);75 // that approach would overwrite the entire data[type] table, leaving only the id:model record76 */77 var dbChild = data[type].fire.$getRef().child(id);78 dbChild.once('value', function(snapshot){79 // if there are users in the database record or in the new model, we need to handle dataQueue syncing80 if((model && model.users) || (snapshot.val() && snapshot.val().users)){81 var addUsers = null;82 var removeUsers = null;83 if(snapshot.val() && snapshot.val().users && model.users){84 addUsers = {};85 if(snapshot.val().users){86 removeUsers = snapshot.val().users;87 }88 // anything not found in the new model.users value will stay in the removeUsers89 // conversely, anything found in the new model.users that is not in the db value (removeUsers), will be added90 angular.forEach(model.users, function(value, userID){91 if(!removeUsers || !removeUsers[userID]){92 // not in db yet, add it (no users at all, or no entry for this one)93 addUsers[userID] = value;94 }95 else if(removeUsers && removeUsers[userID]){96 // it is in db and new model, take it out of the removal list97 delete removeUsers[userID];98 }99 });100 // save the record101 data[type].fire.$child(id).$set(model).then(function(){102 // then update the user data queues103 if(addUsers && Object.keys(addUsers).length){104 data[type].fire.$addToUsers(id, addUsers);105 }106 if(removeUsers && Object.keys(removeUsers).length){107 data[type].fire.$removeFromUsers(id, removeUsers);108 }109 });110 }111 }112 else{113 data[type].fire.$child(id).$set(model);114 }115 });116 },117 update:function(type, id, model){118 //ecodocs inits an object and creates a child with provided id.119 /**var object={};120 object[id] = model;121 data[type].fire.$update(object);122 // that approach would overwrite the full data[type][id] record rather than updating it123 */124 console.log('Updating '+type+': '+id+' with: '+model);125 var time = Date.now();126 if(model && model.users) {127 // if there are users in the new model, compare the new user value with the one in the db128 // this is so we can adjust the user's data queues appropriately129 var dbChild = data[type].fire.$getRef().child(id);130 dbChild.once('value', function(snapshot){131 var addUsers = null;132 var removeUsers = null;133 if(snapshot.val() && snapshot.val().users && model.users){134 addUsers = {};135 removeUsers = snapshot.val().users;136 // anything not found in the new model.users value will stay in the removeUsers137 // conversely, anything found in the new model.users that is not in the db value (removeUsers), will be added138 angular.forEach(model.users, function(value, userID){139 if(!removeUsers[userID]){140 // not there yet, add it141 addUsers[userID] = value;142 }143 else{144 // it is there, take it out of the removal list145 delete removeUsers[userID];146 }147 });148 }149 // save the record150 data[type].fire.$child(id).$update(model).then(function(){151 // then update the user data queues152 if(addUsers && Object.keys(addUsers).length){153 data[type].fire.$addToUsers(id, addUsers);154 }155 if(removeUsers && Object.keys(removeUsers).length){156 data[type].fire.$removeFromUsers(id, removeUsers);157 }158 });159 });160 }161 else{162 // don't need to deal with users for this record163 data[type].fire.$child(id).$update(model);164 }165 data[type].fire.$child(id).$update({updated: time});166 },167 remove:function(type, id){168 var defer = $q.defer();169 console.log('remove:'+type+'/'+id);170 var child = data[type].fire.$child(id);171 if(child){172 child.$on('loaded', function(){173 var users = null;174 // get the associated users before we remove it175 if(child.users){176 users = child.users;177 }178 data[type].fire.$remove(id).then(function(){179 if(users){180 // it's removed, clean up all the associated user records181 data[type].fire.$removeFromUsers(id, users);182 }183 defer.resolve(true);184 });185 });186 }187 else{188 defer.reject(type+'/'+id+' does not exist!');189 }190 return defer.promise;191 },192 loadData: function(){193 var defer = $q.defer();194 var datasLoaded = {};195 angular.forEach(data.types, function(type){196 // only load it if it is not already loaded or is not public (so we aren't reloading public sets)197 if(!data[type.name] || type.access.indexOf('public')===-1){198 var dataLoaded = $q.defer();199 datasLoaded[type.name] = dataLoaded.promise;200 // clean up existing instance of this data type201 if(data[type.name] && data[type.name].fire){202 data[type.name].fire.destroy();203 delete data[type.name].fire;204 }205 var secureFire = mngrSecureFirebase(type, data.user.profile);206 data[type.name] = {207 fire: secureFire,208 array: []209 };210 secureFire.$on('loaded', function(){211 dataLoaded.resolve(true);212 });213 // generate the array every time there is a value214 secureFire.$on('value', function(){215 data[type.name].array = secureFire.$asArray();216 });217 }218 });219 $q.all(datasLoaded).then(function(results){220 defer.resolve(true);221 });222 return defer.promise;223 },224 callbackError: function(error){225 var errorMsg = '';226 if(error){227 if(error.code){228 switch(error.code){229 case 'EMAIL_TAKEN':230 errorMsg = 'Email address is in use';231 break;232 }233 }234 else{235 errorMsg = error;236 }237 }238 if(!errorMsg){239 errorMsg = 'Unknown error occurred';240 }241 // ecodocs: where do we put error messages?242 console.log('Error:'+errorMsg);243 },244 callbackSuccess: function(result){245 if(result){246 if(result.uid){247 // user authenticated248 api.loadProfile(result).then(api.callbackSuccess, api.callbackError);249 }250 else if(!result.new && result.name && result.email){251 // user profile loaded252 api.loadData().then(function(){253 api.loadState();254 });255 }256 else if(result.new && result.linked){257 // new user profile258 if(result.confirmed){259 api.createProfile();260 }261 }262 else if(result.created && result.type && result.id){263 // new record saved264 switch(result.type){265 case 'users':266 if(data.user.profile.email){267 api.set('userEmails', md5.createHash(data.user.profile.email), result.id);268 }269 if(data.user.profile.linked){270 api.linkProfileAccounts(result.id, data.user.profile.linked).then(function(){271 api.login('active'); // profile is created and linked, login to activate272 });273 }274 break;275 default:276 console.log('Created:'+result.type+'/'+result.id);277 break;278 }279 }280 }281 },282 // logs a user in via the given provider283 login: function(provider, email, password){284 // handle login request based on provider285 switch(provider){286 case 'active':287 api.loginActive();288 break;289 case 'password':290 api.loginPassword(email, password);291 break;292 case 'facebook':293 case 'twitter':294 case 'google':295 api.loginProvider(provider);296 break;297 }298 },299 // logs in the active user (ie. by cookie)300 loginActive: function(){301 data.user.auth.$getCurrentUser().then(api.callbackSuccess, api.callbackError);302 },303 // logs in a user by email/password account304 loginPassword: function(email, password){305 data.user.auth.$login('password', {email:email, password:password}).then(api.callbackSuccess, api.callbackError);306 },307 // logs in a user by 3rd party provider308 loginProvider: function(provider){309 data.user.auth.$login(provider).then(api.callbackSuccess, api.callbackError);310 },311 // logs a user out312 logout: function(){313 data.user.auth.$logout();314 data.user.profile = null;315 api.loadData();316 },317 // creates a user email/password account318 createAccount: function(email, password, passwordConfirm){319 if(!email){320 api.callbackError('No email');321 }322 else if(!password){323 api.callbackError('No password');324 }325 else if(password.length < 6){326 api.callbackError('Passwords is too short');327 }328 else if(passwordConfirm !== password){329 api.callbackError('Passwords don\'t match');330 }331 else{332 api.userEmailAvailable(email).then(function(available){333 if(available){334 data.user.auth.$createUser(email, password).then(api.callbackSuccess, api.callbackError);335 }336 else{337 api.callbackError({code: "EMAIL_TAKEN"});338 }339 });340 }341 },342 // removes a user email/password account343 removeAccount: function(email, password){344 if(email && password){345 console.log('removeAccount:'+email+':'+password);346 data.user.auth.$removeUser(email, password).then(api.callbackSuccess, api.callbackError);347 }348 },349 // recovers a user's password350 recoverPassword: function(email){351 console.log('recoverPassword:'+email);352 },353 // changes a user's password354 changePassword: function(email, oldPassword, newPassword){355 console.log('changePassword:'+email);356 },357 // creates a user profile for a given account358 createProfile: function(){359 api.userEmailAvailable(data.user.profile.email).then(function(available){360 if(available){361 if(angular.isDefined(data.user.profile.new)){362 delete data.user.profile.new;363 }364 if(angular.isDefined(data.user.profile.confirmed)){365 delete data.user.profile.confirmed;366 }367 api.create('users', data.user.profile).then(api.callbackSuccess, api.callbackError);368 }369 else{370 api.callbackError({code: "EMAIL_TAKEN"});371 }372 });373 },374 linkProfileAccounts: function(userID, accounts){375 var defer = $q.defer();376 var accountsLinked = {};377 angular.forEach(accounts, function(linked, uid){378 if(linked){379 accountsLinked[uid] = api.set('userAccounts', uid, userID);380 }381 });382 $q.all(accountsLinked).then(function(){383 defer.resolve(true);384 });385 return defer.promise;386 },387 newProfile: function(account){388 var newProfile = null;389 if(account.uid){390 newProfile = {391 new: true,392 confirmed: false, // confirmed===true when the user has confirmed their email address393 linked: {}394 };395 newProfile.linked[account.uid] = true;396 // set email397 if(account.email){398 newProfile.email = account.email;399 }400 else if(account.thirdPartyUserData && account.thirdPartyUserData.email){401 newProfile.email = account.thirdPartyUserData.email;402 }403 // set name404 if(account.displayName){405 newProfile.name = account.displayName;406 }407 else if(newProfile.email){408 // no display name, parse it from the email409 var emailParse = newProfile.email.match(/^(\w+)@/);410 if(emailParse && emailParse.length > 1){411 newProfile.name = emailParse[1];412 }413 }414 // auto-confirm email/password accounts415 if(account.provider==='password' && newProfile.email){416 newProfile.confirmed = true;417 }418 // set default values for all user profile fields419 angular.forEach(models['users'], function(field){420 if(angular.isUndefined(newProfile[field.name])){421 newProfile[field.name] = field.value;422 }423 });424 }425 return newProfile;426 },427 // loads the user profile for a given account428 loadProfile: function(account){429 var defer = $q.defer();430 if(account.uid){431 // look up user account432 var userAccount = data['userAccounts'].fire.$child(account.uid);433 userAccount.$on('loaded', function(){434 if(userAccount.$value){435 // load the profile linked to the account436 var userProfile = data['users'].fire.$child(userAccount.$value);437 userProfile.$on('loaded', function(){438 if(userProfile.$value===null){439 // this would be if the account.uid is linked to a missing profile440 data.user.profile = api.newProfile(account);441 defer.resolve(data.user.profile);442 }443 else{444 data.user.profile = userProfile;445 defer.resolve(data.user.profile);446 }447 });448 }449 else{450 // if no profile linked to the account, create a new profile451 data.user.profile = api.newProfile(account);452 defer.resolve(data.user.profile);453 }454 });455 }456 else{457 defer.reject('No account to load uid for');458 }459 return defer.promise;460 },461 // check if the given email is associated with an existing account462 userEmailAvailable: function(email){463 var defer = $q.defer();464 var emailCheck =data['userEmails'].fire.$child(md5.createHash(email));465 emailCheck.$on('loaded', function(){466 if(emailCheck.$value===null){467 defer.resolve(true);468 }469 else{470 defer.resolve(false);471 }472 });473 return defer.promise;474 },475 setWorkspace: function(workspace, component, params){476 if(Object.keys(ui.workspace).indexOf(workspace)!==-1){477 // load the component into the workspace478 ui.workspace[workspace].component = component.name;479 // reset any existing parameters in this workspace480 angular.forEach(ui.workspace[workspace].params, function(value, name){481 delete ui.workspace[workspace].params[name];482 });483 // load the parameters we are given484 if(angular.isArray(params)){485 // for array params - load the params in the order the component defines them486 angular.forEach(component.params, function(name, index){487 if(index < params.length){488 ui.workspace[workspace].params[name] = params[index];489 }490 });491 // if there are more params than component is configured for, append the extra params onto the last configured param492 if(params.length > component.params.length){493 var lastParam = component.params[component.params.length-1];494 ui.workspace[workspace].params[lastParam] += (ui.workspace[workspace].params[lastParam]?'/':'')+params.slice(component.params.length).join('/');495 }496 }497 else if(angular.isObject(params)){498 // for object params - set the params that are defined for the component499 angular.forEach(params, function(value, name){500 if(component.params.indexOf(name)!==-1){501 ui.workspace[workspace].params[name] = value;502 }503 });504 }505 }506 },507 loadPath: function(path, workspace){508 if(Object.keys(ui.workspace).indexOf(workspace)!==-1){509 // valid workspace, load the path into the ui510 // strip off any leading or trailing /'s from path (for easier parsing)511 path = (path.charAt(0) === '/') ? path.substr(1) : path;512 path = (path.charAt(path.length - 1) === '/') ? path.substring(0, path.length - 1) : path;513 // parse the path by /'s514 var pathParts = path.split('/');515 var componentFound = false;516 if(pathParts && pathParts.length){517 var componentName = pathParts[0]; // component name is part before first '/'518 var params = pathParts.slice(1); // params are everything after first '/'519 // search for the given componentName in the configured components520 // set it into the workspace when a match is found521 angular.forEach(ui.components, function(component, componentIdx){522 if(component.name===componentName){523 api.setWorkspace(workspace, component, params);524 componentFound = true;525 }526 });527 // component not found in ui.components - search in ui.notify.components528 if(!componentFound){529 angular.forEach(ui.notify.components, function(component, componentIdx){530 if(component.name===componentName){531 api.setWorkspace(workspace, component, params);532 componentFound = true;533 }534 });535 }536 }537 // if the first part of the path is not a valid component, load the default component538 if(!componentFound){539 angular.forEach(ui.components, function(component, componentIdx){540 if(component.default){541 api.setWorkspace(workspace, component, pathParts);542 componentFound = true;543 }544 });545 }546 // at this point if !componentFound - then there isn't even a default component configured547 }548 },549 loadState: function (fromPath, withParams) {550 var path = angular.isDefined(fromPath) ? fromPath : ui.path;551 var params = angular.isDefined(withParams) ? withParams : ui.params;552 if(path){553 api.loadPath(path, 'main');554 }555 angular.forEach(params, function(value, workspace){556 api.loadPath(value, workspace);557 });558 }559 };560 return api;...
index.js
Source:index.js
1module.exports = GroupInfoModal;2require('./style.less');3const React = require('react');4const Fragment = React.Fragment;5const SearchableList = require('../../components/SearchableList');6const DropDown = require('../../components/DropDown');7const Modal = require('react-modal');8Modal.setAppElement('#react-app');9const PropTypes = require('prop-types');10const api = require('../../services/apiClient');11const {toast} = require('react-toastify');1213const Editable = require('../../components/Editable');1415GroupInfoModal.propTypes = {16 isOpen: PropTypes.bool,17 onOk: PropTypes.func,18 onCancel: PropTypes.func,19 companies: PropTypes.array,20 groupUsers: PropTypes.array21}2223function GroupInfoModal(props) {24 React.Component.call(this, props);2526 this.state = {27 users: props.users || [],28 group: props.group || {},29 groupUsers: props.groupUsers || [],30 tabIdx: 0,31 removeUsers: [],32 addUsers: []33 }343536 this.clearModelSession = function() {37 this.setState({38 tabIdx: 0,39 removeUsers: [],40 addUsers: [],41 group: {}42 });43 }4445 this.runPropsUpdate = function() {46 this.setState({47 users: this.props.users || [],48 group: this.props.group || {},49 groupUsers: [...(this.props.groupUsers || [])]50 });51 }5253 this.updateToServer = function() {54 // return new Promise(async (resolve, reject)=>{55 // for (let i = 0; i < this.state.removeUsers.length; i++)56 // try {57 // await api.removeUserFromGroup(this.props.selectedGroupId, this.state.removeUsers[i].idUser);58 // } catch (e) {59 // reject(e);60 // }61 // try {62 // await api.addUsersToGroup(this.props.selectedGroupId, this.state.addUsers.map((u)=>u.idUser));63 // } catch (e) {64 // reject(e);65 // }66 // resolve(null);67 // });68 let listPromise = [];69 for (let i = 0; i < this.state.removeUsers.length; i++) {70 listPromise.push(api.removeUserFromGroup(this.props.selectedGroupId, this.state.removeUsers[i].idUser));71 }72 if (this.state.addUsers.length > 0) {73 listPromise.push(api.addUsersToGroup(this.props.selectedGroupId, this.state.addUsers.map((u)=>u.idUser)));74 }75 if (this.state.group.name) {76 listPromise.push(api.editGroupInfo(this.state.group.idGroup, this.state.group.name, this.state.group.description));77 }78 return Promise.all(listPromise);79 };8081 this.submitAndClose = function(e) {82 //console.log('RUN');83 this.updateToServer().then((rs)=>{84 toast.success("Update group successfully");85 this.clearModelSession();86 this.props.onOk();87 }).catch(e=>{88 //console.log(e.message);89 toast.error(typeof(e) == "string" ? e : (typeof(e.message) == "string" ? e.message : JSON.stringify(e.message)));90 });91 }9293 let disabled = !!Object.keys(this.props.group || {}).length;9495 this.getUser = getUser.bind(this);9697 function getUser(user) {98 return (99 <div style={{display: 'flex',padding:'10px 0', justifyContent: 'space-between', alignItems: 'center'}}>100 {user ? (<Fragment>101 <div className="item-content">{user.username}</div>102 <i className="action-icon ti ti-arrow-right" onClick={(e) => {103 this.setState(state => {104 let idx = state.removeUsers.findIndex(u => u.idUser === user.idUser);105 if (idx >= 0) {106 state.removeUsers.splice(idx,1);107 }108 idx = state.addUsers.findIndex(u => u.idUser === user.idUser);109 if (idx < 0) {110 state.addUsers.push(user);111 }112 let index = state.groupUsers.findIndex(u => u.idUser === user.idUser);113 if (index >= 0) return {removeUsers: state.removeUsers, addUsers: state.addUsers};114 //115 idx = state.users.findIndex(u => u.idUser === user.idUser);116 state.users.splice(idx, 1);117 state.groupUsers.push(user);118 return {users: state.users, groupUsers: state.groupUsers, removeUsers: state.removeUsers, addUsers: state.addUsers}; 119 })120 }}></i>121 </Fragment>) : "[select user]"}122 </div>123 );124 }125126 this.getGroupUser = getGroupUser.bind(this);127 function getGroupUser(user) {128 return (129 <div style={{display: 'flex',padding:'10px 0', justifyContent: 'space-between', alignItems: 'center'}}>130 {user ? (<Fragment>131 <div className="item-content">{user.username}</div>132 <i className="action-icon ti ti-close" onClick={() => {133 this.setState(state => {134 let idx = state.addUsers.findIndex(u => u.idUser === user.idUser);135 if (idx >= 0) {136 state.addUsers.splice(idx,1);137 }138 idx = state.removeUsers.findIndex(u => u.idUser === user.idUser);139 if (idx < 0) {140 state.removeUsers.push(user);141 }142 //remove out143 idx = state.groupUsers.findIndex(u => u.idUser === user.idUser);144 state.groupUsers.splice(idx, 1);145 let index = state.users.findIndex(u => u.idUser === user.idUser);146 if (index < 0) {147 state.users.push(user);148 }149 return {groupUsers: state.groupUsers, users: state.users, removeUsers: state.removeUsers, addUsers: state.addUsers} 150 })151 }}></i>152 </Fragment>) : "[select user]"}153 </div>154 );155 }156 this.getRawUser = getRawUser.bind(this);157158 function getRawUser(idx) {159 return this.state.users[idx];160 }161162 this.render = function () { 163 return (164 <Modal isOpen={this.props.isOpen} 165 portalClassName="ModalStyle" 166 className="GroupInfoModal" 167 overlayClassName="modal-backdrop"168 onAfterOpen={()=>this.runPropsUpdate()}169 >170 <div className="header-dialog-tab">171 <div className="title-dialog">Group Info</div>172 <div className="tab-controls">173 <div className={this.state.tabIdx == 0 ? "active-tab":""} onClick={() => this.setState({174 tabIdx:0175 })}>General</div>176 <div className={this.state.tabIdx == 1 ? "active-tab":""} onClick={() => this.setState({177 tabIdx: 1178 })}>Members</div>179 </div>180 </div>181 <div className="content-dialog">182 <div style={{flex:2, position: 'relative'}}>183 <div style={{height: '400px'}}></div>184 <div className={"tab-content"} style={{visibility:this.state.tabIdx===0?'visible':'hidden'}}>185 <div className="fieldset">186 <div>Name:</div>187 <Editable value={this.state.group.name || ""} disabled={disabled}188 formatValue={(v) => (((v !== null ) && v.length) ? v : '[empty]')}189 onValueChanged={(name) => this.setState((state)=>{190 state.group.name = name;191 return {192 group: state.group193 };194 })}195 />196 </div>197 <div className="fieldset">198 <div>Description:</div>199 <Editable value={this.state.group.description || ""} disabled={disabled}200 formatValue={(v) => (((v !== null || true) && v.length) ? v : '[empty]')}201 onValueChanged={(description) => this.setState((state)=>{202 state.group.description = description;203 return {204 group: state.group205 };206 })}/>207 </div>208 </div>209 <div className="members tab-content" style={{visibility:this.state.tabIdx===1?'visible':'hidden'}}>210 <div style={{flex:1, overflow:'hidden', display:'flex'}}>211 <div className="column" style={{marginRight: "20px"}}>212 <SearchableList disabled={!disabled} getItem={this.getUser}213 items={this.state.users}214 filterFn = {(item, searchStr) => {return item.username.includes(searchStr)}}215 itemHeight={32} />216 </div>217 <div className="column">218 <SearchableList disabled={!disabled} getItem={this.getGroupUser}219 items={this.state.groupUsers}220 filterFn = {(item, searchStr) => {return item.username.includes(searchStr)}}221 itemHeight={32} />222 </div>223 </div>224 </div>225 </div>226 227 </div>228 <div className="footer-dialog">229 <div className="btn-next" onClick={(e) => {230 e.preventDefault();231 this.submitAndClose(e);232 }} style={{background: '#4B7DEF', color: '#fff'}}>OK</div>233 <div className="btn-next" onClick={(e) => {234 this.clearModelSession();235 this.props.onCancel();236 }}>Cancel</div>237 </div>238 </Modal>239 );240 }241242}243
...
removeUsers.spec.js
Source:removeUsers.spec.js
1import removeUsers from './removeUsers';2describe('removeUsers', () => {3 it('returns the same text when there are no users', () => {4 const text = 'there is no text here'5 const result = removeUsers(text);6 expect(result).toEqual(text);7 })8 it('returns the trimmed down text with multiple users all over the text', () => {9 const text = '<@user> there is a person <@here> who thinks they can get the attention of <@other>';10 const result = removeUsers(text);11 expect(result).toEqual('there is a person who thinks they can get the attention of')12 })...
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2stf.removeUsers(function(err, data) {3 if (err) {4 console.log('Error occurred while removing users', err);5 } else {6 console.log('Users removed successfully', data);7 }8});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var options = {3};4var stfApi = stf(options);5stfApi.removeUsers('username', function (err, data) {6 if (err) {7 console.log(err);8 } else {9 console.log(data);10 }11});12{ success: true }13var stf = require('devicefarmer-stf');14var options = {15};16var stfApi = stf(options);17stfApi.removeUsers('username', function (err, data) {18 if (err) {19 console.log(err);20 } else {21 console.log(data);22 }23});24{ success: true }25var stf = require('devicefarmer-stf');26var options = {27};28var stfApi = stf(options);29stfApi.removeUsers('username', function (err, data) {30 if (err) {31 console.log(err);32 } else {33 console.log(data);34 }35});36{ success: true }37var stf = require('devicefarmer-stf');38var options = {39};40var stfApi = stf(options);41stfApi.removeUsers('username', function (err, data) {42 if (err) {43 console.log(err);44 } else {45 console.log(data);46 }47});48{ success: true }49var stf = require('devicefarmer-stf');50var options = {51};52var stfApi = stf(options);53stfApi.removeUsers('username', function
Using AI Code Generation
1var devicefarmer = require('devicefarmer-stf');2stf.removeUsers(function(err, data) {3console.log(err, data);4});5var devicefarmer = require('devicefarmer-stf');6stf.removeUser('
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2var auth = new stf.Auth(api);3auth.authenticate('user', 'pass', function(err, token) {4 if (err) {5 console.log(err);6 } else {7 api.removeUsers(token, function(err, users) {8 if (err) {9 console.log(err);10 } else {11 console.log(users);12 }13 });14 }15});16var stf = require('devicefarmer-stf-client');17var auth = new stf.Auth(api);18auth.authenticate('user', 'pass', function(err, token) {19 if (err) {20 console.log(err);21 } else {22 api.removeUser(token, 'user', function(err, users) {23 if (err) {24 console.log(err);25 } else {26 console.log(users);27 }28 });29 }30});31var stf = require('devicefarmer-stf-client');32var auth = new stf.Auth(api);33auth.authenticate('user', 'pass', function(err, token) {34 if (err) {35 console.log(err);36 } else {37 api.getDevices(token, function(err, devices) {38 if (err) {39 console.log(err);40 } else {41 console.log(devices);42 }43 });44 }45});46var stf = require('devicefarmer-stf-client');47var auth = new stf.Auth(api);48auth.authenticate('user', 'pass', function(err, token) {49 if (err) {50 console.log(err);51 } else {52 api.getDevice(token, 'deviceid', function(err, devices) {53 if (err) {54 console.log(err);55 } else {56 console.log(devices);57 }58 });59 }60});
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!!