demo-orgs: Move helper function to get days remaining until deletion.

Moves the get_demo_organization_deadline_days_remaining helper from
"web/src/navbar_alerts.ts" to "web/src/demo_organizations_ui.ts".

Prep commit for updating the navbar alert for demo organization to
have a button that opens the modal for converting the organization
to a permanent organization.
This commit is contained in:
Lauryn Menard
2025-04-29 17:37:42 +02:00
committed by Tim Abbott
parent a9e3331fcc
commit d732a7b801
4 changed files with 39 additions and 24 deletions

View File

@@ -0,0 +1,27 @@
"use strict";
const assert = require("node:assert/strict");
const {addDays} = require("date-fns");
const {zrequire} = require("./lib/namespace.cjs");
const {run_test} = require("./lib/test.cjs");
const demo_organization_ui = zrequire("demo_organizations_ui");
const {set_realm} = zrequire("state_data");
const realm = {};
set_realm(realm);
run_test("get_demo_organization_deadline_days_remaining", ({override}) => {
const start_time = new Date("2024-01-01T10:00:00.000Z"); // Wednesday 1/1/2024 10:00:00 AM (UTC+0)
override(Date, "now", () => start_time);
const demo_organization_scheduled_deletion_date = addDays(start_time, 7); // Wednesday 1/8/2024 10:00:00 AM (UTC+0)
override(
realm,
"demo_organization_scheduled_deletion_date",
Math.trunc(demo_organization_scheduled_deletion_date / 1000),
);
assert.equal(demo_organization_ui.get_demo_organization_deadline_days_remaining(), 7);
});

View File

@@ -152,16 +152,3 @@ test("should_show_server_upgrade_banner", ({override}) => {
override(Date, "now", () => addDays(start_time, 8).getTime()); // Thursday 1/9/2024 10:00:00 AM (UTC+0)
assert.equal(navbar_alerts.should_show_server_upgrade_banner(ls), true);
});
test("get_demo_organization_deadline_days_remaining", ({override}) => {
const start_time = new Date("2024-01-01T10:00:00.000Z"); // Wednesday 1/1/2024 10:00:00 AM (UTC+0)
override(Date, "now", () => start_time);
const demo_organization_scheduled_deletion_date = addDays(start_time, 7); // Wednesday 1/8/2024 10:00:00 AM (UTC+0)
override(
realm,
"demo_organization_scheduled_deletion_date",
Math.trunc(demo_organization_scheduled_deletion_date / 1000),
);
assert.equal(navbar_alerts.get_demo_organization_deadline_days_remaining(), 7);
});