mirror of
https://github.com/fleetdm/fleet
synced 2026-05-24 09:28:54 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #44330, Resolves #44331 # Checklist for submitter - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests. (I'd defer integration tests to a separate PR since this one is pretty large already.) - [x] QA'd all new/changed functionality manually. I've tested this on both the setup flow and the organization settings page. I haven't had the time to test this on other places where we render the logo (macOS setup experience / MDM migration dialog). https://github.com/user-attachments/assets/95d4eae5-3da6-40f4-98a1-8575b97d96b3 ## New Fleet configuration settings - [x] Setting(s) is/are explicitly excluded from GitOps. Will handle GitOps in a separate PR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Organizations can upload custom logos for light and dark modes. * Registration and Org Settings support logo file upload, preview, per-mode replace/delete, and validation (size & image formats). * Activity feed records logo changes/deletions; site nav displays uploaded logos per theme. * File uploader/preview adds a Fleet logo graphic option and improved logo validation. * Config/GitOps outputs now include separate dark/light logo fields. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
101 lines
3.8 KiB
TypeScript
101 lines
3.8 KiB
TypeScript
import { getPastDate, getFutureDate } from "test/test-utils";
|
|
import type { IRegistrationFormData } from "interfaces/registration_form_data";
|
|
import helpers, {
|
|
removeOSPrefix,
|
|
compareVersions,
|
|
willExpireWithinXDays,
|
|
} from "./helpers";
|
|
|
|
describe("helpers utilities", () => {
|
|
describe("removeOSPrefix function", () => {
|
|
it("properly removes Apple prefix from a host's operating system version", () => {
|
|
expect(removeOSPrefix("macOS 14.1.2")).toEqual("14.1.2");
|
|
expect(removeOSPrefix("iOS 18.0")).toEqual("18.0");
|
|
expect(removeOSPrefix("iPadOS 17.5.1")).toEqual("17.5.1");
|
|
});
|
|
});
|
|
|
|
describe("compareVersions function", () => {
|
|
it("properly checks if a version is older than another", () => {
|
|
expect(compareVersions("14.4.1", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14.4.1", "14.5")).toEqual(-1);
|
|
expect(compareVersions("14.4.1", "15")).toEqual(-1);
|
|
|
|
expect(compareVersions("14.4", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14.4", "14.5")).toEqual(-1);
|
|
expect(compareVersions("14.4", "15")).toEqual(-1);
|
|
|
|
expect(compareVersions("14", "14.4.2")).toEqual(-1);
|
|
expect(compareVersions("14", "14.0.5")).toEqual(-1);
|
|
expect(compareVersions("14", "15")).toEqual(-1);
|
|
});
|
|
|
|
it("properly checks if a version is newer than another", () => {
|
|
expect(compareVersions("14.4.4", "14.4.3")).toEqual(1);
|
|
expect(compareVersions("14.3.4", "14.3")).toEqual(1);
|
|
expect(compareVersions("14.0.4", "14")).toEqual(1);
|
|
|
|
expect(compareVersions("14.5", "14.4.3")).toEqual(1);
|
|
expect(compareVersions("14.5", "14.3")).toEqual(1);
|
|
expect(compareVersions("14.5", "14")).toEqual(1);
|
|
|
|
expect(compareVersions("14", "13.9.21")).toEqual(1);
|
|
expect(compareVersions("14", "13.9")).toEqual(1);
|
|
expect(compareVersions("14", "13")).toEqual(1);
|
|
});
|
|
|
|
it("properly checks if a version is equal to another", () => {
|
|
expect(compareVersions("14.0.4", "14.0.4")).toEqual(0);
|
|
expect(compareVersions("14.3", "14.3")).toEqual(0);
|
|
expect(compareVersions("14", "14")).toEqual(0);
|
|
expect(compareVersions("14.3", "14.3.0")).toEqual(0);
|
|
expect(compareVersions("14", "14.0.0")).toEqual(0);
|
|
});
|
|
});
|
|
|
|
describe("willExpireWithinXDays function", () => {
|
|
it("will return true if the date is within x number of days", () => {
|
|
const fiveDaysFromNow = getFutureDate(5);
|
|
expect(willExpireWithinXDays(fiveDaysFromNow, 10)).toEqual(true);
|
|
|
|
const tenDaysFromNow = getFutureDate(10);
|
|
expect(willExpireWithinXDays(tenDaysFromNow, 30)).toEqual(true);
|
|
});
|
|
|
|
it("will return false if the date is not within x number of days", () => {
|
|
const thirtyDaysFromNow = getFutureDate(30);
|
|
expect(willExpireWithinXDays(thirtyDaysFromNow, 10)).toEqual(false);
|
|
|
|
const fiftyDaysFromNow = getFutureDate(50);
|
|
expect(willExpireWithinXDays(fiftyDaysFromNow, 30)).toEqual(false);
|
|
});
|
|
|
|
it("will return false if the date has already expired", () => {
|
|
const fiveDaysAgo = getPastDate(5);
|
|
expect(willExpireWithinXDays(fiveDaysAgo, 10)).toEqual(false);
|
|
|
|
const fiftyDaysAgo = getPastDate(50);
|
|
expect(willExpireWithinXDays(fiftyDaysAgo, 30)).toEqual(false);
|
|
});
|
|
});
|
|
|
|
describe("setupData function", () => {
|
|
it("excludes the org logo file from the JSON setup payload", () => {
|
|
const formData: IRegistrationFormData = {
|
|
email: "admin@example.com",
|
|
name: "Admin",
|
|
password: "password123",
|
|
password_confirmation: "password123",
|
|
org_name: "Fleet",
|
|
org_web_url: "",
|
|
org_logo_file: new File(["x"], "logo.png", { type: "image/png" }),
|
|
fleet_web_address: "",
|
|
server_url: "https://fleet.example.com",
|
|
};
|
|
|
|
const result = helpers.setupData(formData);
|
|
|
|
expect(result.org_info).toEqual({ org_name: "Fleet" });
|
|
});
|
|
});
|
|
});
|