Files
raucao 13e02168c9 Add name onboarding and inline name editing
Ask for the user's name on first launch through a /welcome route, store it in the preferences namespace via a user service, and redirect between welcome and the dashboard based on whether a name exists. Replace the hardcoded greeting name and make it editable in place, with save/cancel handling and a first-run prompt matching the dashboard style.
2026-11-07 13:14:23 +04:00

61 lines
1.8 KiB
JavaScript

import { module, test } from 'qunit';
import { setupTest } from 'dashtab/tests/helpers';
module('Unit | Service | user', function (hooks) {
setupTest(hooks);
hooks.beforeEach(async function () {
const storage = this.owner.lookup('service:storage');
await storage.remove('preferences', 'name');
});
test('it exists', function (assert) {
const service = this.owner.lookup('service:user');
assert.ok(service);
});
test('defaults to no name', async function (assert) {
const service = this.owner.lookup('service:user');
await service.ready;
assert.strictEqual(service.name, null);
assert.false(service.hasName);
});
test('loads a stored name, trimmed', async function (assert) {
const storage = this.owner.lookup('service:storage');
await storage.set('preferences', 'name', ' Ada ');
const service = this.owner.lookup('service:user');
await service.ready;
assert.strictEqual(service.name, 'Ada');
assert.true(service.hasName);
});
test('setName updates the state and persists it', async function (assert) {
const service = this.owner.lookup('service:user');
await service.ready;
await service.setName(' Grace ');
const storage = this.owner.lookup('service:storage');
assert.strictEqual(service.name, 'Grace');
assert.true(service.hasName);
assert.strictEqual(await storage.get('preferences', 'name'), 'Grace');
});
test('setName with only whitespace clears the name', async function (assert) {
const service = this.owner.lookup('service:user');
await service.ready;
await service.setName('Ada');
await service.setName(' ');
const storage = this.owner.lookup('service:storage');
assert.strictEqual(service.name, null);
assert.false(service.hasName);
assert.strictEqual(await storage.get('preferences', 'name'), null);
});
});