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.
47 lines
1.7 KiB
JavaScript
47 lines
1.7 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { setupApplicationTest } from 'dashtab/tests/helpers';
|
|
import { visit, fillIn, click } from '@ember/test-helpers';
|
|
|
|
module('Acceptance | name onboarding', function (hooks) {
|
|
setupApplicationTest(hooks);
|
|
|
|
hooks.beforeEach(async function () {
|
|
const storage = this.owner.lookup('service:storage');
|
|
await storage.remove('preferences', 'name');
|
|
// Keep the dashboard widgets from picking up leftover integrations (and
|
|
// reaching the network) while these tests run.
|
|
await storage.clear('integrations');
|
|
});
|
|
|
|
test('redirects to the welcome flow when no name is stored', async function (assert) {
|
|
await visit('/');
|
|
|
|
const router = this.owner.lookup('service:router');
|
|
assert.strictEqual(router.currentRouteName, 'welcome');
|
|
assert.dom('[data-test-welcome]').exists();
|
|
});
|
|
|
|
test('shows the dashboard when a name is stored', async function (assert) {
|
|
const storage = this.owner.lookup('service:storage');
|
|
await storage.set('preferences', 'name', 'Ada');
|
|
|
|
await visit('/');
|
|
|
|
const router = this.owner.lookup('service:router');
|
|
assert.strictEqual(router.currentRouteName, 'index');
|
|
assert.dom('[data-test-welcome]').doesNotExist();
|
|
assert.dom('.name').hasText('Ada');
|
|
});
|
|
|
|
test('submitting the welcome form stores the name and enters the dashboard', async function (assert) {
|
|
await visit('/');
|
|
await fillIn('[data-test-welcome-input]', 'Ada');
|
|
await click('[data-test-welcome-submit]');
|
|
|
|
const storage = this.owner.lookup('service:storage');
|
|
const router = this.owner.lookup('service:router');
|
|
assert.strictEqual(await storage.get('preferences', 'name'), 'Ada');
|
|
assert.strictEqual(router.currentRouteName, 'index');
|
|
});
|
|
});
|