diff --git a/app/assets/javascripts/loginAlert.js b/app/assets/javascripts/loginAlert.js new file mode 100644 index 000000000..84c2ee6a8 --- /dev/null +++ b/app/assets/javascripts/loginAlert.js @@ -0,0 +1,35 @@ +(function (window) { + +// Set the target date (10 days before March 15th, 2024) + const targetDate = new Date("April 16, 2024 00:00:00").getTime(); + + // Function to update the countdown display + function updateCountdown() { + const now = new Date().getTime(); + const difference = targetDate - now; + + // Time calculations for days only + const days = Math.floor(difference / (1000 * 60 * 60 * 24)); + + // Visibility logic + if (days < 0 || days > 10) { + // Hide if more than 10 days away OR if already past the date + document.getElementById("countdown-container").style.display = "none"; + } else { + // Show if 10 days or less remaining + document.getElementById("countdown-container").style.display = "block"; + document.getElementById("countdown").innerHTML = days + " days "; + } + + } + + // Expose the updateCountdown function to the outside world + window.updateCountdown = updateCountdown; + + // Initial display update + updateCountdown(); + + // Update the countdown every second (inside the IIFE) + setInterval(updateCountdown, 1000); + +})(window); diff --git a/app/assets/sass/uswds/_uswds-theme-custom-styles.scss b/app/assets/sass/uswds/_uswds-theme-custom-styles.scss index 55f17a795..4a032a946 100644 --- a/app/assets/sass/uswds/_uswds-theme-custom-styles.scss +++ b/app/assets/sass/uswds/_uswds-theme-custom-styles.scss @@ -568,3 +568,9 @@ details form { .edit-textbox-error-mt { margin-top: 1.5rem; } + +// Login page + +#countdown-container { + display: none; // Hide the countdown timer +} diff --git a/app/templates/views/signin.html b/app/templates/views/signin.html index a19376d7c..6b4952b0c 100644 --- a/app/templates/views/signin.html +++ b/app/templates/views/signin.html @@ -12,9 +12,20 @@ {% block maincolumn_content %} +{% if login_gov_enabled %}
-
- +
+
+

Login.gov is required by April 16, 2024

+

+ You have left to use Login.gov to sign in +

+
+
+
+{% endif %} +
+
{% if again %}

You need to sign in again

{% if other_device %} @@ -29,9 +40,9 @@ {% else %}

Sign in

{% if login_gov_enabled %} - Sign in with Login.gov -

-

Or:

+

You can access your account by signing in with one of the options below:

+ Sign in with Login.gov +

Or:

{% endif %} {% endif %} @@ -41,6 +52,24 @@ {{ page_footer("Continue", secondary_link=password_reset_url, secondary_link_text="Forgot your password?") }} {% endcall %}
-
+ {% if login_gov_enabled %} +
+

Notify.gov is changing the sign-in experience to Login.gov effective
April 16, 2024

+

Why are we doing this?

+ +

What do I need to do?

+ +
+ Create Login.gov account +
+
+{% endif %} {% endblock %} diff --git a/gulpfile.js b/gulpfile.js index 6828bcaf1..79f976035 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -123,6 +123,7 @@ const javascripts = () => { paths.src + 'javascripts/homepage.js', paths.src + 'javascripts/timeoutPopup.js', paths.src + 'javascripts/date.js', + paths.src + 'javascripts/loginAlert.js', paths.src + 'javascripts/main.js', ]) .pipe(plugins.prettyerror()) diff --git a/tests/javascripts/loginAlert.test.js b/tests/javascripts/loginAlert.test.js new file mode 100644 index 000000000..085434b6a --- /dev/null +++ b/tests/javascripts/loginAlert.test.js @@ -0,0 +1,52 @@ +beforeAll(() => { + jest.spyOn(global, 'setTimeout'); + + document.body.innerHTML = ` +
+
+

Login.gov is required by April 16, 2024

+

+ You have left to use Login.gov to sign in +

+
+
+ ` + + const sessionTimerModule = require('../../app/assets/javascripts/loginAlert.js'); + window.GOVUK.modules.start(); +}); + +jest.useFakeTimers(); +const targetDate = new Date("April 16, 2024 00:00:00"); // Reference point + +test('Hides the countdown if more than 10 days away', () => { + jest.setSystemTime(targetDate.getTime() - 12 * 24 * 60 * 60 * 1000); // 12 days before + + window.updateCountdown(); // Update the countdown display + + expect(document.getElementById("countdown-container").style.display).toBe("none"); +}); + +test('Shows the countdown if 10 days or less away', () => { + jest.setSystemTime(targetDate.getTime() - 8 * 24 * 60 * 60 * 1000); + + window.updateCountdown(); + + expect(document.getElementById("countdown-container").style.display).toBe("block"); +}); + +test('Displays the correct number of days', () => { + jest.setSystemTime(targetDate.getTime() - 5 * 24 * 60 * 60 * 1000); + + window.updateCountdown(); + + expect(document.getElementById("countdown").textContent).toBe("5 days "); +}); + +test('Hides the countdown if the target date has passed', () => { + jest.setSystemTime(targetDate.getTime() + 2 * 24 * 60 * 60 * 1000); + + window.updateCountdown(); + + expect(document.getElementById("countdown-container").style.display).toBe("none"); +});