Best JavaScript code snippet using redwood
auditLogController.spec.js
Source:auditLogController.spec.js
1'use strict';2describe("auditLogController", function () {3 var scope, httpBackend, _spinner, mockAuditLogService, counter, mockResponses, messagingService, translate;4 var DateUtil = Bahmni.Common.Util.DateUtil;5 var translatedMessages = {6 "MATCHING_EVENTS_NOT_FOUND": "No matching events found for given criteria !!",7 "INVALID_DATE": "Please enter valid date !!",8 "NO_EVENTS_FOUND": "No events to display !!",9 "NO_MORE_EVENTS_FOUND": "No more events to be displayed !!"10 };11 var logs = [12 {13 "auditLogId": 9,14 "userId": "superman",15 "patientId": 4,16 "eventType": "VIEWED_DASHBOARD",17 "message": "VIEWED_DASHBOARD message",18 "dateCreated": "March 23rd, 2017 at 4:36:50 PM",19 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"20 },21 {22 "auditLogId": 10,23 "userId": "batman",24 "patientId": 8,25 "eventType": "VIEWED_CLINICAL_DASHBOARD",26 "message": "VIEWED_CLINICAL_DASHBOARD message",27 "dateCreated": "March 23rd, 2017 at 4:37:00 PM",28 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80ce"29 }30 ];31 beforeEach(function () {32 counter = 0;33 module('bahmni.admin');34 _spinner = jasmine.createSpyObj('spinner', ['forPromise']);35 messagingService = jasmine.createSpyObj('messagingService', ['showMessage']);36 _spinner.forPromise.and.returnValue(specUtil.simplePromise({}));37 inject(['$controller', '$rootScope', '$httpBackend', function ($controller, $rootScope, $httpBackend) {38 scope = $rootScope.$new();39 httpBackend = $httpBackend;40 }]);41 mockAuditLogService = jasmine.createSpyObj("auditLogService", ["getLogs"]);42 mockAuditLogService.getLogs.and.callFake(function () {43 return mockResponses[counter++];44 });45 translate = jasmine.createSpyObj('$translate', ['instant']);46 translate.instant.and.callFake(function (key) {47 return translatedMessages[key];48 })49 });50 afterEach(function () {51 httpBackend.verifyNoOutstandingRequest();52 httpBackend.verifyNoOutstandingExpectation();53 });54 var setUp = function () {55 inject(function ($controller) {56 $controller('auditLogController', {57 $scope: scope,58 spinner: _spinner,59 auditLogService: mockAuditLogService,60 messagingService: messagingService,61 $translate: translate62 });63 });64 };65 it('should provide audit log after initialization', function () {66 var startDate = new Date("2017-03-23T18:30:00.548Z");67 scope.startDate = startDate;68 mockResponses = [specUtil.simplePromise(angular.copy(logs).reverse())];69 scope.$apply(setUp);70 var log1 = scope.logs[0];71 var log2 = scope.logs[1];72 expect(scope.logs.length).toBe(2);73 expect(scope.lastIndex).toBe(10);74 expect(scope.firstIndex).toBe(9);75 expect(log1.eventType).toBe("VIEWED_DASHBOARD");76 expect(log1.message).toBe("VIEWED_DASHBOARD message");77 expect(log1.patientId).toBe(4);78 expect(log1.auditLogId).toBe(9);79 expect(log1.dateCreated).toBe("March 23rd, 2017 at 4:36:50 PM");80 expect(log2.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");81 expect(log2.message).toBe("VIEWED_CLINICAL_DASHBOARD message");82 expect(log2.patientId).toBe(8);83 expect(log2.auditLogId).toBe(10);84 expect(log2.dateCreated).toBe("March 23rd, 2017 at 4:37:00 PM");85 expect(_spinner.forPromise).toHaveBeenCalled();86 expect(mockAuditLogService.getLogs.calls.count()).toBe(1);87 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: startDate, defaultView: true});88 expect(messagingService.showMessage).not.toHaveBeenCalled();89 });90 it("should gives audit logs from given date", function () {91 var currentDate = new Date("2018-04-23T18:30:00.548Z");92 var startForm = new Date("2017-02-23T18:30:00.548Z");93 mockResponses = [specUtil.simplePromise([]), specUtil.simplePromise(logs)];94 scope.startDate = currentDate;95 scope.$apply(setUp);96 expect(translate.instant).toHaveBeenCalledWith("NO_EVENTS_FOUND");97 expect(scope.errorMessage).toBe("No events to display !!");98 expect(scope.logs.length).toBe(0);99 expect(scope.lastIndex).toBe(0);100 expect(scope.firstIndex).toBe(0);101 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});102 scope.startDate = startForm;103 scope.runReport();104 var log1 = scope.logs[0];105 var log2 = scope.logs[1];106 expect(scope.logs.length).toBe(2);107 expect(scope.lastIndex).toBe(10);108 expect(scope.firstIndex).toBe(9);109 expect(log1.patientId).toBe(4);110 expect(log1.auditLogId).toBe(9);111 expect(log2.patientId).toBe(8);112 expect(log2.auditLogId).toBe(10);113 expect(_spinner.forPromise).toHaveBeenCalled();114 expect(scope.errorMessage).toBe("");115 expect(mockAuditLogService.getLogs.calls.count()).toBe(2);116 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: startForm});117 });118 it("should provide previous logs from given index", function () {119 var currentDate = new Date("2018-04-23T18:30:00.548Z");120 mockResponses = [specUtil.simplePromise([logs[1]]), specUtil.simplePromise([logs[0]])];121 mockAuditLogService.getLogs.and.callFake(function () {122 return mockResponses[counter++];123 });124 scope.startDate = currentDate;125 scope.$apply(setUp);126 var log = scope.logs[0];127 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});128 expect(scope.logs.length).toBe(1);129 expect(scope.lastIndex).toBe(10);130 expect(scope.firstIndex).toBe(10);131 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");132 expect(log.patientId).toBe(8);133 expect(log.auditLogId).toBe(10);134 scope.prev();135 log = scope.logs[0];136 expect(scope.logs.length).toBe(1);137 expect(scope.lastIndex).toBe(9);138 expect(scope.firstIndex).toBe(9);139 expect(log.eventType).toBe("VIEWED_DASHBOARD");140 expect(log.message).toBe("VIEWED_DASHBOARD message");141 expect(log.patientId).toBe(4);142 expect(log.auditLogId).toBe(9);143 expect(mockAuditLogService.getLogs.calls.count()).toBe(2);144 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({145 startFrom: currentDate,146 lastAuditLogId: 10,147 prev: true148 });149 });150 it("should display warning message when there is no event after initialization", function () {151 mockResponses = [specUtil.simplePromise([]), specUtil.simplePromise([])];152 scope.$apply(setUp);153 expect(scope.logs.length).toBe(0);154 expect(scope.lastIndex).toBe(0);155 expect(scope.firstIndex).toBe(0);156 expect(translate.instant).toHaveBeenCalledWith("NO_EVENTS_FOUND");157 expect(scope.errorMessage).toBe("No events to display !!");158 expect(_spinner.forPromise).toHaveBeenCalled();159 expect(mockAuditLogService.getLogs).toHaveBeenCalled();160 scope.prev();161 expect(scope.logs.length).toBe(0);162 expect(scope.lastIndex).toBe(0);163 expect(scope.firstIndex).toBe(0);164 expect(translate.instant).toHaveBeenCalledWith("NO_MORE_EVENTS_FOUND");165 expect(scope.errorMessage).toBe("No more events to be displayed !!");166 expect(mockAuditLogService.getLogs.calls.count()).toBe(2);167 });168 it("should provide next logs from given index", function () {169 var currentDate = new Date("2018-04-23T18:30:00.548Z");170 mockResponses = [specUtil.simplePromise([logs[0]]), specUtil.simplePromise([logs[1]])];171 scope.startDate = currentDate;172 scope.$apply(setUp);173 var log = scope.logs[0];174 expect(scope.logs.length).toBe(1);175 expect(scope.lastIndex).toBe(9);176 expect(scope.firstIndex).toBe(9);177 expect(log.auditLogId).toBe(9);178 scope.next();179 log = scope.logs[0];180 expect(scope.logs.length).toBe(1);181 expect(scope.lastIndex).toBe(10);182 expect(scope.firstIndex).toBe(10);183 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");184 expect(log.message).toBe("VIEWED_CLINICAL_DASHBOARD message");185 expect(log.patientId).toBe(8);186 expect(log.auditLogId).toBe(10);187 expect(_spinner.forPromise).toHaveBeenCalled();188 expect(mockAuditLogService.getLogs.calls.count()).toBe(2);189 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({190 startFrom: currentDate,191 lastAuditLogId: 9192 });193 });194 it("should display warning if not event found", function () {195 var currentDate = new Date("2018-04-23T18:30:00.548Z");196 mockResponses = [specUtil.simplePromise([])];197 scope.startDate = currentDate;198 scope.$apply(setUp);199 expect(scope.logs.length).toBe(0);200 expect(scope.lastIndex).toBe(0);201 expect(scope.firstIndex).toBe(0);202 expect(translate.instant).toHaveBeenCalledWith("NO_EVENTS_FOUND");203 expect(scope.errorMessage).toBe("No events to display !!");204 expect(_spinner.forPromise).toHaveBeenCalled();205 expect(mockAuditLogService.getLogs.calls.count()).toBe(1);206 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});207 });208 it("should take today's date as default date during initialization", function () {209 var currentDate = new Date(DateUtil.getDateWithoutHours());210 mockResponses = [specUtil.simplePromise([{211 "auditLogId": 9,212 "userId": "superman",213 "patientId": 4,214 "eventType": "VIEWED_DASHBOARD",215 "message": "VIEWED_DASHBOARD message",216 "dateCreated": currentDate.getTime(),217 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"218 }])];219 scope.$apply(setUp);220 expect(scope.logs.length).toBe(1);221 expect(scope.lastIndex).toBe(9);222 expect(scope.firstIndex).toBe(9);223 var log = scope.logs[0];224 expect(log.eventType).toBe("VIEWED_DASHBOARD");225 expect(log.message).toBe("VIEWED_DASHBOARD message");226 expect(log.patientId).toBe(4);227 expect(log.auditLogId).toBe(9);228 expect(_spinner.forPromise).toHaveBeenCalled();229 expect(mockAuditLogService.getLogs.calls.count()).toBe(1);230 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});231 });232 it("should display warning and set default index if there is no event found after pressed prev button", function () {233 var currentDate = new Date("2018-04-23T18:30:00.548Z");234 mockResponses = [specUtil.simplePromise([logs[1]]), specUtil.simplePromise([logs[0]]), specUtil.simplePromise([])];235 scope.startDate = currentDate;236 scope.$apply(setUp);237 var log = scope.logs[0];238 expect(scope.logs.length).toBe(1);239 expect(scope.lastIndex).toBe(10);240 expect(scope.firstIndex).toBe(10);241 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");242 expect(log.message).toBe("VIEWED_CLINICAL_DASHBOARD message");243 expect(log.patientId).toBe(8);244 expect(log.auditLogId).toBe(10);245 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});246 scope.prev();247 log = scope.logs[0];248 expect(scope.logs.length).toBe(1);249 expect(scope.lastIndex).toBe(9);250 expect(scope.firstIndex).toBe(9);251 expect(log.eventType).toBe("VIEWED_DASHBOARD");252 expect(log.message).toBe("VIEWED_DASHBOARD message");253 expect(log.patientId).toBe(4);254 expect(log.auditLogId).toBe(9);255 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({256 startFrom: currentDate,257 prev: true,258 lastAuditLogId: 10259 });260 scope.prev();261 log = scope.logs[0];262 expect(scope.logs.length).toBe(1);263 expect(scope.lastIndex).toBe(9);264 expect(scope.firstIndex).toBe(9);265 expect(log.eventType).toBe("VIEWED_DASHBOARD");266 expect(log.message).toBe("VIEWED_DASHBOARD message");267 expect(log.patientId).toBe(4);268 expect(log.auditLogId).toBe(9);269 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({270 startFrom: currentDate,271 prev: true,272 lastAuditLogId: 9273 });274 expect(mockAuditLogService.getLogs.calls.count()).toBe(3);275 expect(_spinner.forPromise).toHaveBeenCalled();276 expect(translate.instant).toHaveBeenCalledWith("NO_MORE_EVENTS_FOUND");277 expect(scope.errorMessage).toBe("No more events to be displayed !!");278 });279 it("should display warning if there is no event found after pressed next button again and again", function () {280 var currentDate = new Date("2018-04-23T18:30:00.548Z");281 mockResponses = [specUtil.simplePromise([logs[0]]), specUtil.simplePromise([logs[1]]), specUtil.simplePromise([])];282 scope.startDate = currentDate;283 scope.$apply(setUp);284 var log = scope.logs[0];285 expect(scope.logs.length).toBe(1);286 expect(scope.lastIndex).toBe(9);287 expect(scope.firstIndex).toBe(9);288 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});289 expect(log.eventType).toBe("VIEWED_DASHBOARD");290 expect(log.message).toBe("VIEWED_DASHBOARD message");291 expect(log.patientId).toBe(4);292 expect(log.auditLogId).toBe(9);293 scope.next();294 log = scope.logs[0];295 expect(scope.logs.length).toBe(1);296 expect(scope.lastIndex).toBe(10);297 expect(scope.firstIndex).toBe(10);298 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, lastAuditLogId: 9});299 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");300 expect(log.message).toBe("VIEWED_CLINICAL_DASHBOARD message");301 expect(log.patientId).toBe(8);302 expect(log.auditLogId).toBe(10);303 scope.next();304 log = scope.logs[0];305 expect(scope.logs.length).toBe(1);306 expect(scope.lastIndex).toBe(10);307 expect(scope.firstIndex).toBe(10);308 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");309 expect(log.message).toBe("VIEWED_CLINICAL_DASHBOARD message");310 expect(log.patientId).toBe(8);311 expect(log.auditLogId).toBe(10);312 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, lastAuditLogId: 10});313 expect(translate.instant).toHaveBeenCalledWith("NO_MORE_EVENTS_FOUND");314 expect(scope.errorMessage).toBe("No more events to be displayed !!");315 expect(_spinner.forPromise).toHaveBeenCalled();316 expect(mockAuditLogService.getLogs.calls.count()).toBe(3);317 });318 it("should not update present logs if no logs found", function () {319 var currentDate = new Date("2017-03-23T18:30:00.548Z");320 mockResponses = [specUtil.simplePromise(angular.copy(logs).reverse()), specUtil.simplePromise([])];321 scope.startDate = currentDate;322 scope.$apply(setUp);323 var log1 = scope.logs[0];324 var log2 = scope.logs[1];325 expect(scope.logs.length).toBe(2);326 expect(scope.lastIndex).toBe(10);327 expect(scope.firstIndex).toBe(9);328 expect(log1.patientId).toBe(4);329 expect(log1.auditLogId).toBe(9);330 expect(log2.patientId).toBe(8);331 expect(log2.auditLogId).toBe(10);332 expect(_spinner.forPromise).toHaveBeenCalled();333 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});334 scope.next();335 expect(scope.logs.length).toBe(2);336 expect(scope.lastIndex).toBe(10);337 expect(scope.firstIndex).toBe(9);338 expect(log1.patientId).toBe(4);339 expect(log1.auditLogId).toBe(9);340 expect(log2.patientId).toBe(8);341 expect(log2.auditLogId).toBe(10);342 expect(_spinner.forPromise).toHaveBeenCalled();343 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, lastAuditLogId: 10});344 expect(translate.instant).toHaveBeenCalledWith("NO_MORE_EVENTS_FOUND");345 expect(scope.errorMessage).toBe("No more events to be displayed !!");346 });347 it("should replace logs when user use run report to show logs", function () {348 var currentDate = new Date("2017-03-23T18:30:00.548Z");349 var startForm1 = new Date("2017-02-24T18:30:00.548Z");350 var startForm2 = new Date("2017-02-25T18:30:00.548Z");351 mockResponses = [specUtil.simplePromise([logs[0]]), specUtil.simplePromise([]), specUtil.simplePromise(logs)];352 scope.startDate = currentDate;353 scope.$apply(setUp);354 var log = scope.logs[0];355 expect(scope.logs.length).toBe(1);356 expect(scope.lastIndex).toBe(9);357 expect(scope.firstIndex).toBe(9);358 expect(log.eventType).toBe("VIEWED_DASHBOARD");359 expect(log.message).toBe("VIEWED_DASHBOARD message");360 expect(log.patientId).toBe(4);361 expect(log.auditLogId).toBe(9);362 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});363 expect(_spinner.forPromise).toHaveBeenCalled();364 scope.startDate = startForm1;365 scope.runReport();366 expect(translate.instant).toHaveBeenCalledWith("MATCHING_EVENTS_NOT_FOUND");367 expect(scope.errorMessage).toBe("No matching events found for given criteria !!");368 expect(scope.logs.length).toBe(0);369 expect(scope.lastIndex).toBe(0);370 expect(scope.firstIndex).toBe(0);371 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: startForm1});372 expect(_spinner.forPromise).toHaveBeenCalled();373 scope.startDate = startForm2;374 scope.runReport();375 var log1 = scope.logs[0];376 var log2 = scope.logs[1];377 expect(scope.logs.length).toBe(2);378 expect(scope.lastIndex).toBe(10);379 expect(scope.firstIndex).toBe(9);380 expect(log1.eventType).toBe("VIEWED_DASHBOARD");381 expect(log1.message).toBe("VIEWED_DASHBOARD message");382 expect(log1.patientId).toBe(4);383 expect(log1.auditLogId).toBe(9);384 expect(log2.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");385 expect(log2.message).toBe("VIEWED_CLINICAL_DASHBOARD message");386 expect(log2.patientId).toBe(8);387 expect(log2.auditLogId).toBe(10);388 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: startForm2});389 expect(mockAuditLogService.getLogs.calls.count()).toBe(3);390 expect(_spinner.forPromise).toHaveBeenCalled();391 });392 it("should not send if filter values is empty", function () {393 var currentDate = new Date(DateUtil.getDateWithoutHours());394 var response1 = [{395 "auditLogId": 9,396 "userId": "superman",397 "patientId": 4,398 "eventType": "VIEWED_DASHBOARD",399 "message": "VIEWED_DASHBOARD message",400 "dateCreated": currentDate.getTime(),401 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"402 }];403 mockResponses = [specUtil.simplePromise(response1), specUtil.simplePromise(logs)];404 scope.$apply(setUp);405 expect(scope.logs.length).toBe(1);406 expect(scope.lastIndex).toBe(9);407 expect(scope.firstIndex).toBe(9);408 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});409 var log = scope.logs[0];410 expect(log.eventType).toBe("VIEWED_DASHBOARD");411 expect(log.message).toBe("VIEWED_DASHBOARD message");412 expect(log.patientId).toBe(4);413 expect(log.auditLogId).toBe(9);414 expect(_spinner.forPromise).toHaveBeenCalled();415 scope.runReport();416 expect(scope.logs.length).toBe(2);417 var log1 = scope.logs[0];418 var log2 = scope.logs[1];419 expect(scope.logs.length).toBe(2);420 expect(scope.lastIndex).toBe(10);421 expect(scope.firstIndex).toBe(9);422 expect(log1.eventType).toBe("VIEWED_DASHBOARD");423 expect(log1.message).toBe("VIEWED_DASHBOARD message");424 expect(log1.patientId).toBe(4);425 expect(log1.auditLogId).toBe(9);426 expect(log2.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");427 expect(log2.message).toBe("VIEWED_CLINICAL_DASHBOARD message");428 expect(log2.patientId).toBe(8);429 expect(log2.auditLogId).toBe(10);430 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate});431 expect(mockAuditLogService.getLogs.calls.count()).toBe(2);432 });433 it("should give all logs filter by given username", function () {434 var currentDate = new Date(DateUtil.getDateWithoutHours());435 var response1 = [{436 "auditLogId": 9,437 "userId": "superman",438 "patientId": 4,439 "eventType": "VIEWED_DASHBOARD",440 "message": "VIEWED_DASHBOARD message",441 "dateCreated": currentDate.getTime(),442 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"443 }];444 mockResponses = [specUtil.simplePromise(response1), specUtil.simplePromise([logs[1]])];445 scope.$apply(setUp);446 expect(scope.logs.length).toBe(1);447 expect(scope.lastIndex).toBe(9);448 expect(scope.firstIndex).toBe(9);449 var log = scope.logs[0];450 expect(log.eventType).toBe("VIEWED_DASHBOARD");451 expect(log.message).toBe("VIEWED_DASHBOARD message");452 expect(log.userId).toBe("superman");453 expect(log.patientId).toBe(4);454 expect(log.auditLogId).toBe(9);455 expect(_spinner.forPromise).toHaveBeenCalled();456 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});457 scope.username = "batman";458 scope.runReport();459 expect(scope.logs.length).toBe(1);460 expect(scope.lastIndex).toBe(10);461 expect(scope.firstIndex).toBe(10);462 log = scope.logs[0];463 expect(log.eventType).toBe("VIEWED_CLINICAL_DASHBOARD");464 expect(log.message).toBe("VIEWED_CLINICAL_DASHBOARD message");465 expect(log.patientId).toBe(8);466 expect(log.auditLogId).toBe(10);467 expect(log.userId).toBe("batman");468 expect(_spinner.forPromise).toHaveBeenCalled();469 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, username: "batman"});470 });471 it("should give all logs filter by given patient identifier", function () {472 var currentDate = new Date(DateUtil.getDateWithoutHours());473 var response = [{474 "auditLogId": 9,475 "userId": "superman",476 "patientId": 4,477 "eventType": "VIEWED_DASHBOARD",478 "message": "VIEWED_DASHBOARD message",479 "dateCreated": currentDate.getTime(),480 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"481 }];482 mockResponses = [specUtil.simplePromise([]), specUtil.simplePromise(response)];483 scope.$apply(setUp);484 expect(scope.logs.length).toBe(0);485 expect(scope.lastIndex).toBe(0);486 expect(scope.firstIndex).toBe(0);487 expect(_spinner.forPromise).toHaveBeenCalled();488 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});489 scope.patientId = 4;490 scope.runReport();491 var log = scope.logs[0];492 expect(scope.logs.length).toBe(1);493 expect(log.eventType).toBe("VIEWED_DASHBOARD");494 expect(log.message).toBe("VIEWED_DASHBOARD message");495 expect(log.userId).toBe("superman");496 expect(log.patientId).toBe(4);497 expect(log.auditLogId).toBe(9);498 expect(scope.logs.length).toBe(1);499 expect(scope.lastIndex).toBe(9);500 expect(scope.firstIndex).toBe(9);501 expect(_spinner.forPromise).toHaveBeenCalled();502 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, patientId: 4});503 });504 it("should give all logs filter by given patient identifier and username", function () {505 var currentDate = new Date(DateUtil.getDateWithoutHours());506 var response = [{507 "auditLogId": 9,508 "userId": "superman",509 "patientId": 4,510 "eventType": "VIEWED_DASHBOARD",511 "message": "VIEWED_DASHBOARD message",512 "dateCreated": currentDate.getTime(),513 "uuid": "0c2b665e-0fe7-11e7-a6f7-0800270d80cd"514 }];515 mockResponses = [specUtil.simplePromise([]), specUtil.simplePromise(response)];516 scope.$apply(setUp);517 expect(scope.logs.length).toBe(0);518 expect(scope.lastIndex).toBe(0);519 expect(scope.firstIndex).toBe(0);520 expect(_spinner.forPromise).toHaveBeenCalled();521 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({startFrom: currentDate, defaultView: true});522 scope.patientId = 4;523 scope.username = "superman";524 scope.runReport();525 var log = scope.logs[0];526 expect(scope.logs.length).toBe(1);527 expect(log.eventType).toBe("VIEWED_DASHBOARD");528 expect(log.message).toBe("VIEWED_DASHBOARD message");529 expect(log.userId).toBe("superman");530 expect(log.patientId).toBe(4);531 expect(log.auditLogId).toBe(9);532 expect(scope.logs.length).toBe(1);533 expect(scope.lastIndex).toBe(9);534 expect(scope.firstIndex).toBe(9);535 expect(_spinner.forPromise).toHaveBeenCalled();536 expect(mockAuditLogService.getLogs).toHaveBeenCalledWith({537 startFrom: currentDate,538 patientId: 4,539 username: "superman"540 });541 });542 it("should not run report if given date field has future date", function () {543 spyOn($.fn, "hasClass").and.returnValue(true);544 mockResponses = [specUtil.simplePromise([])];545 scope.$apply(setUp);546 expect(scope.logs.length).toBe(0);547 expect(scope.lastIndex).toBe(0);548 expect(scope.firstIndex).toBe(0);549 expect(_spinner.forPromise).toHaveBeenCalled();550 expect(mockAuditLogService.getLogs).toHaveBeenCalled();551 scope.runReport();552 expect(scope.logs.length).toBe(0);553 expect(scope.lastIndex).toBe(0);554 expect(scope.firstIndex).toBe(0);555 expect(mockAuditLogService.getLogs.calls.count()).toBe(1);556 expect(translate.instant).toHaveBeenCalledWith("INVALID_DATE");557 expect(messagingService.showMessage).toHaveBeenCalledWith("error", "Please enter valid date !!");558 });...
xcloud.spec.js
Source:xcloud.spec.js
1describe('xCloud', () => {2 it('should not experience long webdriver calls', () => {3 // browser.getLogs('logcat');4 driver.startRecordingScreen();5 driver.takeScreenshot();6 driver.takeScreenshot();7 driver.getPageSource();8 driver.takeScreenshot();9 driver.getPageSource();10 driver.takeScreenshot();11 driver.getPageSource();12 driver.takeScreenshot();13 driver.stopRecordingScreen();14 driver.getCurrentPackage();15 driver.getCurrentActivity();16 driver.getPageSource();17 // browser.getLogs('logcat');18 driver.startRecordingScreen();19 driver.takeScreenshot();20 driver.getPageSource();21 driver.takeScreenshot();22 driver.getPageSource();23 driver.takeScreenshot();24 driver.getPageSource();25 driver.takeScreenshot();26 driver.getPageSource();27 // browser.getLogs('logcat');28 // NO STOPPING!!!!29 driver.startRecordingScreen();30 driver.takeScreenshot();31 driver.takeScreenshot();32 driver.getPageSource();33 driver.takeScreenshot();34 driver.getPageSource();35 driver.takeScreenshot();36 driver.getPageSource();37 driver.takeScreenshot();38 driver.stopRecordingScreen();39 driver.takeScreenshot();40 driver.getPageSource();41 // browser.getLogs('logcat');42 driver.startRecordingScreen();43 for(let i=0; i < 100; i++) {44 driver.pressKeyCode(69);45 }46 driver.takeScreenshot();47 driver.getPageSource();48 driver.takeScreenshot();49 driver.getPageSource();50 driver.takeScreenshot();51 driver.getPageSource();52 driver.stopRecordingScreen();53 driver.takeScreenshot();54 driver.getPageSource();55 // browser.getLogs('logcat');56 driver.startRecordingScreen();57 for(let i=0; i < 100; i++) {58 driver.pressKeyCode(69);59 }60 driver.takeScreenshot();61 driver.getPageSource();62 driver.takeScreenshot();63 driver.getPageSource();64 driver.takeScreenshot();65 driver.getPageSource();66 driver.stopRecordingScreen();67 driver.takeScreenshot();68 driver.getPageSource();69 driver.takeScreenshot();70 driver.getPageSource();71 driver.takeScreenshot();72 driver.getPageSource();73 // browser.getLogs('logcat');74 driver.startRecordingScreen();75 driver.takeScreenshot();76 driver.getPageSource();77 driver.stopRecordingScreen();78 driver.takeScreenshot();79 driver.getPageSource();80 // browser.getLogs('logcat');81 driver.startRecordingScreen();82 driver.takeScreenshot();83 driver.getPageSource();84 driver.takeScreenshot();85 driver.getPageSource();86 driver.takeScreenshot();87 driver.getPageSource();88 driver.stopRecordingScreen();89 driver.takeScreenshot();90 driver.getPageSource();91 driver.takeScreenshot();92 driver.getPageSource();93 driver.takeScreenshot();94 driver.getPageSource();95 // browser.getLogs('logcat');96 driver.startRecordingScreen();97 driver.takeScreenshot();98 driver.getPageSource();99 driver.stopRecordingScreen();100 driver.takeScreenshot();101 driver.getPageSource();102 driver.takeScreenshot();103 driver.getPageSource();104 driver.takeScreenshot();105 driver.getPageSource();106 driver.takeScreenshot();107 driver.getPageSource();108 driver.takeScreenshot();109 driver.getPageSource();110 driver.takeScreenshot();111 driver.getPageSource();112 driver.takeScreenshot();113 driver.getPageSource();114 driver.takeScreenshot();115 driver.getPageSource();116 driver.takeScreenshot();117 driver.getPageSource();118 // VERY STRANGE, NOW THERE IS A STOP119 driver.stopRecordingScreen();120 driver.getPageSource();121 // browser.getLogs('logcat');122 driver.startRecordingScreen();123 driver.takeScreenshot();124 driver.getPageSource();125 driver.stopRecordingScreen();126 driver.getPageSource();127 // browser.getLogs('logcat');128 driver.startRecordingScreen();129 driver.takeScreenshot();130 driver.getPageSource();131 driver.stopRecordingScreen();132 driver.getPageSource();133 // browser.getLogs('logcat');134 driver.startRecordingScreen();135 for(let i=0; i < 100; i++) {136 driver.pressKeyCode(69);137 }138 driver.takeScreenshot();139 driver.getPageSource();140 driver.stopRecordingScreen();141 driver.getPageSource();142 // browser.getLogs('logcat');143 driver.startRecordingScreen();144 driver.takeScreenshot();145 driver.getPageSource();146 driver.stopRecordingScreen();147 driver.getPageSource();148 // browser.getLogs('logcat');149 driver.startRecordingScreen();150 driver.takeScreenshot();151 driver.getPageSource();152 driver.stopRecordingScreen();153 driver.getPageSource();154 // browser.getLogs('logcat');155 driver.startRecordingScreen();156 driver.takeScreenshot();157 driver.getPageSource();158 driver.stopRecordingScreen();159 driver.getPageSource();160 // browser.getLogs('logcat');161 driver.startRecordingScreen();162 for(let i=0; i < 100; i++) {163 driver.pressKeyCode(69);164 }165 driver.takeScreenshot();166 driver.getPageSource();167 driver.stopRecordingScreen();168 driver.getPageSource();169 driver.takeScreenshot();170 driver.getPageSource();171 driver.getPageSource();172 driver.takeScreenshot();173 driver.getPageSource();174 driver.getPageSource();175 driver.takeScreenshot();176 driver.getPageSource();177 driver.getPageSource();178 driver.takeScreenshot();179 driver.getPageSource();180 driver.getPageSource();181 // browser.getLogs('logcat');182 });...
logs.test.js
Source:logs.test.js
1'use strict';2import {reducers} from ".";3import {info, getLogs, getErrors, getError, warn, error} from "./logs";4import { SET_DATA } from "./data";5import { setActive } from "./products";6const initialState = reducers(undefined, {});7describe("errors", ()=>{8 let e, s;9 beforeEach(()=>{10 e = new Error("Hello");11 s = reducers(initialState, {error: e, type: SET_DATA});12 })13 test("log a line", ()=>{14 expect(getLogs(s)).toHaveLength(1);15 expect(getLogs(s)[0]).toEqual(expect.objectContaining({16 severity: "error", 17 message: e.message, 18 name: SET_DATA,19 }));20 })21 test("get active errors", ()=>{22 expect(getErrors(s)).toHaveLength(1);23 expect(getErrors(s)[0]).toMatchSnapshot({24 id: expect.any(Number),25 timestamp: expect.any(Date),26 context: expect.stringMatching("")27 });28 })29 30 test("get error by name", ()=>{31 expect(getError(s, SET_DATA)).toMatchSnapshot({32 id: expect.any(Number),33 timestamp: expect.any(Date),34 context: expect.stringMatching("")35 })36 })37 test("clear action error", ()=>{38 s = reducers(s, {type: SET_DATA,data: {foo:"bar"}});39 expect(getErrors(s)).toHaveLength(0);40 })41 test("handle setActive() actions", ()=>{42 s = reducers(s, setActive("foo"));43 expect(getLogs(s)[1]).toEqual(expect.objectContaining({44 message: "Connexion à foo",45 name: "SET_ACTIVE_PRODUCT",46 severity: "info",47 timestamp: expect.any(Date),48 }));49 })50 test("Allow custom error type", ()=>{51 let e = new Error("Hello");52 const s = reducers(initialState, {error: e, type: "FOO"});53 expect(getLogs(s)).toHaveProperty("length", 1);54 expect(getLogs(s)[0]).toEqual(expect.objectContaining({severity: "error", message: e.message, name: "FOO"}));55 });56 test("Allow custom context", ()=>{57 let e = new Error("Hello");58 e.context = "At some point";59 const s = reducers(initialState, {error: e, type: "FOO"});60 expect(getLogs(s)).toHaveProperty("length", 1);61 expect(getLogs(s)[0]).toEqual(expect.objectContaining({62 severity: "error", 63 message: e.message, 64 name: "FOO",65 context: "At some point",66 }));67 })68})69test("Cap logs at 100 lines", ()=>{70 let s = initialState;71 for (let i=0; i <110; i++){72 s = reducers(s, info(`Hello ${i}`));73 }74 let lines = getLogs(s);75 expect(lines).toHaveLength(100);76 expect(lines[0]).toHaveProperty("message", `Hello 10`);77})78test("keeps referenced errors when it overflows", ()=>{79 let s = initialState;80 s = reducers(s, {type: SET_DATA, error: new Error(`Something Wrong`)});81 for (let i=0; i <110; i++){82 s = reducers(s, info(`Hello ${i}`));83 }84 let lines = getLogs(s);85 expect(lines).toHaveLength(101);86 expect(lines[0]).toHaveProperty("message", `Something Wrong`);87})88test("can provide just a message to info()", ()=>{89 let s = reducers(initialState, info(`Hello World`));90 expect(getLogs(s)[0]).toEqual(expect.objectContaining({91 name: "INFO",92 severity: "info",93 message: "Hello World"94 }))95});96test("can provide custom log name", ()=>{97 let s = reducers(initialState, info("Foo", `Hello World`));98 expect(getLogs(s)[0]).toEqual(expect.objectContaining({99 name: "Foo",100 severity: "info",101 message: "Hello World"102 }))103})104test("can provide context", ()=>{105 let s = reducers(initialState, info("Foo", `Hello World`, "some context"));106 expect(getLogs(s)[0]).toEqual(expect.objectContaining({107 name: "Foo",108 severity: "info",109 message: "Hello World",110 context: "some context",111 }))112})113test("log warnings", ()=>{114 let s = reducers(initialState, warn("FOO", "Hello"));115 s = reducers(s, warn("World"));116 let lines = getLogs(s);117 expect(lines).toHaveLength(2);118 expect(lines[0]).toEqual(expect.objectContaining({119 name: "FOO",120 severity: "warn",121 message: "Hello"122 }))123 expect(lines[1]).toEqual(expect.objectContaining({124 name: "WARN",125 severity: "warn",126 message: "World"127 }))128})129test("log errors", ()=>{130 let s = reducers(initialState, error("FOO", "Hello"));131 s = reducers(s, error("World"));132 let lines = getLogs(s);133 expect(lines).toHaveLength(2);134 expect(lines[0]).toEqual(expect.objectContaining({135 name: "FOO",136 severity: "error",137 message: "Hello"138 }))139 expect(lines[1]).toEqual(expect.objectContaining({140 name: "ERROR",141 severity: "error",142 message: "World"143 }))144})145describe("serialize message", ()=>{146 class Foo{147 bar(){}148 toString(){return `[object Foo]`}149 }150 151 [152 ["null", null, "null"],153 ["number", 10, "10"],154 ["object", {foo: "Some Data"}, `[object Object]`],155 ["class", new Foo(), `[object Foo]`],156 ].forEach(([msg, src, res])=>{157 test(msg, ()=>{158 let s = reducers(initialState, info(src));159 expect(typeof getLogs(s)[0].message).toBe("string");160 expect(getLogs(s)[0].message).toEqual(res);161 })162 })...
script.js
Source:script.js
1data = document.getElementById("data").textContent2function formpage(data) {3 $('#data').innertext == data4 if ($('#data').innertext == undefined || $('#data').val() == "") {5 document.getElementById("data").textContent = data6 }7 $('#time').html(new Date())8 console.log(new Date(), data)9}10$(document).on("pageinit", "#form-entry", function (event) {11 console.log(data)12 if (data == undefined) {13 $('#some_error').popup("open")14 }15});16$(document).on('pageshow', '#form-entry', function () {17 console.log('pageshow');18 if (data == undefined || data == "") {19 $(location).attr('href', '#home')20 $('#some_error').popup("open")21 }22});23$(document).on('pageshow', '#logs', function () {24 // $('#logtab').empty()25 constructlogs()26});27///Save log data in local storage28var logged = []29function saveEntry() {30 // $('#some_error').popup("open")31 var contact, invoice, destination, data32 console.log("clicked")33 data = document.getElementById("data").textContent34 console.log()35 contact = $('#contact').val()36 invoice = $('#invoice').val()37 destination = $("#Destination").val()38 console.log(contact, invoice)39 if (contact == "") {40 $('#contact_error').popup("open")41 }42 else if (invoice == "") {43 $("#invoice_error").popup("open")44 }45 else if (data == "" || data == undefined) {46 $('#some_error').popup("open")47 }48 else {49 //check if storage is supported or not by browser50 if (typeof (Storage) !== "undefined") {51 // Store data52 //creating objects53 var log_object = ({54 "city": data55 , "contact": contact56 , "invoice": invoice57 , "destination": destination58 , "time": new Date()59 })60 //insert the data in to the array61 logged.push(log_object)62 localStorage.setItem("logger", JSON.stringify(logged));63 // var getlogs = JSON.parse(localStorage.getItem("logger"));64 }65 else {66 document.getElementById("no-support").innerHTML = "Sorry, your browser does not support Web Storage...,Open in Recommended Browsers";67 alert("local storage does'nt support")68 }69 //sucess dialog pop up70 $('#success-msg').popup("open")71 //clear filed on exit72 $('#contact').val('')73 $('#invoice').val('')74 }75}76//clearing form data77function reset() {78 $('#contact').val('') //clear contact field79 $('#invoice').val('') //clear invoice field80}81var table_html = ""82function constructlogs() {83 $('#logtab').empty()84 var getlogs = JSON.parse(localStorage.getItem("logger"));85 console.log(getlogs, typeof (getlogs))86 if (getlogs != null) {87 var table_head= "<tr> <th>City</th> <th>Contact   </th> <th>Invoice Number   </th> <th>Destination  </th> <th>Time</th> </tr>"88 $('#logtab').append(table_head)89 for (var i = 0; i < getlogs.length; i++) {90// if (document.getElementById("data").innerText == getlogs[i].city) {91 console.log(getlogs[i])92 table_html = "<tr> <td>" + getlogs[i].city + " </td><td>" + getlogs[i].contact + " </td><td>" + getlogs[i].invoice + " </td> <td> " + getlogs[i].destination + " </td><td> " + getlogs[i].time + " </td> </tr>";93 $('#logtab').append(table_html)94// }95 }96 }97}98function sendlogger(){99 $('#erase-log').popup("open")100}101function confirmed(){102 $('#erase-log').popup("close")103 setTimeout(function(){104 localStorage.clear()105 $('#success-log').popup("open")106 },600)107 ...
log-dialog-spec.js
Source:log-dialog-spec.js
1/** @babel */2import LogDialog from "../../lib/dialogs/LogDialog";3import {mockGit, createGitRoot} from "../mocks";4describe("LogDialog", function () {5 beforeEach(async function () {6 await atom.packages.activatePackage("git-menu");7 this.gitRoot = await createGitRoot();8 this.git = mockGit({9 log: () => Promise.resolve(""),10 });11 });12 describe("unescaping format", function () {13 beforeEach(function () {14 spyOn(this.git, "log").and.callThrough();15 });16 it("should change \\\\ to \\", function () {17 const dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\\\"});18 dialog.getLogs();19 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "\\");20 });21 it("should change \\\\n to %n", function () {22 const dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\n"});23 dialog.getLogs();24 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "%n");25 });26 it("should change \\\\t to \\t", function () {27 const dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\t"});28 dialog.getLogs();29 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "\t");30 });31 it("should not unescape a slash at the end", function () {32 let dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\n\\t\\"});33 dialog.getLogs();34 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "%n\t\\");35 this.git.log.calls.reset();36 dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\n\\t\\\\"});37 dialog.getLogs();38 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "%n\t\\");39 });40 it("should not unescape an odd number of slashes at the end", function () {41 let dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\n\\t\\\\\\"});42 dialog.getLogs();43 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "%n\t\\\\");44 this.git.log.calls.reset();45 dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: "\\n\\t\\\\\\\\"});46 dialog.getLogs();47 expect(this.git.log).toHaveBeenCalledWith(this.gitRoot, 10, 0, "%n\t\\\\");48 });49 });50 it("should call getLogs when scrolled to the bottom", function () {51 const dialog = new LogDialog({root: this.gitRoot, gitCmd: this.git, format: ""});52 spyOn(dialog, "getLogs");53 expect(dialog.getLogs).not.toHaveBeenCalled();54 dialog.scroll({55 target: {56 scrollHeight: 1000,57 scrollTop: 0,58 clientHeight: 100,59 },60 });61 expect(dialog.getLogs).not.toHaveBeenCalled();62 dialog.scroll({63 target: {64 scrollHeight: 1000,65 scrollTop: 900,66 clientHeight: 100,67 },68 });69 expect(dialog.getLogs).toHaveBeenCalled();70 });...
040-Model14Log.js
Source:040-Model14Log.js
1describe("Log model", function() {2 before(function(done){3 $fh.forms.config.set("logger", true);4 appForm.models.log.clearLogs(done);5 });6 it ("how to log error",function(){7 appForm.models.log.e("Error happens");8 assert.ok(appForm.models.log.getLogs()[0], "Expected an error log at position 0 but got nothing");9 assert(appForm.models.log.getLogs()[0].indexOf("Error happens")>-1, "Expected Error happens to be logged");10 });11 it ("how to log debug",function(){12 appForm.models.log.d("Debug happens");13 assert.ok(appForm.models.log.getLogs()[0], "Expected an debug log at position 0 but got nothing");14 assert(appForm.models.log.getLogs()[0].indexOf("Debug happens")===-1);15 });16 it ("should solve asynchours IO issue",function(done){17 appForm.models.log.clearLogs(function(err){18 assert(!err, "Expected no error: " + err);19 for (var i=0;i<100;i++){20 appForm.models.log.l("information");21 }22 setTimeout(function(){23 assert(appForm.models.log.getLogs().length==100);24 appForm.models.log.loadLocal(function(){25 assert(appForm.models.log.getLogs().length==100);26 done();27 });28 },500);29 });30 });31 it ("should under the limitation of configuration",function(done){32 for (var i=0;i<5000;i++){33 appForm.models.log.l("information");34 }35 setTimeout(function(){36 assert(appForm.models.log.getLogs().length==300);37 appForm.models.log.loadLocal(function(){38 assert(appForm.models.log.getLogs().length==300);39 done();40 });41 },500);42 });43 it ("should send logs email ",function(done){44 appForm.models.log.sendLogs(function(err){45 assert(!err || err =="send_nosupport");46 done();47 });48 });...
SearchBar.js
Source:SearchBar.js
1import React, { useRef } from 'react';2import { connect } from 'react-redux';3import PropTypes from 'prop-types';4import { searchLogs, getLogs } from '../../actions/logActions';5const SearchBar = ({ searchLogs, getLogs }) => {6 const text = useRef('');7 // reset text field, run getLogs8 const onClick = e => {9 text.current.value = '';10 getLogs();11 };12 // run when key released13 const onKeyUp = async e => {14 // run if back space pressed15 if (e.keyCode === 8) {16 // if text field empty, return all logs, else return searchLogs for text field value17 if (text.current.value !== '') {18 getLogs();19 }20 let temp = e.target.value;21 await getLogs();22 searchLogs(temp);23 // run for all other keys pressed24 } else if (text.current.value !== '') {25 searchLogs(e.target.value);26 } else {27 getLogs();28 }29 };30 return (31 <nav style={{ marginBottom: '30px' }} className='blue'>32 <div className='nav-wrapper'>33 <form>34 <div className='input-field'>35 <input36 id='search'37 type='search'38 placeholder='Search Logs...'39 ref={text}40 onKeyUp={onKeyUp}41 />42 <label className='label-icon' htmlFor='search'>43 <i className='material-icons'>search</i>44 </label>45 <i className='material-icons' onClick={onClick}>46 close47 </i>48 </div>49 </form>50 </div>51 </nav>52 );53};54SearchBar.propTypes = {55 searchLogs: PropTypes.func.isRequired,56 getLogs: PropTypes.func.isRequired57};...
Logs.js
Source:Logs.js
1import React, { useEffect } from 'react';2import { connect } from 'react-redux';3import LogItem from './LogItem';4import Preloader from '../layout/Preloader';5import PropTypes from 'prop-types';6import { getLogs } from '../../actions/logActions';7const Logs = ({ log: { logs, loading }, getLogs }) => {8 useEffect(() => {9 getLogs();10 // eslint-disable-next-line11 }, []);12 if (loading || logs === null) {13 return <Preloader />;14 }15 return (16 <ul className='collection with-header'>17 <li className='collection-header'>18 <h4 className='center'>System Logs</h4>19 </li>20 {!loading && logs.length === 0 ? (21 <p className='center'>No logs o show...</p>22 ) : (23 logs.map(log => <LogItem key={log.id} log={log} />)24 )}25 </ul>26 );27};28Logs.propTypes = {29 log: PropTypes.object.isRequired,30 getLogs: PropTypes.func.isRequired,31};32const mapStateToProps = state => ({33 log: state.log,34});...
Using AI Code Generation
1import { GetLogs } from '@redwoodjs/api'2export const handler = async (event, context) => {3 const logs = await GetLogs()4 return {5 body: JSON.stringify({ data: logs }),6 }7}
Using AI Code Generation
1var redwood = require('redwood');2var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());3var request = new redwood.GetLogsRequest();4request.setDeviceId(1);5request.setStart(0);6request.setEnd(100);7client.getLogs(request, function(err, response) {8 console.log(response);9});10var redwood = require('redwood');11var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());12var request = new redwood.SubscribeRequest();13request.setDeviceId(1);14request.setStart(0);15request.setEnd(100);16var call = client.subscribe(request);17call.on('data', function(response) {18 console.log(response);19});20call.on('end', function() {21 console.log('end');22});23var redwood = require('redwood');24var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());25var request = new redwood.AddLogRequest();26request.setDeviceId(1);27request.setTimestamp(100);28request.setPayload("test");29client.addLog(request, function(err, response) {30 console.log(response);31});32var redwood = require('redwood');33var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());34var request = new redwood.AddDeviceRequest();35request.setName("test");36request.setDescription("test");37request.setTopic("test");38client.addDevice(request, function(err, response) {39 console.log(response);40});41var redwood = require('redwood');42var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());43var request = new redwood.GetDevicesRequest();44client.getDevices(request, function(err, response) {45 console.log(response);46});47var redwood = require('redwood');48var client = new redwood.RedwoodClient('localhost:50051',redwood.credentials.createInsecure());49var request = new redwood.GetDeviceRequest();50request.setId(1);51client.getDevice(request, function(err, response) {52 console.log(response);
Using AI Code Generation
1const logger = require('redwood-logger')2const log = logger.createLogger('test', 'test')3log.info('test', 'test')4const logger = require('redwood-logger')5const log = logger.createLogger('test', 'test')6log.info('test', 'test')
Using AI Code Generation
1var Redwood = require('redwood');2var redwood = new Redwood({3});4var fs = require('fs');5var logFile = fs.createWriteStream('logs.txt', {flags: 'a'});6redwood.getLogs(function (err, logs) {7 if (err) {8 console.log('Error: ' + err);9 return;10 }11 console.log(logs);12 logFile.write(logs);13});
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!!