Files
raucao f7b174017a Add clock time-format settings and honor them in the clock
Clicking the clock opens a settings dialog; the clock renders the time with a smaller day period when the format shows one.
2026-10-27 21:49:03 +04:00

62 lines
2.1 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, click } from '@ember/test-helpers';
import DefaultClock from 'dashtab/components/default-clock.gjs';
import ClockForm from 'dashtab/components/settings/clock-form';
import { timeParts } from 'dashtab/utils/time-format';
const DATE = new Date(2026, 7, 3, 13, 5);
function registerServices(owner, overrides = {}) {
const clock = overrides.clock ?? { time: DATE, timeFormat: '24h' };
const modal = overrides.modal ?? {
opened: null,
open(descriptor) {
this.opened = descriptor;
},
};
const storage = overrides.storage ?? { get: async () => null };
owner.register('service:clock', clock, { instantiate: false });
owner.register('service:modal', modal, { instantiate: false });
owner.register('service:storage', storage, { instantiate: false });
return { clock, modal, storage };
}
module('Integration | Component | default-clock', function (hooks) {
setupRenderingTest(hooks);
test('renders the time in the configured 24-hour format', async function (assert) {
registerServices(this.owner, { clock: { time: DATE, timeFormat: '24h' } });
await render(<template><DefaultClock /></template>);
const { time, period } = timeParts(DATE, '24h');
assert.strictEqual(period, '');
assert.dom('[aria-label="Edit clock settings"]').containsText(time);
});
test('renders the day period smaller in 12-hour format', async function (assert) {
registerServices(this.owner, { clock: { time: DATE, timeFormat: '12h' } });
await render(<template><DefaultClock /></template>);
const { period } = timeParts(DATE, '12h');
assert.ok(period.length > 0);
assert.dom('[aria-label="Edit clock settings"] .text-2xl').hasText(period);
});
test('clicking the clock opens the settings dialog', async function (assert) {
const { modal } = registerServices(this.owner);
await render(<template><DefaultClock /></template>);
await click('[aria-label="Edit clock settings"]');
assert.strictEqual(modal.opened.component, ClockForm);
assert.strictEqual(modal.opened.size, 'sm');
});
});