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

57 lines
1.8 KiB
Plaintext

import { module, test } from 'qunit';
import { setupRenderingTest } from 'dashtab/tests/helpers';
import { render, fillIn, click } from '@ember/test-helpers';
import Welcome from 'dashtab/components/welcome';
import FakeUser from 'dashtab/tests/helpers/fake-user';
function registerServices(owner) {
const router = {
replacedWith: null,
replaceWith(route) {
this.replacedWith = route;
},
};
const user = new FakeUser();
owner.register('service:router', router, { instantiate: false });
owner.register('service:user', user, { instantiate: false });
return { router, user };
}
module('Integration | Component | welcome', function (hooks) {
setupRenderingTest(hooks);
test('it renders the name prompt and focuses the field', async function (assert) {
registerServices(this.owner);
await render(<template><Welcome /></template>);
assert.dom('[data-test-welcome]').exists();
assert.dom('h1').hasText("Hello! What's your name?");
assert.dom('[data-test-welcome-input]').isFocused();
});
test('submitting stores the trimmed name and enters the dashboard', async function (assert) {
const { router, user } = registerServices(this.owner);
await render(<template><Welcome /></template>);
await fillIn('[data-test-welcome-input]', ' Ada ');
await click('[data-test-welcome-submit]');
assert.deepEqual(user.calls, ['Ada']);
assert.strictEqual(user.name, 'Ada');
assert.strictEqual(router.replacedWith, 'index');
});
test('does not submit an empty name', async function (assert) {
const { router, user } = registerServices(this.owner);
await render(<template><Welcome /></template>);
await click('[data-test-welcome-submit]');
assert.deepEqual(user.calls, []);
assert.strictEqual(router.replacedWith, null);
});
});