Fix datetime formatting in MDM status modal (#43214)

Fixes #43186
This commit is contained in:
Carlo 2026-04-08 15:48:27 -04:00 committed by GitHub
parent 91160dedc2
commit 4df3012906
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 5 deletions

View file

@ -293,6 +293,34 @@ describe("MDMStatusModal - component", () => {
});
});
it("renders 'Never' for zero-value profile timestamps", async () => {
(hostAPI.getDepAssignment as jest.Mock).mockResolvedValue({
...mockDepAssignmentResponse,
dep_device: {
...mockDepAssignmentResponse.dep_device,
profile_assign_time: "0001-01-01T00:00:00Z",
profile_push_time: "0001-01-01T00:00:00Z",
},
});
render(
<MDMStatusModal
hostId={3}
enrollmentStatus="On (manual)"
router={mockRouter}
isPremiumTier
isAppleDevice
onExit={jest.fn()}
/>
);
await screen.findByText("Profile assigned");
const neverTexts = screen.getAllByText("Never");
// Both profile_assign_time and profile_push_time should show "Never"
expect(neverTexts.length).toBeGreaterThanOrEqual(2);
});
it("calls onExit when Close is clicked", async () => {
(hostAPI.getDepAssignment as jest.Mock).mockResolvedValue(
mockDepAssignmentResponse

View file

@ -7,6 +7,7 @@ import { addHours, differenceInMinutes } from "date-fns";
import { internationalTimeFormat } from "utilities/helpers";
import {
DEFAULT_EMPTY_CELL_VALUE,
INITIAL_FLEET_DATE,
LEARN_MORE_ABOUT_BASE_LINK,
MDM_STATUS_TOOLTIP,
} from "utilities/constants";
@ -371,9 +372,13 @@ const MDMStatusModal = ({
</>
),
// Follow current pattern of international time format for dates in UI
status: internationalTimeFormat(
new Date(depAssignmentData.dep_device?.profile_assign_time)
),
status:
!depAssignmentData.dep_device?.profile_assign_time ||
depAssignmentData.dep_device.profile_assign_time < INITIAL_FLEET_DATE
? "Never"
: internationalTimeFormat(
new Date(depAssignmentData.dep_device.profile_assign_time)
),
},
{
id: "profile-pushed",
@ -387,8 +392,9 @@ const MDMStatusModal = ({
),
// Follow current pattern of international time format for dates in UI
status:
depAssignmentData.dep_device.profile_push_time === ""
? DEFAULT_EMPTY_CELL_VALUE
!depAssignmentData.dep_device.profile_push_time ||
depAssignmentData.dep_device.profile_push_time < INITIAL_FLEET_DATE
? "Never"
: internationalTimeFormat(
new Date(depAssignmentData.dep_device.profile_push_time)
),