How to use addNotification method in storybook-root

Best JavaScript code snippet using storybook-root

idea.js

Source:idea.js Github

copy

Full Screen

...34 };35 $scope.notifications = []; 36 $scope.invalidNotification = false;37 var index = 0;38 function addNotification(notification){ 39 if(!notification){40 $scope.invalidNotification = true;41 return;42 }43 $scope.invalidNotification = false;44 $scope.notifications[index++] = notification; 45 };46 function goHome(){47 $rootScope.user = {};48 addNotification('Your session expired !');49 $location.url(APP_CONSTANTS.NAV_HOME);50 };51 52 $scope.init = function(){53 if(user){54 try{55 /*//Relaxed for API Hackathon56 if($rootScope.viewType == APP_CONSTANTS.TEAM_ROLE_LEAD){57 $scope.leadAction = true;58 }else{59 $scope.leadAction = false;60 }61 */62 $scope.leadAction = true;63 // Get the Themes64 ThemeService.query({},function(success){65 $scope.themes = success; 66 // Get the Idea Information 67 if($rootScope.ideaId){68 // Open the exisisting Idea69 IdeaService.get({id: $rootScope.ideaId},function(success){70 $scope.idea = success;71 // Control the Screen72 controlDisplay();73 populateSubTheme();74 // Get Idea History75 getIdeaHistory();76 },function(error){77 addNotification(error.data.message);78 });79 }else{80 // Control the Screen81 console.log('No Idea Id...' + $rootScope.team.sector + $rootScope.team.account);82 controlDisplay(); 83 if( $rootScope.team ){84 $scope.idea.theme = $rootScope.team.sector;85 $scope.themeSelected($scope.idea.theme);86 //$scope.idea.subTheme = $rootScope.team.account;87 $scope.idea.subTheme = $scope.idea.theme;88 }89 }90 },function(error){91 addNotification(error.data.message);92 });93 }catch(exception){94 addNotification(exception);95 };96 }else{97 goHome();98 };99 };100 $scope.themeSelected = function(theme){101 if($scope.idea.theme){102 populateSubTheme();103 $scope.idea.subTheme = $scope.idea.theme;104 }; 105 };106 $scope.resetIdea = function(){107 if(user){108 $scope.idea = {};109 }else{110 goHome();111 };112 };113 $scope.saveIdea = function(){114 $scope.processing = true;115 console.log('Idea Subtheme' + $scope.idea.subTheme);116 if(user && $scope.idea){ 117 if($scope.idea.id){ 118 //Update Idea119 IdeaService.update($scope.idea, function(success){120 $scope.idea = success; 121 // Control the Screen122 controlDisplay(); 123 addNotification($scope.idea.title +' Idea info updated.'); 124 // Get Update Idea History125 getIdeaHistory();126 }, function(error){127 addNotification(error.data.message);128 }); 129 }else{130 if(validateSave()){131 //Create Idea132 $scope.buttonDissabled = true;133 IdeaCreateService.create({teamId : $rootScope.teamId},$scope.idea, function(success){ 134 $scope.idea = success;135 // Control the Screen136 controlDisplay();137 // Get Update Idea History138 getIdeaHistory();139 addNotification($scope.idea.title + ' Idea created.');140 $scope.buttonDissabled = false;141 }, function(error){142 addNotification(error.data.message);143 $scope.buttonDissabled = false;144 });145 };146 } 147 }else{148 goHome();149 };150 $scope.processing = false;151 };152 $scope.cancelIdea = function(){153 if(user){154 $location.url('/ideaview');155 }else{156 goHome();157 };158 };159 $scope.deleteIdea = function(){160 $scope.processing = true;161 if(user && $scope.idea && $scope.idea.id){162 //Deleting Idea Files163 FileDeleteService.remove({type : 'idea', id : $scope.idea.id}, function(success){164 addNotification('Idea document removed.'); 165 }, function(error){166 addNotification(error.data.message);167 }); 168 // Delete Idea169 IdeaService.remove({id : $scope.idea.id}, function(success){170 addNotification( $scope.idea.title +' Idea deleted.');171 $location.url('/ideaview');172 }, function(error){173 addNotification(error.data.message);174 }); 175 }else{176 goHome();177 };178 $scope.processing = false;179 };180 $scope.deleteIdeaFile = function(docId, fileName, index){181 $scope.processing = true;182 if(user && docId ){183 //File Delete184 FileDeleteService.remove({type : 'doc', id : docId}, function(success){185 addNotification('Idea document removed.'); 186 $scope.idea.documents.splice(index, 1);187 // Update the Save Message188 $scope.idea.updateMessage = fileName +" document removed. !";189 // Save the Idea190 $scope.saveIdea();191 }, function(error){192 addNotification(error.data.message);193 }); 194 }else{195 goHome();196 };197 $scope.processing = false;198 };199 $scope.submitIdea = function(){200 console.log('root submitIdea....');201 $scope.processing = true;202 if(user && $scope.idea ){203 if($scope.idea.id){204 submit();205 }else{206 IdeaCreateService.create({teamId : $rootScope.teamId},$scope.idea, function(success){ 207 // Control the Screen208 controlDisplay();209 $scope.idea = success;210 console.log('Idea created successfully :' +$scope.idea.id);211 if($scope.idea.id){212 submit();213 } 214 }, function(error){215 addNotification(error.data.message);216 $scope.buttonDissabled = false;217 });218 }219 }else{220 goHome();221 };222 $scope.processing = false;223 };224 function submit(){225 if(validateSubmit()){226 $scope.idea.teamId = $rootScope.teamId; 227 console.log('submitIdea....for ' + $scope.idea.teamId );228 // Save Before Submit229 $scope.buttonDissabled = true;230 IdeaService.update($scope.idea, function(success){231 console.log('submitIdea....Saved ' + $scope.idea.id );232 $scope.idea = success;233 addNotification($scope.idea.title +' Idea updated.');234 IdeaSubmitService.update({id : $scope.idea.id },$scope.idea, function(success){235 addNotification($scope.idea.title +' Idea submitted.');236 $location.url('/ideaview');237 }, function(error){238 addNotification(error.data.message);239 $scope.buttonDissabled = false;240 });241 }, function(error){242 // Control the Screen243 controlDisplay();244 addNotification(error.data.message);245 $scope.buttonDissabled = false;246 }); 247 };248 }249 $scope.reCallIdea = function(){250 $scope.processing = true;251 if(user && $scope.idea && $scope.idea.id){252 if($scope.idea.status && ( $scope.idea.status == APP_CONSTANTS.IDEA_STATUS_SUBMITTED 253 || $scope.idea.status == APP_CONSTANTS.IDEA_STATUS_READY_FOR_REVIEW ) ){254 IdeaReCallService.update({id : $scope.idea.id }, {} , function(success){255 addNotification($scope.idea.title +' Idea Recalled.');256 $location.url('/ideaview');257 }, function(error){258 addNotification(error.data.message);259 });260 }else{261 addNotification('Re Call is not valid for '+ $scope.idea.status+' Idea status.');262 };263 }else{264 goHome();265 };266 $scope.processing = false;267 };268 $scope.onFileSelect = function($files) {269 if($scope.idea.documents && $scope.idea.documents.length >= APP_CONSTANTS.IDEA_DOCUMENT_MAX_COUNT){270 addNotification("Document attachement should be only "+APP_CONSTANTS.IDEA_DOCUMENT_MAX_COUNT+" numbers with each Max 5MB size.");271 }else{272 $scope.processing = true;273 //$files: an array of files selected, each file has name, size, and type.274 for (var i = 0; i < $files.length; i++) {275 var file = $files[i]; 276 if(file && file.name && file.size && file.type){277 console.log('File name '+ file.name + 'File type '+ file.type);278 if( !('application/zip' == file.type || 'application/x-zip-compressed' == file.type || 'multipart/x-zip' == file.type || 'application/x-zip' == file.type ) ){279 addNotification('Please upload only ZIP (application/zip, application/x-zip-compressed, multipart/x-zip) format files, Your file type is '+ file.type);280 }else if(file.size > 5242880){281 // 10 MB = 10485760, 5 MB = 5242880282 addNotification('Your file size is more than 5 MB !');283 }else{284 $scope.buttonDissabled = true;285 $scope.upload = $upload.upload({286 url: serviceurl+'file/upload', //upload.php script, node.js route, or servlet url287 method: 'POST',288 //headers: {'header-key': 'header-value'},289 //withCredentials: true,290 data: { teamId : $rootScope.teamId, ideaId: $scope.idea.id, type : 'ABSTRACT'},291 file: file, // or list of files ($files) for html5 only292 }).progress(function(evt) {293 $scope.uploadProgress = parseInt(100.0 * evt.loaded / evt.total);294 //console.log('percent: ' + parseInt(100.0 * evt.loaded / evt.total));295 }).success(function(data, status, headers, config) {296 // file is uploaded successfully297 $scope.uploadProgress = 0;298 addNotification(file.name +' Document uploaded to the server.'); 299 $scope.idea.documents.push(data);300 // Update the Save Message301 $scope.idea.updateMessage = file.name +" document uploaded by "+user.name;302 // Save the Idea303 $scope.saveIdea();304 $scope.buttonDissabled = false;305 }).error(function(error){306 addNotification(error.message);307 $scope.buttonDissabled = false;308 });309 }310 }else{311 addNotification('Problem in your file upload. Please, upload valid file format.');312 }313 //.error(...)314 //.then(success, error, progress); 315 // access or attach event listeners to the underlying XMLHttpRequest.316 //.xhr(function(xhr){xhr.upload.addEventListener(...)})317 }318 /* alternative way of uploading, send the file binary with the file's content-type.319 Could be used to upload files to CouchDB, imgur, etc... html5 FileReader is needed. 320 It could also be used to monitor the progress of a normal http post/put request with large data*/321 // $scope.upload = $upload.http({...}) see 88#issuecomment-31366487 for sample code.322 $scope.processing = false;323 }324 };325 function getIdeaHistory(){326 if($scope.idea.id){327 IdeaHistoryQueryService.query({id : $scope.idea.id }, function(success){328 if(success){329 $scope.histories = success;330 }; 331 }, function(error){332 addNotification(error.data.message);333 });334 };335 };336 function controlDisplay(){337 if($scope.idea.id == null){338 $scope.formDissabled = false;339 $scope.showSave = true;340 $scope.showSubmit = true;341 $scope.showDelete = false;342 $scope.showReCall = false;343 $scope.themeDissable = false;344 $scope.docUploadShow = false;345 $scope.uploadDissable = false;346 $scope.demoOptionDissable = false;347 }else if(APP_CONSTANTS.IDEA_STATUS_DRAFT == $scope.idea.status){348 $scope.formDissabled = false; 349 if( $rootScope.control.addIdea){350 $scope.showSave = true;351 $scope.showSubmit = true;352 $scope.showDelete = true;353 } 354 $scope.showReCall = false;355 $scope.themeDissable = false;356 $scope.docUploadShow = false;357 $scope.uploadDissable = false;358 $scope.demoOptionDissable = false;359 }else if(APP_CONSTANTS.IDEA_STATUS_SUBMITTED == $scope.idea.status){360 $scope.formDissabled = true;361 $scope.showSave = false;362 $scope.showSubmit = false;363 $scope.showDelete = false;364 $scope.showReCall = true;365 $scope.themeDissable = true;366 $scope.docUploadShow = false;367 $scope.uploadDissable = true;368 $scope.demoOptionDissable = false;369 }else if(APP_CONSTANTS.IDEA_STATUS_REWORK == $scope.idea.status){370 $scope.formDissabled = false;371 $scope.showSave = true;372 $scope.showSubmit = true;373 $scope.showDelete = false;374 $scope.showReCall = false;375 $scope.themeDissable = true;376 $scope.docUploadShow = false;377 $scope.uploadDissable = false;378 $scope.demoOptionDissable = false;379 }else if(APP_CONSTANTS.IDEA_STATUS_READY_FOR_REVIEW == $scope.idea.status){380 $scope.formDissabled = true;381 $scope.showSave = false;382 $scope.showSubmit = false;383 $scope.showDelete = false;384 $scope.showReCall = true;385 $scope.themeDissable = true;386 $scope.docUploadShow = false;387 $scope.uploadDissable = true;388 $scope.demoOptionDissable = false;389 }else if(APP_CONSTANTS.IDEA_STATUS_P2_DRAFT == $scope.idea.status){390 $scope.formDissabled = false; 391 if( $rootScope.control.p2SubmitIdea){ 392 $scope.showSubmit = true; 393 } 394 $scope.showSave = true;395 $scope.showDelete = false;396 $scope.showReCall = false;397 $scope.themeDissable = true;398 $scope.docUploadShow = true;399 $scope.uploadDissable = false;400 $scope.demoOptionDissable = true;401 }else if(APP_CONSTANTS.IDEA_STATUS_P2_SUBMITTED == $scope.idea.status){402 $scope.formDissabled = true;403 $scope.showSave = false;404 $scope.showSubmit = false;405 $scope.showDelete = false;406 $scope.showReCall = false;407 $scope.themeDissable = true;408 $scope.docUploadShow = true;409 $scope.uploadDissable = true;410 $scope.demoOptionDissable = false;411 }else{412 $scope.formDissabled = true;413 $scope.showSave = false;414 $scope.showSubmit = false;415 $scope.showDelete = false;416 $scope.showReCall = false;417 $scope.themeDissable = true;418 $scope.docUploadShow = true;419 $scope.uploadDissable = true;420 $scope.demoOptionDissable = false;421 } 422 };423 function populateSubTheme(){424 if($scope.themes && $scope.idea.theme){ 425 for (var i = 0; i < $scope.themes.length; i++) {426 if( $scope.themes[i] && $scope.themes[i].id == $scope.idea.theme){ 427 $scope.environments = $scope.themes[i].subThemes;428 }429 }430 }431 };432 function validateSave(){433 var valid = true;434 if($scope.idea){ 435 if(!$scope.idea.title){436 addNotification("Idea title is missing !");437 valid = false;438 }439 if(!$scope.idea.theme){440 441 addNotification("Theme is missing !");442 valid = false;443 }444 445 /*if(!$scope.idea.subTheme){446 addNotification("Api Idea Account is missing !");447 valid = false;448 } */449 if(!$scope.idea.applyIndustries || $scope.idea.applyIndustries.length <= 0 ){450 addNotification("Applicable Industry selection missing !");451 valid = false;452 }453 454 if(!$scope.idea.industry ){455 addNotification("Industry selection missing !");456 valid = false;457 }458 if(!$scope.idea.summary){459 addNotification("Idea/ candidate is missing/not in proper range!");460 valid = false;461 }462 }else{463 addNotification("Idea information is missing");464 valid = false;465 }466 return valid;467 };468 function validateSubmit(){469 var valid = true;470 if(validateSave()){ 471 if(!$scope.idea.env.runTimes || $scope.idea.env.runTimes.length <= 0){472 valid = false;473 addNotification('Please select Bluemix Runtime.');474 }475 if(!$scope.idea.id){476 addNotification("Idea id is missing !");477 valid = false;478 }479 /*480 if(!$scope.idea.implementationInfo){481 addNotification("Idea Implementation information is missing !");482 valid = false;483 } 484 */ 485 if( $scope.idea.status == APP_CONSTANTS.IDEA_STATUS_P2_DRAFT){486 if(!$scope.idea.demoStatus || !$scope.idea.demoStatus == null ){487 addNotification('Please select the development status.');488 }489 490 if( !$scope.idea.documents || $scope.idea.documents.length <= 0 ){491 valid = false;492 addNotification('Please attach the updated mandatory documents.');493 }else if( $scope.idea.documents.length > APP_CONSTANTS.IDEA_DOCUMENT_MAX_COUNT ){494 valid = false;495 addNotification('Please check attachements. It should be max of '+ APP_CONSTANTS.IDEA_DOCUMENT_MAX_COUNT +' numbers with 5MB max size.');496 } 497 }498 }else{499 valid = false;500 }501 return valid;502 };...

Full Screen

Full Screen

registration.js

Source:registration.js Github

copy

Full Screen

...21 $scope.waitForRequest= false;22 $scope.notifications = []; 23 $scope.invalidNotification = false;24 var index = 0;25 function addNotification(notification){ 26 if(!notification){27 $scope.invalidNotification = true;28 return;29 }30 $scope.invalidNotification = false;31 $scope.notifications[index++] = notification;32 };33 function goHome(){34 console.log('Go Home !');35 $rootScope.user = {};36 $location.url(APP_CONSTANTS.NAV_HOME);37 };38 $scope.init = function(){39 if(user){40 $rootScope.teamEnable = false;41 $rootScope.skillsetEnable = false;42 $rootScope.ideaEnable = false;43 44 if($rootScope.invitationCount){45 $scope.createTeamEnable = true;46 $scope.waitForRequest= false;47 }else{48 $scope.createTeamEnable = true;49 $scope.waitForRequest= true;50 }51 52 console.log('Registration Launched');53 }else{54 goHome();55 }56 }; 57 $scope.navigateStep2 = function(){58 if(user){ 59 //Update User Accept60 UserAcceptService.update(user, function(success){61 addNotification(user.name + ' User Registration Accepted !');62 $location.url('/registrationsteptwo');63 }, function(error){64 addNotification(error.data.message);65 }); 66 }else{67 goHome();68 }69 };70 $scope.initStep2 = function(){71 if(user){ 72 $rootScope.teamEnable = false;73 $rootScope.skillsetEnable = false;74 $rootScope.ideaEnable = false;75 76 loadThemes();77 LocationService.query({},function(response){78 $scope.locations = response;79 },function(error){80 addNotification(error.data.message);81 });82 processRegistration(user);83 }else{84 goHome();85 }86 };87 $scope.goReg1 = function(){88 if(user){89 $location.url('/registrationstepone');90 }else{91 goHome();92 };93 };94 $scope.goBack = function(){95 goHome();96 };97 $scope.waitTeamRequest = function(){98 addNotification('Thanks '+user.name + ' for joining !. Please wait for team joining invitation(s).');99 goHome();100 };101 $scope.getMembers = function(val) {102 return UserSearchService.query({filter : val}).$promise.then(103 function(response){104 var members = [];105 angular.forEach(response, function(item){106 members.push(item.id+'-'+item.name + "-" + item.email);107 });108 return members;109 });110 };111 $scope.acceptTeamJoining = function(teamRequest){112 if(user){113 console.log('Called acceptTeamJoining...');114 if(teamRequest){ 115 TeamRequestProcessService.get({action : 'accept', id : teamRequest.id},{}, function(success){ 116 if(success){ 117 if(success.id){118 addNotification(success.name + " team joining request accepted !");119 $rootScope.teamId = success.id;120 $location.url('/team');121 }else{122 console.log('Failed to get team information');123 }124 }125 }, function(error){126 addNotification(error.data.message);127 });128 }else{129 console.log('Team Joining information is Missing !');130 }131 }else{132 goHome();133 } 134 };135 $scope.declineTeamJoining = function(teamRequest, index){136 if(user){137 console.log('Called acceptTeamJoining...');138 if(teamRequest){ 139 TeamRequestProcessService.get({action : 'decline', id : teamRequest.id},{}, function(success){ 140 addNotification(teamRequest.team.name +' team joining request declined !');141 if($scope.teamRequests){142 $scope.teamRequests.splice(index, 1);143 if($scope.teamRequests.length){144 console.log("More Requests are there..");145 }else{146 $scope.teamRequestEnable = false;147 $scope.teamCreationEnable = true;148 }149 }150 }, function(error){151 addNotification(error.data.message);152 });153 }else{154 console.log('Team Joining information is Missing !');155 }156 }else{157 goHome();158 } 159 };160 161 function loadThemes(){162 // Get the Themes163 ThemeService.query({},function(success){164 $scope.themes = success; 165 },function(error){166 addNotification(error.data.message);167 });168 }169 170 $scope.themeSelected = function(theme){171 for (var i = 0; i < $scope.themes.length; i++) {172 if( $scope.themes[i] && $scope.themes[i].id == $scope.team.sector){ 173 $scope.subThemes = $scope.themes[i].subThemes;174 }175 } 176 };177 $scope.createTeam = function(){178 if(user){179 console.log('Called Team Creation...');180 $scope.team.creator = { id : user.id, email : user.email};181 $scope.team.members = [];182 if(validateTeam() && validateSkillset($scope.skillsetRequest)){183 var member1Valid = true;184 var member2Valid = true;185 var bothMemberValid = true;186 if($scope.member1){187 var info = convertUser($scope.member1);188 if(info && info.id){189 $scope.team.members[0] = { user : info };190 if(info.id == $rootScope.user.id){191 member1Valid = false;192 };193 }194 };195 if($scope.member2){196 var info = convertUser($scope.member2);197 if(info && info.id){198 $scope.team.members[1] = { user : info };199 if(info.id == $rootScope.user.id){200 member2Valid = false;201 };202 }203 };204 if($scope.team.members.length == 2){205 bothMemberValid = validateBoth($scope.team.members[0].user,$scope.team.members[1].user);206 };207 if( member1Valid && member2Valid && bothMemberValid){208 TeamCreateService.create({}, $scope.team, function(success){209 if(success && success.id){210 $rootScope.teamId = success.id;211 addNotification(success.name + " Team created !" );212 if($scope.skillsetEnabled && $scope.skillsetRequest){213 $scope.skillsetRequest.teamId = $rootScope.teamId;214 var createdBy = {};215 createdBy.id = user.id;216 createdBy.name = user.name;217 createdBy.email = user.email;218 $scope.skillsetRequest.createdBy = createdBy;219 //Create SkillSet Request220 SkillsetRequestCreateService.create({}, $scope.skillsetRequest, function(success){221 addNotification($scope.skillsetRequest.skillsetRequired +' SkillSet request created for the team');222 }, function(error){223 addNotification(error.data.message);224 });225 }226 $location.url('/team');227 };228 }, function(error){229 addNotification(error.data.message);230 });231 }else{232 addNotification('Member Validation failed !');233 }234 }235 }else{236 goHome();237 } 238 };239 function validateSkillset(skillsetRequest){240 var valid = true; 241 if($scope.skillsetEnabled){242 if(!skillsetRequest.skillsetRequired){243 valid = false;244 addNotification('Skillset required is missing');245 }246 if(!skillsetRequest.location){247 valid = false;248 addNotification('Skillset required location is missing');249 }250 if(!skillsetRequest.ideaSummary){251 valid = false;252 addNotification('Idea summary is missing');253 }254 }255 return valid;256 }257 function validateTeam(){258 var valid = true;259 if(!$scope.team){260 addNotification('Team Information is missing');261 valid = false;262 }else{263 if(!$scope.team.name){264 addNotification('Team Name is missing');265 valid = false;266 }267 if(!$scope.team.location){268 addNotification('Team location is missing');269 valid = false;270 }271 }272 return valid;273 };274 function getUserTeam(user){275 if(user && user.id){276 TeamByUserService.get({id : user.id}, function(success){277 if(success){ 278 if(success.id){279 addNotification(success.name + " Team assigned for you !");280 $rootScope.team = success;281 $location.url('/team');282 }else{283 console.log('Processing Registration Process');284 }285 }286 }, function(error){287 addNotification(error.data.message);288 });289 }290 };291 function processRegistration(user){292 // To get teamRequests293 TeamRequestProcessService.query({action : 'user', id : user.id},{}, function(success){294 $scope.teamRequests = success;295 if($scope.teamRequests && $scope.teamRequests.length){296 $scope.teamRequestEnable = true; 297 }else{ 298 $scope.teamCreationEnable = true;299 } 300 301 if( $rootScope.control.teamCreation){302 $scope.teamCreationDissableMessage = false;303 }else{304 $scope.teamCreationEnable = false;305 $scope.teamCreationDissableMessage = true;306 }307 }, function(error){308 addNotification(error.data.message);309 });310 };311 function convertUser(userStr){312 var user = {};313 if(userStr){314 var userInfo = userStr.split('-');315 if(userInfo && userInfo.length == 3){316 //console.log('Split Result '+ userInfo[0] + userInfo[1] +userInfo[2]);317 user = {318 id : userInfo[0],319 name : userInfo[1],320 email : userInfo[2]321 };322 }else{323 addNotification('Failed to get information from ' + userStr);324 }325 }326 return user;327 };328 function validateBoth(member1, member2){329 var valid = true;330 if(member1 && member1.id && member2 && member2.id){331 if(member1.id == member2.id){332 valid = false;333 addNotification('You have selected same member('+ member1.name+') for team request');334 } 335 }336 addNotification('Both Member Validation '+valid+' !');337 return valid; 338 };...

Full Screen

Full Screen

notification.spec.ts

Source:notification.spec.ts Github

copy

Full Screen

...1213 function createClient(): IClient {14 return {15 notifications: [],16 addNotification() { },17 removeNotification() { },18 } as any;19 }2021 beforeEach(() => {22 notificationService = new NotificationService();23 client = createClient();24 });2526 after(() => {27 notificationService = undefined as any;28 client = undefined as any;29 });3031 describe('addNotification()', () => {32 it('adds notification to client', () => {33 const notification = { id: 0, name: 'name', message: 'test' };3435 notificationService.addNotification(client, notification);3637 expect(client.notifications).contain(notification);38 });3940 it('returns new notification ID', () => {41 const notification = { id: 0, name: 'name', message: 'test' };4243 expect(notificationService.addNotification(client, notification)).equal(1);44 });4546 it('assigns ID to notification', () => {47 const notification = { id: 0, name: 'name', message: 'test1' };48 client.notifications.push({ id: 1, name: 'name', message: 'test2' });4950 notificationService.addNotification(client, notification);5152 expect(notification.id).not.equal(0);53 });5455 it('sends addNotification', () => {56 const notification = { id: 0, name: 'name', message: 'test', note: 'note', flags: 123 };57 const addNotification = stub(client, 'addNotification');5859 notificationService.addNotification(client, notification);6061 assert.calledWith(addNotification, 1, 0, 'name', 'test', 'note', 123);62 });6364 it('does not add notification to client if limit is reached', () => {65 times(10, () => notificationService.addNotification(client, { id: 0, name: 'name', message: uniqueId('test') }));66 const addNotification = stub(client, 'addNotification');6768 expect(notificationService.addNotification(client, { id: 0, name: 'name', message: uniqueId('test') })).equal(0);6970 assert.notCalled(addNotification);71 });7273 it('does not add notification to client if identical notification already exists', () => {74 const addNotification = stub(client, 'addNotification');7576 expect(notificationService.addNotification(client, { id: 0, name: 'name', message: 'foo' })).not.equal(0);77 expect(notificationService.addNotification(client, { id: 0, name: 'name', message: 'foo' })).equal(0);7879 expect(client.notifications.length).equal(1);80 assert.calledOnce(addNotification);81 });82 });8384 describe('removeNotification()', () => {85 it('removes notification from client', () => {86 const notification = { id: 1, name: 'name', message: 'test' };87 client.notifications.push(notification);8889 notificationService.removeNotification(client, 1);9091 expect(client.notifications).not.contain(notification);92 });9394 it('does nothing if notification does not exist', () => {95 const removeNotification = stub(client, 'removeNotification');9697 notificationService.removeNotification(client, 1);9899 assert.notCalled(removeNotification);100 });101102 it('sends removeNotification', () => {103 client.notifications.push({ id: 1, name: 'name', message: 'test' });104 const removeNotification = stub(client, 'removeNotification');105106 notificationService.removeNotification(client, 1);107108 assert.calledWith(removeNotification, 1);109 });110111 it('returns true if notification is removed', () => {112 client.notifications.push({ id: 1, name: 'name', message: 'test' });113114 expect(notificationService.removeNotification(client, 1)).true;115 });116117 it('returns false if notification does not exist', () => {118 expect(notificationService.removeNotification(client, 1)).false;119 });120 });121122 describe('acceptNotification()', () => {123 it('calls accept callback', () => {124 const accept = spy();125 notificationService.addNotification(client, { id: 0, name: 'name', message: 'test', accept });126127 notificationService.acceptNotification(client, 1);128129 assert.calledOnce(accept);130 });131132 it('removes notification', () => {133 notificationService.addNotification(client, { id: 0, name: 'name', message: 'test', accept() { } });134 const removeNotification = stub(notificationService, 'removeNotification');135136 notificationService.acceptNotification(client, 1);137138 assert.calledWith(removeNotification, client, 1);139 });140141 it('does nothing if notification does not exist', () => {142 const removeNotification = stub(client, 'removeNotification');143144 notificationService.acceptNotification(client, 1);145146 assert.notCalled(removeNotification);147 });148149 it('works if notification does not have accept callback', () => {150 const notification = { id: 0, name: 'name', message: 'test' };151 notificationService.addNotification(client, notification);152153 notificationService.acceptNotification(client, 1);154155 expect(client.notifications).not.include(notification);156 });157 });158159 describe('rejectNotification()', () => {160 it('calls reject callback', () => {161 const reject = spy();162 notificationService.addNotification(client, { id: 0, name: 'name', message: 'test', reject });163164 notificationService.rejectNotification(client, 1);165166 assert.calledOnce(reject);167 });168169 it('removes notification', () => {170 notificationService.addNotification(client, { id: 0, name: 'name', message: 'test', accept() { } });171 const removeNotification = stub(notificationService, 'removeNotification');172173 notificationService.rejectNotification(client, 1);174175 assert.calledWith(removeNotification, client, 1);176 });177178 it('does nothing if notification does not exist', () => {179 const removeNotification = stub(client, 'removeNotification');180181 notificationService.rejectNotification(client, 1);182183 assert.notCalled(removeNotification);184 });185186 it('works if notification does not have reject callback', () => {187 const notification = { id: 0, name: 'name', message: 'test' };188 notificationService.addNotification(client, notification);189190 notificationService.rejectNotification(client, 1);191192 expect(client.notifications).not.include(notification);193 });194 });195196 describe('rejectAll()', () => {197 it('rejects all notifications', () => {198 client.notifications = [{ id: 1 }, { id: 2 }] as any;199 const rejectNotification = stub(notificationService, 'rejectNotification');200201 notificationService.rejectAll(client);202 ...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addNotification } from 'storybook-root-decorator';2import { Button } from '@storybook/react/demo';3export default {4 (story) => {5 addNotification('This is a notification from the story');6 return story();7 },8};9export const Text = () => <Button>Hello Button</Button>;10import { addDecorator } from '@storybook/react';11import { withNotifications } from 'storybook-root-decorator';12addDecorator(withNotifications());13import { addDecorator } from '@storybook/react';14import { withNotifications } from 'storybook-root-decorator';15addDecorator(withNotifications());

Full Screen

Using AI Code Generation

copy

Full Screen

1addNotification({2 onAdd: () => {},3 onRemove: () => {},4});5| onAdd | `function` | `() => {}` | Callback function to execute when the notification is added. |6| onRemove | `function` | `() => {}` | Callback function to execute when the notification is removed. |

Full Screen

Using AI Code Generation

copy

Full Screen

1import { addNotification } from 'storybook-root-decorator';2addNotification({3});4import { addDecorator } from 'storybook-root-decorator';5addDecorator((story) => <div>{story()}</div>);6import { addParameters } from 'storybook-root-decorator';7addParameters({8 options: {9 },10});11import { addGlobalStyles } from 'storybook-root-decorator';12addGlobalStyles(`13 body {14 background-color: #eee;15 }16`);17import { addGlobalStylesFromUrl } from 'storybook-root-decorator';

Full Screen

Using AI Code Generation

copy

Full Screen

1import RootSibling from 'react-native-root-siblings';2import { addNotification } from 'react-native-root-sibling-notification';3export const showNotification = (type, message) => {4 const notification = (5 <Notification type={type} message={message} />6 );7 addNotification(notification);8};9import React from 'react';10import { View, Text, StyleSheet } from 'react-native';11const Notification = ({ message, type }) => {12 return (13 <View style={styles.container}>14 <Text style={styles.text}>{message}</Text>15 );16};17const styles = StyleSheet.create({18 container: {19 },20 text: {21 },22});23export default Notification;

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run storybook-root automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful