Introduce a locale/12-hour/24-hour preference on the clock service and a shared Intl-based formatter used across the dashboard.
46 lines
1.4 KiB
JavaScript
46 lines
1.4 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupTest } from 'dashtab/tests/helpers';
|
|
import { DEFAULT_TIME_FORMAT } from 'dashtab/utils/time-format';
|
|
|
|
module('Unit | Service | clock', function (hooks) {
|
|
setupTest(hooks);
|
|
|
|
hooks.beforeEach(async function () {
|
|
const storage = this.owner.lookup('service:storage');
|
|
await storage.remove('preferences', 'time-format');
|
|
});
|
|
|
|
test('it exists', function (assert) {
|
|
const service = this.owner.lookup('service:clock');
|
|
assert.ok(service);
|
|
});
|
|
|
|
test('defaults to the locale format', async function (assert) {
|
|
const service = this.owner.lookup('service:clock');
|
|
await service.ready;
|
|
|
|
assert.strictEqual(service.timeFormat, DEFAULT_TIME_FORMAT);
|
|
});
|
|
|
|
test('loads a stored format', async function (assert) {
|
|
const storage = this.owner.lookup('service:storage');
|
|
await storage.set('preferences', 'time-format', '24h');
|
|
|
|
const service = this.owner.lookup('service:clock');
|
|
await service.ready;
|
|
|
|
assert.strictEqual(service.timeFormat, '24h');
|
|
});
|
|
|
|
test('setTimeFormat updates the state and persists it', async function (assert) {
|
|
const service = this.owner.lookup('service:clock');
|
|
await service.ready;
|
|
|
|
await service.setTimeFormat('12h');
|
|
|
|
const storage = this.owner.lookup('service:storage');
|
|
assert.strictEqual(service.timeFormat, '12h');
|
|
assert.strictEqual(await storage.get('preferences', 'time-format'), '12h');
|
|
});
|
|
});
|