From f257a38084dc10c9f86d7e06b81793003b4ce981 Mon Sep 17 00:00:00 2001 From: Andrew Shumway Date: Wed, 13 Sep 2023 12:44:40 -0600 Subject: [PATCH] Refactor code/initial tests --- app/assets/javascripts/timeoutPopup.js | 12 +++----- app/templates/admin_template.html | 41 -------------------------- tests/javascripts/timeoutPopup.test.js | 18 +++++++++++ 3 files changed, 22 insertions(+), 49 deletions(-) create mode 100644 tests/javascripts/timeoutPopup.test.js diff --git a/app/assets/javascripts/timeoutPopup.js b/app/assets/javascripts/timeoutPopup.js index af9a9d1cb..0a98ea3d7 100644 --- a/app/assets/javascripts/timeoutPopup.js +++ b/app/assets/javascripts/timeoutPopup.js @@ -12,21 +12,17 @@ var seconds = Math.floor((difference % (1000 * 60)) / 1000); document.getElementById("timeLeft").innerHTML = + minutes + "m " + seconds + "s"; showTimer(); - document.getElementById("logOutTimer").addEventListener("click", logoutByUser); + document.getElementById("logOutTimer").addEventListener("click", logoutUser); document.getElementById("extendSessionTimer").addEventListener("click", extendSession); if (difference < 0) { clearInterval(x); closeTimer(); - redirectToSignin(); + logoutUser(); } }, 1000); - }, 60 * 1000); + }, 25 * 60 * 1000); - function redirectToSignin() { - window.location.href = '/sign-in'; - } - - function logoutByUser() { + function logoutUser() { window.location.href = '/sign-out'; } diff --git a/app/templates/admin_template.html b/app/templates/admin_template.html index 86a9847c3..8a7aa49b1 100644 --- a/app/templates/admin_template.html +++ b/app/templates/admin_template.html @@ -11,47 +11,6 @@ {% endblock %} {% block head %} -{# {% if current_user.is_authenticated %}#} -{# {% block sessionUserWarning %}#} -{# #} -{#
#} -{#
#} -{#

#} -{# Your session will end soon.#} -{#

#} -{#
#} -{#

#} -{#

#} -{#
#} -{# #} -{# #} -{#
#} -{#
#} -{#
#} -{# #} -{# {% endblock %}#} -{# {% endif %}#} {%- for font in font_paths %} {%- endfor %} diff --git a/tests/javascripts/timeoutPopup.test.js b/tests/javascripts/timeoutPopup.test.js new file mode 100644 index 000000000..a91e667ea --- /dev/null +++ b/tests/javascripts/timeoutPopup.test.js @@ -0,0 +1,18 @@ +const timeoutPopup = require('../../app/assets/javascripts/timeoutPopup.js'); + + +describe('Test popup process', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + it('Test timers work', () => { + jest.runAllTimers(); + }); + +}); +