Files
api/web/__test__/composables/dateTime.test.ts
Eli Bosley 73b2ce360c fix: update @unraid/shared-callbacks to version 3.0.0 (#1831)
…on and pnpm-lock.yaml

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added a standalone redirect page that shows "Redirecting..." and
navigates automatically.

* **Improvements**
* Redirect preserves hash callback data, validates targets, and logs the
computed redirect.
  * Purchase callback origin changed to a different account host.
* Date/time formatting now tolerates missing or empty server formats
with safe fallbacks.
  * Redirect page included in backup/restore.

* **Tests**
  * Added tests covering date/time formatting fallbacks.

* **Chores**
  * Dependency @unraid/shared-callbacks upgraded.
  * Removed multiple demo/debug pages and related test UIs.

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-12-15 16:20:18 -05:00

59 lines
2.0 KiB
TypeScript

import { defineComponent } from 'vue';
import { mount } from '@vue/test-utils';
import dayjs from 'dayjs';
import { describe, expect, it } from 'vitest';
import type { ServerDateTimeFormat } from '~/types/server';
import useDateTimeHelper from '~/composables/dateTime';
import { testTranslate } from '../utils/i18n';
const formatDateWithComponent = (
dateTimeFormat: ServerDateTimeFormat | undefined,
hideMinutesSeconds: boolean,
providedDateTime: number
) => {
const wrapper = mount(
defineComponent({
setup() {
const { outputDateTimeFormatted } = useDateTimeHelper(
dateTimeFormat,
testTranslate,
hideMinutesSeconds,
providedDateTime
);
return { outputDateTimeFormatted };
},
template: '<div />',
})
);
const output = (wrapper.vm as unknown as { outputDateTimeFormatted: string | { value: string } })
.outputDateTimeFormatted;
return typeof output === 'string' ? output : output.value;
};
describe('useDateTimeHelper', () => {
it('falls back to default date format when server format is empty', () => {
const timestamp = new Date(2025, 0, 2, 3, 4, 5).getTime();
const formatted = formatDateWithComponent({ date: '', time: '' }, true, timestamp);
expect(formatted).toBe(dayjs(timestamp).format('dddd, MMMM D, YYYY'));
});
it('falls back to default date format when server format is unknown', () => {
const timestamp = new Date(2025, 0, 2, 3, 4, 5).getTime();
const formatted = formatDateWithComponent({ date: '%Q', time: '%Q' }, true, timestamp);
expect(formatted).toBe(dayjs(timestamp).format('dddd, MMMM D, YYYY'));
});
it('falls back to default time format when server time format is unknown', () => {
const timestamp = new Date(2025, 0, 2, 3, 4, 5).getTime();
const formatted = formatDateWithComponent({ date: '%c', time: '%Q' }, false, timestamp);
expect(formatted).toBe(dayjs(timestamp).format('ddd, D MMMM YYYY hh:mma'));
});
});