From fe34856be34bb51b9bd553ce41c524ec60ba1311 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Tue, 18 Mar 2025 01:34:55 +0530 Subject: [PATCH 01/16] Added dialog box --- frontend/src/js/controllers/profileCtrl.js | 26 ++++++++++++++++++- .../views/web/auth/token-expired-dialog.html | 13 ++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 frontend/src/views/web/auth/token-expired-dialog.html diff --git a/frontend/src/js/controllers/profileCtrl.js b/frontend/src/js/controllers/profileCtrl.js index 5545f14cda..fbf875bea3 100644 --- a/frontend/src/js/controllers/profileCtrl.js +++ b/frontend/src/js/controllers/profileCtrl.js @@ -88,6 +88,12 @@ vm.jsonResponse = response.data; vm.token = response.data['token']; vm.expiresAt = moment.utc(response.data['expires_at']).local().format("MMM D, YYYY h:mm:ss A"); + var expirationDateStr = response.data['expires_at']; + var expirationDate = new Date(expirationDateStr); + var currentDate = new Date(); + if (expirationDate < currentDate) { + vm.showTokenExpiredDialog(); + } let expiresAtOffset = new Date(vm.expiresAt).getTimezoneOffset(); var timezone = moment.tz.guess(); vm.expiresAtTimezone = moment.tz.zone(timezone).abbr(expiresAtOffset); @@ -182,7 +188,25 @@ } return (url.length <= 200); }; - + + vm.showTokenExpiredDialog = function() { + console.log("Token Expired Dialog Triggered!"); + $mdDialog.show({ + templateUrl: 'dist/views/web/auth/token-expired-dialog.html', + controller: ['$scope', '$mdDialog', function($scope, $mdDialog) { + $scope.refreshToken = function() { + $mdDialog.hide(); + vm.refreshToken(); + }; + + $scope.dismiss = function() { + $mdDialog.hide(); + }; + }] + }); + + }; + vm.editprofileDialog = function(ev) { switch (ev.currentTarget.id) { case "first_name": diff --git a/frontend/src/views/web/auth/token-expired-dialog.html b/frontend/src/views/web/auth/token-expired-dialog.html new file mode 100644 index 0000000000..4ad5ecc5d2 --- /dev/null +++ b/frontend/src/views/web/auth/token-expired-dialog.html @@ -0,0 +1,13 @@ + + +

Your authentication token has expired. Would you like to refresh it?

+
+ + + Dismiss + + + Refresh Token + + +
From 7e030c1a9226e8ff5e157fec806a31107078094d Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 19 Mar 2025 03:03:48 +0530 Subject: [PATCH 02/16] pretified the dialog box --- .../views/web/auth/token-expired-dialog.html | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/frontend/src/views/web/auth/token-expired-dialog.html b/frontend/src/views/web/auth/token-expired-dialog.html index 4ad5ecc5d2..2dd0081aae 100644 --- a/frontend/src/views/web/auth/token-expired-dialog.html +++ b/frontend/src/views/web/auth/token-expired-dialog.html @@ -1,13 +1,16 @@ - - -

Your authentication token has expired. Would you like to refresh it?

+ + +

Session Expired

+

+ Your authentication token has expired. Please refresh it to continue. +

- - - Dismiss + + + Cancel - - Refresh Token + + Submit
From 29f8239d0a793660be711543e223f7fc25fe75c1 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Thu, 20 Mar 2025 23:17:23 +0530 Subject: [PATCH 03/16] Changes --- frontend/src/js/controllers/profileCtrl.js | 1 - ...token-expired-dialog.html => auth-token-expired-dialog.html} | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) rename frontend/src/views/web/auth/{token-expired-dialog.html => auth-token-expired-dialog.html} (92%) diff --git a/frontend/src/js/controllers/profileCtrl.js b/frontend/src/js/controllers/profileCtrl.js index fbf875bea3..50e168e0c9 100644 --- a/frontend/src/js/controllers/profileCtrl.js +++ b/frontend/src/js/controllers/profileCtrl.js @@ -190,7 +190,6 @@ }; vm.showTokenExpiredDialog = function() { - console.log("Token Expired Dialog Triggered!"); $mdDialog.show({ templateUrl: 'dist/views/web/auth/token-expired-dialog.html', controller: ['$scope', '$mdDialog', function($scope, $mdDialog) { diff --git a/frontend/src/views/web/auth/token-expired-dialog.html b/frontend/src/views/web/auth/auth-token-expired-dialog.html similarity index 92% rename from frontend/src/views/web/auth/token-expired-dialog.html rename to frontend/src/views/web/auth/auth-token-expired-dialog.html index 2dd0081aae..89b4bc1997 100644 --- a/frontend/src/views/web/auth/token-expired-dialog.html +++ b/frontend/src/views/web/auth/auth-token-expired-dialog.html @@ -1,6 +1,6 @@ -

Session Expired

+

Auth Token Expired

Your authentication token has expired. Please refresh it to continue.

From 1767a4a7b5dbc8b020cadf1218ceee41351a6cb2 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Thu, 20 Mar 2025 23:42:54 +0530 Subject: [PATCH 04/16] Test Cases --- .../controllers-test/profileCtrl.test.js | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index d6f4ae3d9c..82b47ac3a4 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -162,6 +162,60 @@ describe('Unit tests for profile controller', function () { expect($mdDialog.hide).toHaveBeenCalled(); }); }); + describe('Unit tests for Token Expired Dialog', function () { + var $mdDialog, vm, $rootScope, $scope, createController; + + beforeEach(angular.mock.module('evalai')); + + beforeEach(inject(function (_$controller_, _$rootScope_, _$mdDialog_) { + $mdDialog = _$mdDialog_; + $rootScope = _$rootScope_; + $scope = $rootScope.$new(); + + createController = function () { + return _$controller_('profileCtrl', { $scope: $scope }); + }; + vm = createController(); + })); + + it('should open the token expired dialog', function () { + spyOn(console, 'log'); + spyOn($mdDialog, 'show'); + + vm.showTokenExpiredDialog(); + + expect(console.log).toHaveBeenCalledWith("Token Expired Dialog Triggered!"); + expect($mdDialog.show).toHaveBeenCalledWith({ + templateUrl: 'dist/views/web/auth/auth-token-expired-dialog.html', + controller: jasmine.any(Array) + }); + }); + + it('should refresh token when refreshToken is called', function () { + spyOn(vm, 'refreshToken'); + spyOn($mdDialog, 'hide'); + + var dialogController = $mdDialog.show.calls.mostRecent().args[0].controller[2]; + var dialogScope = {}; + dialogController(dialogScope, $mdDialog); + dialogScope.refreshToken(); + + expect($mdDialog.hide).toHaveBeenCalled(); + expect(vm.refreshToken).toHaveBeenCalled(); + }); + + it('should dismiss the dialog when dismiss is called', function () { + spyOn($mdDialog, 'hide'); + + var dialogController = $mdDialog.show.calls.mostRecent().args[0].controller[2]; + var dialogScope = {}; + dialogController(dialogScope, $mdDialog); + dialogScope.dismiss(); + + expect($mdDialog.hide).toHaveBeenCalled(); + }); + }); + describe('Unit tests for `updateProfile` function', function () { var success, tryClauseResponse; From 05ceb30f6b22c1e61cdec6ed3e2ea2ff8e04e1a5 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Fri, 21 Mar 2025 00:19:52 +0530 Subject: [PATCH 05/16] Test Cases --- .../controllers-test/profileCtrl.test.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 82b47ac3a4..6339803f2e 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -162,21 +162,24 @@ describe('Unit tests for profile controller', function () { expect($mdDialog.hide).toHaveBeenCalled(); }); }); + describe('Unit tests for Token Expired Dialog', function () { var $mdDialog, vm, $rootScope, $scope, createController; - beforeEach(angular.mock.module('evalai')); + beforeEach(function () { + angular.mock.module('evalai'); - beforeEach(inject(function (_$controller_, _$rootScope_, _$mdDialog_) { - $mdDialog = _$mdDialog_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); + inject(function (_$controller_, _$rootScope_, _$mdDialog_) { + $mdDialog = _$mdDialog_; + $rootScope = _$rootScope_; + $scope = $rootScope.$new(); - createController = function () { - return _$controller_('profileCtrl', { $scope: $scope }); - }; - vm = createController(); - })); + createController = function () { + return _$controller_('profileCtrl', { $scope: $scope }); + }; + vm = createController(); + }); + }); it('should open the token expired dialog', function () { spyOn(console, 'log'); From d227ecceed412beb5e9f35543fa039c8b59d9435 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 09:39:34 +0530 Subject: [PATCH 06/16] Added Test --- .../controllers-test/profileCtrl.test.js | 197 +++++++++++++----- 1 file changed, 140 insertions(+), 57 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 6339803f2e..afefd5e40d 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -163,63 +163,6 @@ describe('Unit tests for profile controller', function () { }); }); - describe('Unit tests for Token Expired Dialog', function () { - var $mdDialog, vm, $rootScope, $scope, createController; - - beforeEach(function () { - angular.mock.module('evalai'); - - inject(function (_$controller_, _$rootScope_, _$mdDialog_) { - $mdDialog = _$mdDialog_; - $rootScope = _$rootScope_; - $scope = $rootScope.$new(); - - createController = function () { - return _$controller_('profileCtrl', { $scope: $scope }); - }; - vm = createController(); - }); - }); - - it('should open the token expired dialog', function () { - spyOn(console, 'log'); - spyOn($mdDialog, 'show'); - - vm.showTokenExpiredDialog(); - - expect(console.log).toHaveBeenCalledWith("Token Expired Dialog Triggered!"); - expect($mdDialog.show).toHaveBeenCalledWith({ - templateUrl: 'dist/views/web/auth/auth-token-expired-dialog.html', - controller: jasmine.any(Array) - }); - }); - - it('should refresh token when refreshToken is called', function () { - spyOn(vm, 'refreshToken'); - spyOn($mdDialog, 'hide'); - - var dialogController = $mdDialog.show.calls.mostRecent().args[0].controller[2]; - var dialogScope = {}; - dialogController(dialogScope, $mdDialog); - dialogScope.refreshToken(); - - expect($mdDialog.hide).toHaveBeenCalled(); - expect(vm.refreshToken).toHaveBeenCalled(); - }); - - it('should dismiss the dialog when dismiss is called', function () { - spyOn($mdDialog, 'hide'); - - var dialogController = $mdDialog.show.calls.mostRecent().args[0].controller[2]; - var dialogScope = {}; - dialogController(dialogScope, $mdDialog); - dialogScope.dismiss(); - - expect($mdDialog.hide).toHaveBeenCalled(); - }); - }); - - describe('Unit tests for `updateProfile` function', function () { var success, tryClauseResponse; var usernameInvalid = { @@ -371,3 +314,143 @@ describe('Unit tests for profile controller', function () { }); }); }); + +describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + spyOn($mdDialog, 'show').and.callFake(function (options) { + var fakeScope = $rootScope.$new(); + options.controller(fakeScope, $mdDialog); + + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + if (confirmCallback) confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + // Simulate user clicking 'refreshToken' + var testScope = $rootScope.$new(); + dialogArgs.controller(testScope, $mdDialog); + testScope.refreshToken(); + expect(vm.refreshToken).toHaveBeenCalled(); + }); +}); + +describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + spyOn($mdDialog, 'show').and.callFake(function (options) { + var fakeScope = $rootScope.$new(); + options.controller(fakeScope, $mdDialog); + + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + if (confirmCallback) confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + // Simulate user clicking 'refreshToken' + var testScope = $rootScope.$new(); + dialogArgs.controller(testScope, $mdDialog); + testScope.refreshToken(); + expect(vm.refreshToken).toHaveBeenCalled(); + }); +}); + +describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + spyOn($mdDialog, 'show').and.callFake(function (options) { + var fakeScope = $rootScope.$new(); + options.controller(fakeScope, $mdDialog); + + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + if (confirmCallback) confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + // Simulate user clicking 'refreshToken' + var testScope = $rootScope.$new(); + dialogArgs.controller(testScope, $mdDialog); + testScope.refreshToken(); + expect(vm.refreshToken).toHaveBeenCalled(); + }); +}); + +describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + // Mocking $mdDialog.show + spyOn($mdDialog, 'show').and.callFake(function (options) { + // Create a new scope to test the dialog controller + var fakeScope = $rootScope.$new(); + options.controller(fakeScope, $mdDialog); + + // Verify the functions inside the controller + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + // Simulate success (dialog closed) + confirmCallback && confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Track if refreshToken gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + // Simulate user clicking 'refreshToken' + var testScope = $rootScope.$new(); + dialogArgs.controller(testScope, $mdDialog); + testScope.refreshToken(); + expect(vm.refreshToken).toHaveBeenCalled(); + }); +}); From da1dd10f6611b291605571d5352b2eef7f6f2c04 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 09:41:23 +0530 Subject: [PATCH 07/16] Changes --- frontend/src/views/web/auth/auth-token-expired-dialog.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/views/web/auth/auth-token-expired-dialog.html b/frontend/src/views/web/auth/auth-token-expired-dialog.html index 89b4bc1997..f99ded98ce 100644 --- a/frontend/src/views/web/auth/auth-token-expired-dialog.html +++ b/frontend/src/views/web/auth/auth-token-expired-dialog.html @@ -10,7 +10,7 @@

Auth Token Expired

Cancel - Submit + Refresh
From a0b3c4a3f5929de3a537634382a9c0eb8cce9dc7 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 10:11:44 +0530 Subject: [PATCH 08/16] Added Test --- .../controllers-test/profileCtrl.test.js | 104 ------------------ 1 file changed, 104 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index afefd5e40d..7350fbfe8a 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -338,74 +338,7 @@ describe('Unit tests for showTokenExpiredDialog function', function () { vm.showTokenExpiredDialog(); expect($mdDialog.show).toHaveBeenCalled(); - var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); - - // Simulate user clicking 'refreshToken' - var testScope = $rootScope.$new(); - dialogArgs.controller(testScope, $mdDialog); - testScope.refreshToken(); - expect(vm.refreshToken).toHaveBeenCalled(); - }); -}); - -describe('Unit tests for showTokenExpiredDialog function', function () { - beforeEach(function () { - spyOn($mdDialog, 'show').and.callFake(function (options) { - var fakeScope = $rootScope.$new(); - options.controller(fakeScope, $mdDialog); - - expect(typeof fakeScope.refreshToken).toBe('function'); - expect(typeof fakeScope.dismiss).toBe('function'); - - return { - then: function (confirmCallback, cancelCallback) { - if (confirmCallback) confirmCallback(); - } - }; - }); - - spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called - }); - - it('should open token expired dialog with correct config and call refreshToken', function () { - vm.showTokenExpiredDialog(); - - expect($mdDialog.show).toHaveBeenCalled(); - var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); - - // Simulate user clicking 'refreshToken' - var testScope = $rootScope.$new(); - dialogArgs.controller(testScope, $mdDialog); - testScope.refreshToken(); - expect(vm.refreshToken).toHaveBeenCalled(); - }); -}); - -describe('Unit tests for showTokenExpiredDialog function', function () { - beforeEach(function () { - spyOn($mdDialog, 'show').and.callFake(function (options) { - var fakeScope = $rootScope.$new(); - options.controller(fakeScope, $mdDialog); - - expect(typeof fakeScope.refreshToken).toBe('function'); - expect(typeof fakeScope.dismiss).toBe('function'); - return { - then: function (confirmCallback, cancelCallback) { - if (confirmCallback) confirmCallback(); - } - }; - }); - - spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called - }); - - it('should open token expired dialog with correct config and call refreshToken', function () { - vm.showTokenExpiredDialog(); - - expect($mdDialog.show).toHaveBeenCalled(); var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); @@ -413,44 +346,7 @@ describe('Unit tests for showTokenExpiredDialog function', function () { var testScope = $rootScope.$new(); dialogArgs.controller(testScope, $mdDialog); testScope.refreshToken(); - expect(vm.refreshToken).toHaveBeenCalled(); - }); -}); -describe('Unit tests for showTokenExpiredDialog function', function () { - beforeEach(function () { - // Mocking $mdDialog.show - spyOn($mdDialog, 'show').and.callFake(function (options) { - // Create a new scope to test the dialog controller - var fakeScope = $rootScope.$new(); - options.controller(fakeScope, $mdDialog); - - // Verify the functions inside the controller - expect(typeof fakeScope.refreshToken).toBe('function'); - expect(typeof fakeScope.dismiss).toBe('function'); - - return { - then: function (confirmCallback, cancelCallback) { - // Simulate success (dialog closed) - confirmCallback && confirmCallback(); - } - }; - }); - - spyOn(vm, 'refreshToken'); // Track if refreshToken gets called - }); - - it('should open token expired dialog with correct config and call refreshToken', function () { - vm.showTokenExpiredDialog(); - - expect($mdDialog.show).toHaveBeenCalled(); - var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); - - // Simulate user clicking 'refreshToken' - var testScope = $rootScope.$new(); - dialogArgs.controller(testScope, $mdDialog); - testScope.refreshToken(); expect(vm.refreshToken).toHaveBeenCalled(); }); }); From ae716aba6223fa81df8d27581969a1c02bd75181 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 11:28:00 +0530 Subject: [PATCH 09/16] Added Test --- .../controllers-test/profileCtrl.test.js | 68 ++++++++++--------- 1 file changed, 35 insertions(+), 33 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 7350fbfe8a..da68496273 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -313,40 +313,42 @@ describe('Unit tests for profile controller', function () { expect($rootScope.notify).toHaveBeenCalledWith("error", errorResponse.error); }); }); -}); - -describe('Unit tests for showTokenExpiredDialog function', function () { - beforeEach(function () { - spyOn($mdDialog, 'show').and.callFake(function (options) { - var fakeScope = $rootScope.$new(); - options.controller(fakeScope, $mdDialog); - - expect(typeof fakeScope.refreshToken).toBe('function'); - expect(typeof fakeScope.dismiss).toBe('function'); - return { - then: function (confirmCallback, cancelCallback) { - if (confirmCallback) confirmCallback(); - } - }; + describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + spyOn($mdDialog, 'show').and.callFake(function (options) { + var fakeScope = $rootScope.$new(); + options.controller(fakeScope, $mdDialog); + + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + if (confirmCallback) confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + // Simulate user clicking 'refreshToken' + var testScope = $rootScope.$new(); + dialogArgs.controller(testScope, $mdDialog); + testScope.refreshToken(); + + expect(vm.refreshToken).toHaveBeenCalled(); }); - - spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called - }); - - it('should open token expired dialog with correct config and call refreshToken', function () { - vm.showTokenExpiredDialog(); - - expect($mdDialog.show).toHaveBeenCalled(); - - var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); - - // Simulate user clicking 'refreshToken' - var testScope = $rootScope.$new(); - dialogArgs.controller(testScope, $mdDialog); - testScope.refreshToken(); - - expect(vm.refreshToken).toHaveBeenCalled(); }); + }); + From 320d59a8818b3360c6b3a7fe91d0c1ffdeac6aba Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 17:01:35 +0530 Subject: [PATCH 10/16] Added Test --- .../tests/controllers-test/profileCtrl.test.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index da68496273..fa05378c4f 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -318,7 +318,13 @@ describe('Unit tests for profile controller', function () { beforeEach(function () { spyOn($mdDialog, 'show').and.callFake(function (options) { var fakeScope = $rootScope.$new(); - options.controller(fakeScope, $mdDialog); + + // ✅ Get the actual controller function from the inline array + var controllerFn = Array.isArray(options.controller) + ? options.controller[options.controller.length - 1] + : options.controller; + + controllerFn(fakeScope, $mdDialog); expect(typeof fakeScope.refreshToken).toBe('function'); expect(typeof fakeScope.dismiss).toBe('function'); @@ -341,14 +347,18 @@ describe('Unit tests for profile controller', function () { var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); - // Simulate user clicking 'refreshToken' var testScope = $rootScope.$new(); - dialogArgs.controller(testScope, $mdDialog); + var controllerFn = Array.isArray(dialogArgs.controller) + ? dialogArgs.controller[dialogArgs.controller.length - 1] + : dialogArgs.controller; + + controllerFn(testScope, $mdDialog); testScope.refreshToken(); expect(vm.refreshToken).toHaveBeenCalled(); }); }); + }); From 3771335ebb6d0933ac368525e39d33c2863376af Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 2 Apr 2025 17:30:05 +0530 Subject: [PATCH 11/16] Added Test --- frontend/tests/controllers-test/profileCtrl.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index fa05378c4f..3f100253dd 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -319,7 +319,6 @@ describe('Unit tests for profile controller', function () { spyOn($mdDialog, 'show').and.callFake(function (options) { var fakeScope = $rootScope.$new(); - // ✅ Get the actual controller function from the inline array var controllerFn = Array.isArray(options.controller) ? options.controller[options.controller.length - 1] : options.controller; From 658be5f06d3685ffddb7f7e3a2afd16bc4dfd52f Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 23 Apr 2025 11:59:51 +0530 Subject: [PATCH 12/16] Merged from upstream --- .../controllers-test/profileCtrl.test.js | 58 ++++++++----------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 3f100253dd..ba6e0dac57 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -314,50 +314,40 @@ describe('Unit tests for profile controller', function () { }); }); - describe('Unit tests for showTokenExpiredDialog function', function () { - beforeEach(function () { - spyOn($mdDialog, 'show').and.callFake(function (options) { - var fakeScope = $rootScope.$new(); - - var controllerFn = Array.isArray(options.controller) - ? options.controller[options.controller.length - 1] - : options.controller; - - controllerFn(fakeScope, $mdDialog); + describe('Unit tests for isURLValid function', function () { + it('should allow empty URLs', function () { + var result = vm.isURLValid(''); + expect(result).toBeTruthy(); - expect(typeof fakeScope.refreshToken).toBe('function'); - expect(typeof fakeScope.dismiss).toBe('function'); - - return { - then: function (confirmCallback, cancelCallback) { - if (confirmCallback) confirmCallback(); - } - }; - }); + result = vm.isURLValid(null); + expect(result).toBeTruthy(); - spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + result = vm.isURLValid(undefined); + expect(result).toBeTruthy(); }); - it('should open token expired dialog with correct config and call refreshToken', function () { - vm.showTokenExpiredDialog(); + it('should return true for valid URLs within 200 characters', function () { + var result = vm.isURLValid('https://github.com'); + expect(result).toBeTruthy(); - expect($mdDialog.show).toHaveBeenCalled(); + result = vm.isURLValid('http://example.com/path?query=param'); + expect(result).toBeTruthy(); - var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + result = vm.isURLValid('https://sub.domain.example.com/long-path/to/resource?query=1&more=2'); + expect(result).toBeTruthy(); + }); - var testScope = $rootScope.$new(); - var controllerFn = Array.isArray(dialogArgs.controller) - ? dialogArgs.controller[dialogArgs.controller.length - 1] - : dialogArgs.controller; + it('should return false for invalid URLs or overly long ones', function () { + var result = vm.isURLValid('invalid-url'); + expect(result).toBeFalsy(); - controllerFn(testScope, $mdDialog); - testScope.refreshToken(); + result = vm.isURLValid('htp://missing-schema.com'); + expect(result).toBeFalsy(); - expect(vm.refreshToken).toHaveBeenCalled(); + var longUrl = 'http://example.com/' + 'a'.repeat(201); + result = vm.isURLValid(longUrl); + expect(result).toBeFalsy(); }); }); - }); - From 18749803a3eea739d667b158c6871388ddbe4707 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Wed, 23 Apr 2025 12:01:35 +0530 Subject: [PATCH 13/16] Resolved Conflicts --- .../controllers-test/profileCtrl.test.js | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index ba6e0dac57..98d80b4fe0 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -349,5 +349,49 @@ describe('Unit tests for profile controller', function () { expect(result).toBeFalsy(); }); }); + + describe('Unit tests for showTokenExpiredDialog function', function () { + beforeEach(function () { + spyOn($mdDialog, 'show').and.callFake(function (options) { + var fakeScope = $rootScope.$new(); + + var controllerFn = Array.isArray(options.controller) + ? options.controller[options.controller.length - 1] + : options.controller; + + controllerFn(fakeScope, $mdDialog); + + expect(typeof fakeScope.refreshToken).toBe('function'); + expect(typeof fakeScope.dismiss).toBe('function'); + + return { + then: function (confirmCallback, cancelCallback) { + if (confirmCallback) confirmCallback(); + } + }; + }); + + spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + }); + + it('should open token expired dialog with correct config and call refreshToken', function () { + vm.showTokenExpiredDialog(); + + expect($mdDialog.show).toHaveBeenCalled(); + + var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + + var testScope = $rootScope.$new(); + var controllerFn = Array.isArray(dialogArgs.controller) + ? dialogArgs.controller[dialogArgs.controller.length - 1] + : dialogArgs.controller; + + controllerFn(testScope, $mdDialog); + testScope.refreshToken(); + + expect(vm.refreshToken).toHaveBeenCalled(); + }); + }); }); From da4430e40326ed765fa1b6541c17aa3155b1c046 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Fri, 2 May 2025 14:25:59 +0530 Subject: [PATCH 14/16] Changes Made --- frontend/src/js/controllers/profileCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/js/controllers/profileCtrl.js b/frontend/src/js/controllers/profileCtrl.js index 50e168e0c9..e22261f579 100644 --- a/frontend/src/js/controllers/profileCtrl.js +++ b/frontend/src/js/controllers/profileCtrl.js @@ -191,7 +191,7 @@ vm.showTokenExpiredDialog = function() { $mdDialog.show({ - templateUrl: 'dist/views/web/auth/token-expired-dialog.html', + templateUrl: 'dist/views/web/auth/auth-token-expired-dialog.html', controller: ['$scope', '$mdDialog', function($scope, $mdDialog) { $scope.refreshToken = function() { $mdDialog.hide(); From 413f1d62b2b87dbea7095e8f45ad7bbbdb33c159 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Fri, 2 May 2025 15:23:03 +0530 Subject: [PATCH 15/16] Made Changes --- frontend/tests/controllers-test/profileCtrl.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index 98d80b4fe0..f6ea1d0e87 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -380,7 +380,7 @@ describe('Unit tests for profile controller', function () { expect($mdDialog.show).toHaveBeenCalled(); var dialogArgs = $mdDialog.show.calls.mostRecent().args[0]; - expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/token-expired-dialog.html'); + expect(dialogArgs.templateUrl).toBe('dist/views/web/auth/auth-token-expired-dialog.html'); var testScope = $rootScope.$new(); var controllerFn = Array.isArray(dialogArgs.controller) From 1c92f16e727d1db19208af9744fb8dab6a3a5193 Mon Sep 17 00:00:00 2001 From: Akshat Singh Date: Fri, 2 May 2025 16:21:43 +0530 Subject: [PATCH 16/16] Made Changes --- frontend/tests/controllers-test/profileCtrl.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/tests/controllers-test/profileCtrl.test.js b/frontend/tests/controllers-test/profileCtrl.test.js index f6ea1d0e87..e6c65a0364 100644 --- a/frontend/tests/controllers-test/profileCtrl.test.js +++ b/frontend/tests/controllers-test/profileCtrl.test.js @@ -371,7 +371,7 @@ describe('Unit tests for profile controller', function () { }; }); - spyOn(vm, 'refreshToken'); // Spy on refreshToken to ensure it gets called + spyOn(vm, 'refreshToken'); }); it('should open token expired dialog with correct config and call refreshToken', function () {