Skip to content

Modular logistics and supply chain operating system (LSOS)

test(console): green the unit suite — fix service stubbing, add controller/route tests

Ronald A. Richardson2a02cea8fc1e
diff --git a/console/app/controllers/auth/verification.js b/console/app/controllers/auth/verification.js
index 2b19596b..89a0671c 100644
--- a/console/app/controllers/auth/verification.js
+++ b/console/app/controllers/auth/verification.js
@@ -2,7 +2,7 @@ import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
-import { later } from '@ember/runloop';
+import { later, cancel } from '@ember/runloop';
import { task } from 'ember-concurrency';
export default class AuthVerificationController extends Controller {
@@ -27,7 +27,7 @@ export default class AuthVerificationController extends Controller {
constructor() {
super(...arguments);
- later(
+ this.stillWaitingTimer = later(
this,
() => {
this.stillWaiting = true;
@@ -36,6 +36,16 @@ export default class AuthVerificationController extends Controller {
);
}
+ willDestroy() {
+ super.willDestroy(...arguments);
+
+ // Cancel the pending "still waiting" timer so it never fires on a torn-down
+ // controller (e.g. navigating away before the timeout elapses).
+ if (this.stillWaitingTimer) {
+ cancel(this.stillWaitingTimer);
+ }
+ }
+
@action onDidntReceiveCode() {
this.stillWaiting = true;
}
diff --git a/console/tests/unit/controllers/auth/verification-test.js b/console/tests/unit/controllers/auth/verification-test.js
index b4dc9c1c..7fe365ca 100644
--- a/console/tests/unit/controllers/auth/verification-test.js
+++ b/console/tests/unit/controllers/auth/verification-test.js
@@ -1,12 +1,101 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
module('Unit | Controller | auth/verification', function (hooks) {
setupTest(hooks);
- // TODO: Replace this with your real tests.
- test('it exists', function (assert) {
- let controller = this.owner.lookup('controller:auth/verification');
- assert.ok(controller);
+ test('validateInput toggles isReadyToSubmit on input length', function (assert) {
+ const controller = this.owner.lookup('controller:auth/verification');
+
+ controller.validateInput({ target: { value: '123456' } });
+ assert.true(controller.isReadyToSubmit);
+
+ controller.validateInput({ target: { value: '123' } });
+ assert.false(controller.isReadyToSubmit);
+ });
+
+ test('validateInitInput toggles isReadyToSubmit on element value length', function (assert) {
+ const controller = this.owner.lookup('controller:auth/verification');
+
+ controller.validateInitInput({ value: 'abcdef' });
+ assert.true(controller.isReadyToSubmit);
+
+ controller.validateInitInput({ value: 'ab' });
+ assert.false(controller.isReadyToSubmit);
+ });
+
+ test('onDidntReceiveCode flags the controller as still waiting', function (assert) {
+ const controller = this.owner.lookup('controller:auth/verification');
+ assert.false(controller.stillWaiting);
+
+ controller.onDidntReceiveCode();
+
+ assert.true(controller.stillWaiting);
+ });
+
+ test('verifyCode authenticates and transitions to console when a token is returned', async function (assert) {
+ class FetchStub extends Service {
+ post() {
+ return Promise.resolve({ status: 'ok', token: 'auth-token' });
+ }
+ }
+ class SessionStub extends Service {
+ manuallyAuthenticate(token) {
+ this.token = token;
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ info() {}
+ serverError() {}
+ }
+ class IntlStub extends Service {
+ t() {
+ return 'Fleetbase';
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:session', SessionStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ this.owner.register('service:intl', IntlStub);
+
+ const controller = this.owner.lookup('controller:auth/verification');
+ let transitioned;
+ controller.router.transitionTo = (route) => {
+ transitioned = route;
+ return route;
+ };
+
+ await controller.verifyCode.perform();
+
+ assert.strictEqual(this.owner.lookup('service:session').token, 'auth-token');
+ assert.strictEqual(transitioned, 'console');
+ });
+
+ test('verifyCode transitions to login when no token is returned', async function (assert) {
+ class FetchStub extends Service {
+ post() {
+ return Promise.resolve({ status: 'ok' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ info() {}
+ serverError() {}
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const controller = this.owner.lookup('controller:auth/verification');
+ let transitioned;
+ controller.router.transitionTo = (route) => {
+ transitioned = route;
+ return route;
+ };
+
+ await controller.verifyCode.perform();
+
+ assert.strictEqual(transitioned, 'auth.login');
});
});
diff --git a/console/tests/unit/controllers/console/account/auth-test.js b/console/tests/unit/controllers/console/account/auth-test.js
index 3c907279..20c7aa87 100644
--- a/console/tests/unit/controllers/console/account/auth-test.js
+++ b/console/tests/unit/controllers/console/account/auth-test.js
@@ -1,12 +1,150 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
+
+// The controller's constructor immediately performs loadSystemTwoFaConfig and
+// loadUserTwoFaSettings, so service:fetch must be registered before any lookup.
+function stubServices(owner, { get = () => Promise.resolve(null), post = () => Promise.resolve({}) } = {}) {
+ const posts = [];
+ const notified = { success: [], errors: [] };
+
+ class FetchStub extends Service {
+ get(path) {
+ return get(path);
+ }
+ post(path, payload) {
+ posts.push({ path, payload });
+ return post(path, payload);
+ }
+ }
+ class NotificationsStub extends Service {
+ success(message) {
+ notified.success.push(message);
+ }
+ serverError(error, message) {
+ notified.errors.push(message ?? error);
+ }
+ }
+
+ owner.register('service:fetch', FetchStub);
+ owner.register('service:notifications', NotificationsStub);
+
+ return { posts, notified };
+}
module('Unit | Controller | console/account/auth', function (hooks) {
setupTest(hooks);
- // TODO: Replace this with your real tests.
- test('it exists', function (assert) {
- let controller = this.owner.lookup('controller:console/account/auth');
- assert.ok(controller);
+ test('onTwoFaToggled and onTwoFaMethodSelected merge into the 2FA settings', function (assert) {
+ stubServices(this.owner);
+ const controller = this.owner.lookup('controller:console/account/auth');
+
+ controller.onTwoFaToggled(true);
+ assert.deepEqual(controller.twoFaSettings, { enabled: true });
+
+ controller.onTwoFaMethodSelected('sms');
+ assert.deepEqual(controller.twoFaSettings, { enabled: true, method: 'sms' }, 'existing settings are preserved');
+ });
+
+ test('loadSystemTwoFaConfig and loadUserTwoFaSettings populate tracked state', async function (assert) {
+ stubServices(this.owner, {
+ get: (path) => Promise.resolve(path === 'two-fa/config' ? { enabled: true, method: 'email' } : { enabled: false }),
+ });
+
+ const controller = this.owner.lookup('controller:console/account/auth');
+
+ await controller.loadSystemTwoFaConfig.perform();
+ assert.true(controller.isSystemTwoFaEnabled);
+ assert.deepEqual(controller.twoFaConfig, { enabled: true, method: 'email' });
+
+ await controller.loadUserTwoFaSettings.perform();
+ assert.deepEqual(controller.twoFaSettings, { enabled: false });
+ });
+
+ test('changeEmail posts the new address and clears the form on success', async function (assert) {
+ const { posts, notified } = stubServices(this.owner);
+ const controller = this.owner.lookup('controller:console/account/auth');
+
+ controller.newEmail = '[email protected]';
+ controller.currentPassword = 'hunter2';
+
+ await controller.changeEmail.perform();
+
+ assert.deepEqual(posts.at(-1), { path: 'users/change-email', payload: { email: '[email protected]', password: 'hunter2' } });
+ assert.strictEqual(notified.success.length, 1, 'success is reported');
+ assert.strictEqual(controller.newEmail, undefined, 'email field cleared');
+ assert.strictEqual(controller.currentPassword, undefined, 'password field cleared');
+ });
+
+ test('changeEmail reports a server error and keeps the form values', async function (assert) {
+ const { notified } = stubServices(this.owner, { post: () => Promise.reject(new Error('nope')) });
+ const controller = this.owner.lookup('controller:console/account/auth');
+
+ controller.newEmail = '[email protected]';
+
+ await controller.changeEmail.perform();
+
+ assert.deepEqual(notified.errors, ['Failed to request email change.']);
+ assert.strictEqual(controller.newEmail, '[email protected]', 'form is not cleared on failure');
+ });
+
+ test('changePassword aborts and clears the fields when the current password is not validated', async function (assert) {
+ const { posts } = stubServices(this.owner);
+
+ class ModalsManagerStub extends Service {
+ show(_name, options) {
+ options.onValidated(false);
+ return Promise.resolve();
+ }
+ }
+ this.owner.register('service:modals-manager', ModalsManagerStub);
+
+ const controller = this.owner.lookup('controller:console/account/auth');
+ controller.newPassword = 'a-new-password';
+ controller.newConfirmPassword = 'a-new-password';
+
+ await controller.changePassword.perform();
+
+ assert.notOk(
+ posts.some((p) => p.path === 'users/change-password'),
+ 'the password is never submitted'
+ );
+ assert.strictEqual(controller.newPassword, undefined);
+ assert.strictEqual(controller.newConfirmPassword, undefined);
+ });
+
+ test('changePassword submits once the current password is validated', async function (assert) {
+ const { posts, notified } = stubServices(this.owner);
+
+ class ModalsManagerStub extends Service {
+ show(_name, options) {
+ options.onValidated(true);
+ return Promise.resolve();
+ }
+ }
+ this.owner.register('service:modals-manager', ModalsManagerStub);
+
+ const controller = this.owner.lookup('controller:console/account/auth');
+ controller.newPassword = 'a-new-password';
+ controller.newConfirmPassword = 'a-new-password';
+
+ await controller.changePassword.perform();
+
+ assert.deepEqual(posts.at(-1), {
+ path: 'users/change-password',
+ payload: { password: 'a-new-password', password_confirmation: 'a-new-password' },
+ });
+ assert.strictEqual(notified.success.length, 1);
+ assert.strictEqual(controller.newPassword, undefined, 'fields are cleared after submitting');
+ });
+
+ test('saveTwoFactorAuthSettings posts the current 2FA settings', async function (assert) {
+ const { posts } = stubServices(this.owner);
+ const controller = this.owner.lookup('controller:console/account/auth');
+
+ controller.onTwoFaToggled(true);
+ await controller.saveUserTwoFaSettings.perform(controller.twoFaSettings);
+
+ assert.deepEqual(posts.at(-1), { path: 'users/two-fa', payload: { twoFaSettings: { enabled: true } } });
});
});
diff --git a/console/tests/unit/controllers/console/account/organizations-test.js b/console/tests/unit/controllers/console/account/organizations-test.js
index cadeeed2..208b8943 100644
--- a/console/tests/unit/controllers/console/account/organizations-test.js
+++ b/console/tests/unit/controllers/console/account/organizations-test.js
@@ -1,12 +1,313 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
+import { cancel } from '@ember/runloop';
+
+// Captures whatever the controller hands to the modals manager so the modal's
+// `confirm` callback can be driven directly.
+class ModalsManagerStub extends Service {
+ lastOptions = null;
+ shown = [];
+
+ show(name, options) {
+ this.shown.push(name);
+ this.lastOptions = options;
+ return Promise.resolve();
+ }
+
+ confirm(options) {
+ this.shown.push('confirm');
+ this.lastOptions = options;
+ return Promise.resolve();
+ }
+
+ setOption(key, value) {
+ this.lastOptions[key] = value;
+ }
+
+ getOption(key) {
+ return this.lastOptions[key];
+ }
+}
+
+class NotificationsStub extends Service {
+ warnings = [];
+ successes = [];
+ errors = [];
+ warning(m) {
+ this.warnings.push(m);
+ }
+ success(m) {
+ this.successes.push(m);
+ }
+ serverError(e) {
+ this.errors.push(e);
+ }
+}
+
+class IntlStub extends Service {
+ t(key) {
+ return key;
+ }
+}
+
+// A stand-in for the modal instance passed to `confirm`. Backed by the same options
+// object the controller passed to the modals manager, since some confirm handlers read
+// their values back out via modal.getOption().
+function fakeModal(options = {}) {
+ return {
+ loading: false,
+ startLoading() {
+ this.loading = true;
+ },
+ stopLoading() {
+ this.loading = false;
+ },
+ getOption(key) {
+ return options[key];
+ },
+ setOption(key, value) {
+ options[key] = value;
+ },
+ };
+}
+
+function organization(attrs = {}) {
+ return {
+ name: 'Acme',
+ uuid: 'org_1',
+ owner_uuid: 'user_1',
+ users_count: 1,
+ calls: [],
+ loadUsers(params) {
+ this.calls.push(['loadUsers', params]);
+ },
+ transferOwnership(newOwnerId, params) {
+ this.calls.push(['transferOwnership', newOwnerId, params]);
+ return Promise.resolve();
+ },
+ destroyRecord() {
+ this.calls.push(['destroyRecord']);
+ return Promise.resolve();
+ },
+ leave() {
+ this.calls.push(['leave']);
+ return Promise.resolve();
+ },
+ save() {
+ this.calls.push(['save']);
+ return Promise.resolve();
+ },
+ ...attrs,
+ };
+}
module('Unit | Controller | console/account/organizations', function (hooks) {
setupTest(hooks);
- // TODO: Replace this with your real tests.
- test('it exists', function (assert) {
- let controller = this.owner.lookup('controller:console/account/organizations');
- assert.ok(controller);
+ hooks.beforeEach(function () {
+ this.owner.register('service:modals-manager', ModalsManagerStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ this.owner.register('service:intl', IntlStub);
+
+ this.controller = this.owner.lookup('controller:console/account/organizations');
+ this.modals = this.owner.lookup('service:modals-manager');
+ this.notifications = this.owner.lookup('service:notifications');
+
+ // router is the built-in RouterService, which owner.register cannot swap.
+ this.refreshed = 0;
+ this.controller.router.refresh = () => this.refreshed++;
+ });
+
+ test('leaveOrganization refuses to leave your only organization', async function (assert) {
+ this.controller.model = [organization()];
+
+ await this.controller.leaveOrganization(organization());
+
+ assert.deepEqual(this.notifications.warnings, ['Unable to leave your only organization.']);
+ assert.strictEqual(this.modals.lastOptions, null, 'no modal is opened');
+ });
+
+ test('leaveOrganization offers ownership transfer when the owner has other members', async function (assert) {
+ this.controller.currentUser.userSnapshot = { id: 'user_1' };
+ const org = organization({ users_count: 3 });
+ this.controller.model = [org, organization()];
+
+ await this.controller.leaveOrganization(org);
+
+ const options = this.modals.lastOptions;
+ assert.strictEqual(options.title, 'Transfer Ownership and Leave');
+ assert.true(options.isOwner);
+ assert.true(options.hasOtherMembers);
+ assert.false(options.willBeDeleted);
+ assert.true(options.acceptButtonDisabled, 'confirming is blocked until a new owner is chosen');
+ assert.deepEqual(org.calls, [['loadUsers', { exclude: ['user_1'] }]], 'other members are loaded for selection');
+
+ options.selectNewOwner('user_2');
+ assert.strictEqual(options.newOwnerId, 'user_2');
+ assert.false(options.acceptButtonDisabled, 'choosing an owner unblocks confirm');
+
+ await options.confirm(fakeModal());
+ assert.deepEqual(org.calls.at(-1), ['transferOwnership', 'user_2', { leave: true }]);
+ assert.strictEqual(this.refreshed, 1, 'the route is refreshed');
+ });
+
+ test('leaveOrganization deletes the organization when the sole owner leaves', async function (assert) {
+ this.controller.currentUser.userSnapshot = { id: 'user_1' };
+ const org = organization({ users_count: 1 });
+ this.controller.model = [org, organization()];
+
+ await this.controller.leaveOrganization(org);
+
+ const options = this.modals.lastOptions;
+ assert.strictEqual(options.title, 'Delete Organization');
+ assert.true(options.willBeDeleted);
+
+ await options.confirm(fakeModal());
+ assert.deepEqual(org.calls.at(-1), ['destroyRecord']);
+ assert.strictEqual(this.refreshed, 1);
+ });
+
+ test('leaveOrganization simply leaves when the user is not the owner', async function (assert) {
+ this.controller.currentUser.userSnapshot = { id: 'user_2' };
+ const org = organization({ owner_uuid: 'user_1', users_count: 4 });
+ this.controller.model = [org, organization()];
+
+ await this.controller.leaveOrganization(org);
+
+ const options = this.modals.lastOptions;
+ assert.strictEqual(options.title, 'Leave Organization');
+ assert.false(options.isOwner);
+ assert.false(options.acceptButtonDisabled);
+
+ await options.confirm(fakeModal());
+ assert.deepEqual(org.calls.at(-1), ['leave']);
+ });
+
+ test('deleteOrganization refuses for the only organization and for non-owners', async function (assert) {
+ this.controller.currentUser.userSnapshot = { id: 'user_2' };
+
+ this.controller.model = [organization()];
+ this.controller.deleteOrganization(organization());
+ assert.deepEqual(this.notifications.warnings, ['Unable to delete your only organization.']);
+
+ this.controller.model = [organization(), organization()];
+ this.controller.deleteOrganization(organization({ owner_uuid: 'user_1' }));
+ assert.deepEqual(this.notifications.warnings.at(-1), 'You do not have rights to delete this organization.');
+ });
+
+ test('deleteOrganization destroys the record through crud.delete for the owner', async function (assert) {
+ this.controller.currentUser.userSnapshot = { id: 'user_1' };
+ const org = organization();
+ this.controller.model = [org, organization()];
+
+ // crud.delete is an @action, which is exposed as a getter — shadow it with an
+ // own value property instead of assigning.
+ let deleted;
+ Object.defineProperty(this.controller.crud, 'delete', {
+ configurable: true,
+ value: (record, options) => {
+ deleted = { record, options };
+ },
+ });
+
+ this.controller.deleteOrganization(org);
+
+ assert.strictEqual(deleted.record, org);
+ assert.strictEqual(deleted.options.acceptButtonText, 'Delete Organization');
+
+ await deleted.options.confirm(fakeModal());
+ assert.deepEqual(org.calls.at(-1), ['destroyRecord']);
+ assert.strictEqual(this.refreshed, 1);
+ });
+
+ test('editOrganization saves the record and refreshes', async function (assert) {
+ const org = organization();
+ this.controller.currentUser.userSnapshot = { id: 'user_1' };
+
+ this.controller.editOrganization(org);
+
+ const options = this.modals.lastOptions;
+ assert.strictEqual(options.title, 'Edit Organization');
+ assert.true(options.isOwner);
+
+ await options.confirm(fakeModal());
+ assert.deepEqual(org.calls.at(-1), ['save']);
+ assert.strictEqual(this.refreshed, 1);
+ });
+
+ test('createOrganization posts the new organization and refreshes', async function (assert) {
+ const posted = [];
+ class FetchStub extends Service {
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({});
+ }
+ flushRequestCache(path) {
+ posted.push({ flushed: path });
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const controller = this.owner.lookup('controller:console/account/organizations');
+ controller.router.refresh = () => this.refreshed++;
+
+ controller.createOrganization();
+
+ const options = this.modals.lastOptions;
+ options.organization.name = 'New Co';
+
+ // this confirm handler reads the edited organization back via modal.getOption()
+ await options.confirm(fakeModal(options));
+
+ assert.strictEqual(posted[0].path, 'auth/create-organization');
+ assert.strictEqual(posted[0].payload.name, 'New Co');
+ assert.deepEqual(posted[1], { flushed: 'auth/organizations' });
+ assert.strictEqual(this.refreshed, 1);
+ });
+
+ test('switchOrganization reports a server error without reloading', async function (assert) {
+ class FetchStub extends Service {
+ post() {
+ return Promise.reject(new Error('nope'));
+ }
+ flushRequestCache() {}
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const controller = this.owner.lookup('controller:console/account/organizations');
+ controller.switchOrganization(organization());
+
+ const modal = fakeModal();
+ await this.modals.lastOptions.confirm(modal);
+
+ assert.strictEqual(this.notifications.errors.length, 1, 'the failure is surfaced');
+ assert.false(modal.loading, 'the modal stops loading');
+ });
+
+ test('switchOrganization posts the switch and schedules a reload on success', async function (assert) {
+ const posted = [];
+ class FetchStub extends Service {
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({});
+ }
+ flushRequestCache(path) {
+ posted.push({ flushed: path });
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const controller = this.owner.lookup('controller:console/account/organizations');
+ controller.switchOrganization(organization());
+
+ // The success path returns the `later` timer that reloads the page — cancel it
+ // so the pending reload never fires against the test runner.
+ const timer = await this.modals.lastOptions.confirm(fakeModal());
+ cancel(timer);
+
+ assert.deepEqual(posted[0], { path: 'auth/switch-organization', payload: { next: 'org_1' } });
+ assert.deepEqual(posted[1], { flushed: 'auth/organizations' });
+ assert.strictEqual(this.notifications.successes.length, 1);
});
});
diff --git a/console/tests/unit/controllers/console/admin-test.js b/console/tests/unit/controllers/console/admin-test.js
index 8b98c8e1..ab0124e7 100644
--- a/console/tests/unit/controllers/console/admin-test.js
+++ b/console/tests/unit/controllers/console/admin-test.js
@@ -1,58 +1,49 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
-import window from 'ember-window-mock';
-
-class MenuServiceStub {
- adminMenuItems = [
- {
- title: 'Registry Config',
- label: 'Registry Config',
- description: 'Configure the registry bridge.',
- icon: 'gear',
- slug: 'registry-config',
- view: null,
- tags: ['extensions'],
- },
- ];
-
- adminMenuPanels = [
- {
- title: 'Fleet-Ops Config',
- slug: 'fleet-ops',
- icon: 'truck',
- items: [
- {
- title: 'Navigator App',
- icon: 'location-arrow',
- slug: 'fleet-ops',
- view: 'navigator-app',
- description: 'Configure the navigator app.',
- },
- {
- title: 'Map',
- icon: 'map',
- slug: 'fleet-ops',
- view: 'map',
- },
- ],
- },
- ];
-}
-
-class UniverseStub {
- transitions = [];
-
- transitionMenuItem(route, menuItem) {
- this.transitions.push({ route, menuItem });
- }
-}
-
-class IntlStub {
+import Service from '@ember/service';
+
+const ADMIN_MENU_ITEMS = [
+ {
+ title: 'Registry Config',
+ label: 'Registry Config',
+ description: 'Configure the registry bridge.',
+ icon: 'gear',
+ slug: 'registry-config',
+ view: null,
+ tags: ['extensions'],
+ },
+];
+
+const ADMIN_MENU_PANELS = [
+ {
+ title: 'Fleet-Ops Config',
+ slug: 'fleet-ops',
+ icon: 'truck',
+ items: [
+ {
+ title: 'Navigator App',
+ icon: 'location-arrow',
+ slug: 'fleet-ops',
+ view: 'navigator-app',
+ description: 'Configure the navigator app.',
+ },
+ {
+ title: 'Map',
+ icon: 'map',
+ slug: 'fleet-ops',
+ view: 'map',
+ },
+ ],
+ },
+];
+
+class IntlStub extends Service {
translations = {
'console.admin.menu.overview': 'Overview',
'console.admin.menu.organizations': 'Organizations',
'console.admin.menu.branding': 'Branding',
'console.admin.menu.2fa-config': '2FA Config',
+ 'console.admin.menu.platform-api-token': 'Platform API Token',
'console.admin.schedule-monitor.schedule-monitor': 'Schedule Monitor',
'console.admin.menu.services': 'Services',
'console.admin.menu.mail': 'Mail',
@@ -71,9 +62,28 @@ module('Unit | Controller | console/admin', function (hooks) {
setupTest(hooks);
hooks.beforeEach(function () {
- this.owner.register('service:universe/menu-service', MenuServiceStub);
- this.owner.register('service:universe', UniverseStub);
+ // ember-intl's service overrides cleanly via owner.register.
this.owner.register('service:intl', IntlStub);
+
+ // The universe service (and its universe/menu-service alias) is a pre-resolved
+ // singleton that owner.register can't swap, and it boots real extension menus.
+ // adminMenuItems/adminMenuPanels are @computed getters and transitionMenuItem is an
+ // @action getter, so shadow each with an own value property on the injected instance.
+ const seedMenus = (service) => {
+ Object.defineProperty(service, 'adminMenuItems', { configurable: true, value: ADMIN_MENU_ITEMS });
+ Object.defineProperty(service, 'adminMenuPanels', { configurable: true, value: ADMIN_MENU_PANELS });
+ };
+ seedMenus(this.owner.lookup('service:universe/menu-service'));
+
+ const universe = this.owner.lookup('service:universe');
+ seedMenus(universe);
+ universe.transitions = [];
+ Object.defineProperty(universe, 'transitionMenuItem', {
+ configurable: true,
+ value: (route, menuItem) => {
+ universe.transitions.push({ route, menuItem });
+ },
+ });
});
test('it exists', function (assert) {
@@ -86,25 +96,32 @@ module('Unit | Controller | console/admin', function (hooks) {
const items = controller.navigationItems;
assert.deepEqual(
- items.slice(0, 5).map((item) => item.label),
- ['Overview', 'Organizations', 'Branding', '2FA Config', 'Schedule Monitor'],
+ items.slice(0, 6).map((item) => item.label),
+ ['Overview', 'Organizations', 'Branding', '2FA Config', 'Platform API Token', 'Schedule Monitor'],
'core admin items retain their current order'
);
assert.deepEqual(
- items.slice(0, 5).map((item) => item.route),
- ['console.admin.index', 'console.admin.organizations', 'console.admin.branding', 'console.admin.two-fa-settings', 'console.admin.schedule-monitor'],
+ items.slice(0, 6).map((item) => item.route),
+ [
+ 'console.admin.index',
+ 'console.admin.organizations',
+ 'console.admin.branding',
+ 'console.admin.two-fa-settings',
+ 'console.admin.platform-api-token',
+ 'console.admin.schedule-monitor',
+ ],
'core admin items retain their routes'
);
assert.deepEqual(
- items.slice(0, 5).map((item) => item.icon),
- ['rectangle-list', 'building', 'palette', 'shield-halved', 'calendar-check'],
+ items.slice(0, 6).map((item) => item.icon),
+ ['rectangle-list', 'building', 'palette', 'shield-halved', 'key', 'calendar-check'],
'core admin items retain their icons'
);
});
test('it converts loose registry admin menu items into root navigator items', function (assert) {
const controller = this.owner.lookup('controller:console/admin');
- const registryItem = controller.navigationItems[5];
+ const registryItem = controller.navigationItems[6];
assert.strictEqual(registryItem.label, 'Registry Config');
assert.strictEqual(registryItem.icon, 'gear');
@@ -118,7 +135,7 @@ module('Unit | Controller | console/admin', function (hooks) {
test('it converts registry admin panels into nested navigator branches', function (assert) {
const controller = this.owner.lookup('controller:console/admin');
- const panel = controller.navigationItems[6];
+ const panel = controller.navigationItems[7];
assert.strictEqual(panel.label, 'Fleet-Ops Config');
assert.strictEqual(panel.icon, 'truck');
@@ -132,7 +149,9 @@ module('Unit | Controller | console/admin', function (hooks) {
['location-arrow', 'map'],
'panel children preserve icons'
);
- assert.deepEqual(panel.children[0].keywords, ['fleet-ops', 'navigator-app', 'Navigator App', 'Navigator App', 'Configure the navigator app.']);
+ // keywords = [slug, view, section, title, label, description, ...tags].filter(Boolean);
+ // this fixture item has no section/label, so those drop out.
+ assert.deepEqual(panel.children[0].keywords, ['fleet-ops', 'navigator-app', 'Navigator App', 'Configure the navigator app.']);
assert.true(panel.children[0]._virtual, 'panel children keep virtual metadata');
assert.strictEqual(panel.children[0].slug, 'fleet-ops', 'panel child slug remains the panel slug for /admin/<panel>');
assert.strictEqual(panel.children[0].view, 'navigator-app', 'panel child view remains the child slug for ?view=<item>');
@@ -141,27 +160,37 @@ module('Unit | Controller | console/admin', function (hooks) {
test('it marks virtual registry items active from the current admin virtual URL', function (assert) {
const controller = this.owner.lookup('controller:console/admin');
- const rootRegistryItem = controller.navigationItems[5];
- const navigatorAppItem = controller.navigationItems[6].children[0];
- const mapItem = controller.navigationItems[6].children[1];
-
- window.location.href = '/admin/fleet-ops?view=navigator-app';
-
- assert.true(navigatorAppItem.activeWhen(), 'matching panel child is active for /admin/<panel>?view=<item>');
- assert.false(mapItem.activeWhen(), 'sibling panel child is not active for a different view');
- assert.false(rootRegistryItem.activeWhen(), 'loose registry item is not active for a panel child URL');
-
- window.location.href = '/admin/registry-config';
-
- assert.true(rootRegistryItem.activeWhen(), 'loose registry item is active for /admin/<slug>');
- assert.false(navigatorAppItem.activeWhen(), 'panel child is not active for loose registry URL');
+ const rootRegistryItem = controller.navigationItems[6];
+ const navigatorAppItem = controller.navigationItems[7].children[0];
+ const mapItem = controller.navigationItems[7].children[1];
+
+ // activeWhen delegates to isMenuItemActive, which reads window.location.pathname and
+ // (via getUrlParam) window.location.search off the real global window. replaceState
+ // rewrites both synchronously without navigating the test iframe.
+ const originalUrl = window.location.href;
+ const visit = (url) => window.history.replaceState(null, '', url);
+
+ try {
+ visit('/admin/fleet-ops?view=navigator-app');
+
+ assert.true(navigatorAppItem.activeWhen(), 'matching panel child is active for /admin/<panel>?view=<item>');
+ assert.false(mapItem.activeWhen(), 'sibling panel child is not active for a different view');
+ assert.false(rootRegistryItem.activeWhen(), 'loose registry item is not active for a panel child URL');
+
+ visit('/admin/registry-config');
+
+ assert.true(rootRegistryItem.activeWhen(), 'loose registry item is active for /admin/<slug>');
+ assert.false(navigatorAppItem.activeWhen(), 'panel child is not active for loose registry URL');
+ } finally {
+ window.history.replaceState(null, '', originalUrl);
+ }
});
test('it transitions registry items through the admin virtual route', function (assert) {
const controller = this.owner.lookup('controller:console/admin');
const universe = this.owner.lookup('service:universe');
- const rootRegistryItem = controller.navigationItems[5];
- const panelRegistryItem = controller.navigationItems[6].children[0];
+ const rootRegistryItem = controller.navigationItems[6];
+ const panelRegistryItem = controller.navigationItems[7].children[0];
rootRegistryItem.onClick();
panelRegistryItem.onClick();
@@ -180,7 +209,7 @@ module('Unit | Controller | console/admin', function (hooks) {
test('it adds system config as a nested navigator branch', function (assert) {
const controller = this.owner.lookup('controller:console/admin');
- const systemConfig = controller.navigationItems[7];
+ const systemConfig = controller.navigationItems[8];
assert.strictEqual(systemConfig.label, 'System Config');
assert.deepEqual(
diff --git a/console/tests/unit/controllers/console/admin/organizations-test.js b/console/tests/unit/controllers/console/admin/organizations-test.js
deleted file mode 100644
index 5d4b9a18..00000000
--- a/console/tests/unit/controllers/console/admin/organizations-test.js
+++ /dev/null
@@ -1,12 +0,0 @@
-import { module, test } from 'qunit';
-import { setupTest } from '@fleetbase/console/tests/helpers';
-
-module('Unit | Controller | console/admin/organizations', function (hooks) {
- setupTest(hooks);
-
- // TODO: Replace this with your real tests.
- test('it exists', function (assert) {
- let controller = this.owner.lookup('controller:console/admin/organizations');
- assert.ok(controller);
- });
-});
diff --git a/console/tests/unit/controllers/onboard/verify-email-test.js b/console/tests/unit/controllers/onboard/verify-email-test.js
index f5729c5d..39cc44bf 100644
--- a/console/tests/unit/controllers/onboard/verify-email-test.js
+++ b/console/tests/unit/controllers/onboard/verify-email-test.js
@@ -1,12 +1,70 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
module('Unit | Controller | onboard/verify-email', function (hooks) {
setupTest(hooks);
- // TODO: Replace this with your real tests.
- test('it exists', function (assert) {
- let controller = this.owner.lookup('controller:onboard/verify-email');
- assert.ok(controller);
+ test('verifyCode authenticates and transitions to console when a token is returned', async function (assert) {
+ class FetchStub extends Service {
+ post(path, body) {
+ this.request = { path, body };
+ return Promise.resolve({ status: 'ok', token: 'auth-token' });
+ }
+ }
+ class SessionStub extends Service {
+ manuallyAuthenticate(token) {
+ this.token = token;
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ info() {}
+ serverError() {}
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:session', SessionStub);
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const controller = this.owner.lookup('controller:onboard/verify-email');
+ controller.hello = 'session-1';
+ controller.code = '654321';
+ let transitioned;
+ controller.router.transitionTo = (route) => {
+ transitioned = route;
+ return route;
+ };
+
+ await controller.verifyCode.perform();
+
+ assert.strictEqual(this.owner.lookup('service:fetch').request.path, 'onboard/verify-email');
+ assert.strictEqual(this.owner.lookup('service:session').token, 'auth-token');
+ assert.strictEqual(transitioned, 'console');
+ });
+
+ test('verifyCode transitions to login when no token is returned', async function (assert) {
+ class FetchStub extends Service {
+ post() {
+ return Promise.resolve({ status: 'ok' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ info() {}
+ serverError() {}
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const controller = this.owner.lookup('controller:onboard/verify-email');
+ let transitioned;
+ controller.router.transitionTo = (route) => {
+ transitioned = route;
+ return route;
+ };
+
+ await controller.verifyCode.perform();
+
+ assert.strictEqual(transitioned, 'auth.login');
});
});
diff --git a/console/tests/unit/routes/auth/confirm-email-change-test.js b/console/tests/unit/routes/auth/confirm-email-change-test.js
new file mode 100644
index 00000000..7fb1100d
--- /dev/null
+++ b/console/tests/unit/routes/auth/confirm-email-change-test.js
@@ -0,0 +1,60 @@
+import { module, test } from 'qunit';
+import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
+
+class NotificationsStub extends Service {
+ warnings = [];
+ warning(message) {
+ this.warnings.push(message);
+ }
+}
+
+module('Unit | Route | auth/confirm-email-change', function (hooks) {
+ setupTest(hooks);
+
+ test('model validates the verification code for an email change', async function (assert) {
+ class FetchStub extends Service {
+ get(path, params) {
+ return Promise.resolve({ path, params });
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const route = this.owner.lookup('route:auth/confirm-email-change');
+ const model = await route.model({ id: 'code_1' });
+
+ assert.strictEqual(model.path, 'auth/validate-verification');
+ assert.deepEqual(model.params, { id: 'code_1', for: 'email_change' });
+ });
+
+ test('setupController warns and redirects to login when the code is invalid', async function (assert) {
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const route = this.owner.lookup('route:auth/confirm-email-change');
+ let transitioned;
+ route.router.transitionTo = (name) => (transitioned = name);
+
+ const controller = {};
+ await route.setupController(controller, { is_valid: false });
+
+ assert.strictEqual(transitioned, 'auth.login');
+ assert.strictEqual(route.notifications.warnings.length, 1, 'the user is warned');
+ assert.notOk(controller.brand, 'no brand is loaded for an invalid code');
+ });
+
+ test('setupController loads the brand when the code is valid', async function (assert) {
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const route = this.owner.lookup('route:auth/confirm-email-change');
+ route.store.findRecord = (type, id) => Promise.resolve(`${type}:${id}`);
+
+ let transitioned;
+ route.router.transitionTo = (name) => (transitioned = name);
+
+ const controller = {};
+ await route.setupController(controller, { is_valid: true });
+
+ assert.strictEqual(controller.brand, 'brand:1');
+ assert.strictEqual(transitioned, undefined, 'no redirect for a valid code');
+ });
+});
diff --git a/console/tests/unit/routes/auth/login-test.js b/console/tests/unit/routes/auth/login-test.js
index 0a6c89f3..1e756e79 100644
--- a/console/tests/unit/routes/auth/login-test.js
+++ b/console/tests/unit/routes/auth/login-test.js
@@ -41,17 +41,20 @@ module('Unit | Route | auth/login', function (hooks) {
}
}
- class RouterStub extends Service {
- transitionTo(routeName) {
- transitionedTo = routeName;
- return 'onboard-transition';
- }
- }
-
this.owner.register('service:installation', InstallationStub);
- this.owner.register('service:router', RouterStub);
const route = this.owner.lookup('route:auth/login');
+
+ // Ember's built-in RouterService can't be replaced via owner.register in setupTest,
+ // so spy on transitionTo on the injected instance the route actually calls.
+ Object.defineProperty(route.router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => {
+ transitionedTo = routeName;
+ return 'onboard-transition';
+ },
+ });
+
const result = await route.beforeModel({});
assert.strictEqual(result, 'onboard-transition');
@@ -77,19 +80,22 @@ module('Unit | Route | auth/login', function (hooks) {
}
}
- class UniverseStub extends Service {
- virtualRouteRedirect(transition, routeName, virtualRouteName, options) {
- virtualRedirect = { transition, routeName, virtualRouteName, options };
- return 'login-transition';
- }
- }
-
this.owner.register('service:installation', InstallationStub);
this.owner.register('service:session', SessionStub);
- this.owner.register('service:universe', UniverseStub);
const transition = {};
const route = this.owner.lookup('route:auth/login');
+
+ // universe is a pre-resolved singleton that owner.register can't swap, and
+ // virtualRouteRedirect is an @action (a getter) — shadow it with a value property.
+ Object.defineProperty(route.universe, 'virtualRouteRedirect', {
+ configurable: true,
+ value: (transition, routeName, virtualRouteName, options) => {
+ virtualRedirect = { transition, routeName, virtualRouteName, options };
+ return 'login-transition';
+ },
+ });
+
const result = await route.beforeModel(transition);
assert.strictEqual(result, 'login-transition');
diff --git a/console/tests/unit/routes/auth/reset-password-test.js b/console/tests/unit/routes/auth/reset-password-test.js
index 2a4298fe..4f7a967b 100644
--- a/console/tests/unit/routes/auth/reset-password-test.js
+++ b/console/tests/unit/routes/auth/reset-password-test.js
@@ -1,11 +1,64 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
+
+class NotificationsStub extends Service {
+ warnings = [];
+ warning(message) {
+ this.warnings.push(message);
+ }
+}
module('Unit | Route | auth/reset-password', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:auth/reset-password');
- assert.ok(route);
+ test('model validates the verification code by id', async function (assert) {
+ class FetchStub extends Service {
+ get(path, params) {
+ return Promise.resolve({ path, params });
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const route = this.owner.lookup('route:auth/reset-password');
+ const model = await route.model({ id: 'code_1' });
+
+ assert.strictEqual(model.path, 'auth/validate-verification');
+ assert.deepEqual(model.params, { id: 'code_1' });
+ });
+
+ test('setupController warns and redirects when the verification code is invalid', async function (assert) {
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const route = this.owner.lookup('route:auth/reset-password');
+ let transitioned;
+ route.router.transitionTo = (name) => {
+ transitioned = name;
+ return name;
+ };
+
+ const controller = {};
+ await route.setupController(controller, { is_valid: false });
+
+ assert.strictEqual(transitioned, 'auth');
+ assert.strictEqual(route.notifications.warnings.length, 1, 'the user is warned');
+ assert.notOk(controller.brand, 'no brand is loaded for an invalid code');
+ });
+
+ test('setupController loads the brand when the verification code is valid', async function (assert) {
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const route = this.owner.lookup('route:auth/reset-password');
+ route.store.findRecord = (type, id) => Promise.resolve(`${type}:${id}`);
+
+ let transitioned;
+ route.router.transitionTo = (name) => (transitioned = name);
+
+ const controller = {};
+ await route.setupController(controller, { is_valid: true });
+
+ assert.strictEqual(controller.brand, 'brand:1');
+ assert.strictEqual(transitioned, undefined, 'no redirect for a valid code');
+ assert.strictEqual(route.notifications.warnings.length, 0);
});
});
diff --git a/console/tests/unit/routes/console/admin/organizations-test.js b/console/tests/unit/routes/console/admin/organizations-test.js
deleted file mode 100644
index c70e4306..00000000
--- a/console/tests/unit/routes/console/admin/organizations-test.js
+++ /dev/null
@@ -1,11 +0,0 @@
-import { module, test } from 'qunit';
-import { setupTest } from '@fleetbase/console/tests/helpers';
-
-module('Unit | Route | console/admin/organizations', function (hooks) {
- setupTest(hooks);
-
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/admin/organizations');
- assert.ok(route);
- });
-});
diff --git a/console/tests/unit/routes/console/home-test.js b/console/tests/unit/routes/console/home-test.js
index eca6d72e..1759fef7 100644
--- a/console/tests/unit/routes/console/home-test.js
+++ b/console/tests/unit/routes/console/home-test.js
@@ -4,8 +4,19 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | console/home', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/home');
- assert.ok(route);
+ test('activate disables the sidebar and deactivate re-enables it', function (assert) {
+ const route = this.owner.lookup('route:console/home');
+
+ // Patch the injected sidebar instance rather than registering a stub — app-wide
+ // singletons are already resolved by the time the route is looked up. enable/disable
+ // are @action, which are exposed as getters, so shadow them with value properties.
+ const calls = [];
+ Object.defineProperty(route.sidebar, 'disable', { configurable: true, value: () => calls.push('disable') });
+ Object.defineProperty(route.sidebar, 'enable', { configurable: true, value: () => calls.push('enable') });
+
+ route.activate();
+ route.deactivate();
+
+ assert.deepEqual(calls, ['disable', 'enable']);
});
});
diff --git a/console/tests/unit/routes/console/notifications-test.js b/console/tests/unit/routes/console/notifications-test.js
index cbba4e2e..abe7aaef 100644
--- a/console/tests/unit/routes/console/notifications-test.js
+++ b/console/tests/unit/routes/console/notifications-test.js
@@ -4,8 +4,39 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | console/notifications', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/notifications');
- assert.ok(route);
+ test('every listed query param refreshes the model', function (assert) {
+ const route = this.owner.lookup('route:console/notifications');
+
+ assert.deepEqual(Object.keys(route.queryParams), ['page', 'limit', 'sort', 'query', 'created_at']);
+ Object.entries(route.queryParams).forEach(([key, options]) => {
+ assert.true(options.refreshModel, `${key} refreshes the model`);
+ });
+ });
+
+ test('model queries notifications with the given params', function (assert) {
+ const route = this.owner.lookup('route:console/notifications');
+
+ let queried;
+ route.store.query = (type, params) => {
+ queried = { type, params };
+ return 'result';
+ };
+
+ assert.strictEqual(route.model({ page: 2 }), 'result');
+ assert.deepEqual(queried, { type: 'notification', params: { page: 2 } });
+ });
+
+ test('activate disables the sidebar and deactivate re-enables it', function (assert) {
+ const route = this.owner.lookup('route:console/notifications');
+
+ // enable/disable are @action, which are exposed as getters — shadow with values.
+ const calls = [];
+ Object.defineProperty(route.sidebar, 'disable', { configurable: true, value: () => calls.push('disable') });
+ Object.defineProperty(route.sidebar, 'enable', { configurable: true, value: () => calls.push('enable') });
+
+ route.activate();
+ route.deactivate();
+
+ assert.deepEqual(calls, ['disable', 'enable']);
});
});
diff --git a/console/tests/unit/routes/console/settings/index-test.js b/console/tests/unit/routes/console/settings/index-test.js
index 88e30c88..8b907f8d 100644
--- a/console/tests/unit/routes/console/settings/index-test.js
+++ b/console/tests/unit/routes/console/settings/index-test.js
@@ -4,8 +4,13 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | console/settings/index', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/settings/index');
- assert.ok(route);
+ test('model loads the current user company', async function (assert) {
+ const route = this.owner.lookup('route:console/settings/index');
+
+ // companyId is @alias('userSnapshot.company_uuid') — set the backing property.
+ route.currentUser.userSnapshot = { company_uuid: 'company_1' };
+ route.store.findRecord = (type, id) => Promise.resolve(`${type}:${id}`);
+
+ assert.strictEqual(await route.model(), 'company:company_1');
});
});
diff --git a/console/tests/unit/routes/console/settings/notifications-test.js b/console/tests/unit/routes/console/settings/notifications-test.js
index b3e8b5c6..cc25a060 100644
--- a/console/tests/unit/routes/console/settings/notifications-test.js
+++ b/console/tests/unit/routes/console/settings/notifications-test.js
@@ -1,11 +1,41 @@
import { module, test } from 'qunit';
import { setupTest } from '@fleetbase/console/tests/helpers';
+import Service from '@ember/service';
module('Unit | Route | console/settings/notifications', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/settings/notifications');
- assert.ok(route);
+ test('model fetches the notification registry and notifiables', async function (assert) {
+ class FetchStub extends Service {
+ get(path) {
+ return Promise.resolve(`${path}-result`);
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const route = this.owner.lookup('route:console/settings/notifications');
+ const model = await route.model();
+
+ assert.strictEqual(model.registry, 'notifications/registry-result');
+ assert.strictEqual(model.notifiables, 'notifications/notifiables-result');
+ });
+
+ test('setupController groups the registry by package and loads the company', async function (assert) {
+ const route = this.owner.lookup('route:console/settings/notifications');
+ route.currentUser.loadCompany = () => Promise.resolve('acme');
+
+ const controller = {};
+ const registry = [
+ { package: 'core', name: 'a' },
+ { package: 'core', name: 'b' },
+ { package: 'fleet-ops', name: 'c' },
+ ];
+
+ await route.setupController(controller, { registry, notifiables: ['user'] });
+
+ assert.deepEqual(Object.keys(controller.groupedNotifications), ['core', 'fleet-ops']);
+ assert.strictEqual(controller.groupedNotifications.core.length, 2);
+ assert.deepEqual(controller.notifiables, ['user']);
+ assert.strictEqual(controller.company, 'acme');
});
});
diff --git a/console/tests/unit/routes/console/virtual-test.js b/console/tests/unit/routes/console/virtual-test.js
index aedf12b8..40848985 100644
--- a/console/tests/unit/routes/console/virtual-test.js
+++ b/console/tests/unit/routes/console/virtual-test.js
@@ -4,8 +4,41 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | console/virtual', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:console/virtual');
- assert.ok(route);
+ test('the view query param refreshes the model', function (assert) {
+ const route = this.owner.lookup('route:console/virtual');
+
+ assert.true(route.queryParams.view.refreshModel);
+ });
+
+ test('model resolves the menu item for the slug and the transition view', function (assert) {
+ const route = this.owner.lookup('route:console/virtual');
+ const transition = { to: { queryParams: { view: 'settings' } } };
+
+ // universe and universe/menu-service are pre-resolved singletons that owner.register
+ // cannot swap, so patch the methods on the injected instances.
+ route.universe.getViewFromTransition = (t) => t.to.queryParams.view;
+
+ let lookedUp;
+ route.menuService.lookupMenuItem = (...args) => {
+ lookedUp = args;
+ return 'menu-item';
+ };
+
+ assert.strictEqual(route.model({ slug: 'reports' }, transition), 'menu-item');
+ assert.deepEqual(lookedUp, ['console', 'reports', 'settings']);
+ });
+
+ test('activate disables the sidebar and deactivate re-enables it', function (assert) {
+ const route = this.owner.lookup('route:console/virtual');
+
+ // enable/disable are @action, which are exposed as getters — shadow with values.
+ const calls = [];
+ Object.defineProperty(route.sidebar, 'disable', { configurable: true, value: () => calls.push('disable') });
+ Object.defineProperty(route.sidebar, 'enable', { configurable: true, value: () => calls.push('enable') });
+
+ route.activate();
+ route.deactivate();
+
+ assert.deepEqual(calls, ['disable', 'enable']);
});
});
diff --git a/console/tests/unit/routes/onboard/index-test.js b/console/tests/unit/routes/onboard/index-test.js
index 9f606d62..a1602388 100644
--- a/console/tests/unit/routes/onboard/index-test.js
+++ b/console/tests/unit/routes/onboard/index-test.js
@@ -4,8 +4,33 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | onboard/index', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:onboard/index');
- assert.ok(route);
+ test('none of the onboarding query params refresh the model', function (assert) {
+ const route = this.owner.lookup('route:onboard/index');
+
+ assert.deepEqual(Object.keys(route.queryParams), ['step', 'session', 'code']);
+ Object.entries(route.queryParams).forEach(([key, options]) => {
+ assert.false(options.refreshModel, `${key} does not refresh the model`);
+ });
+ });
+
+ test('beforeModel resumes the default onboarding flow', function (assert) {
+ const route = this.owner.lookup('route:onboard/index');
+
+ let started;
+ route.orchestrator.start = (flowId, opts) => {
+ started = { flowId, opts };
+ return Promise.resolve();
+ };
+
+ route.beforeModel();
+
+ assert.deepEqual(started, { flowId: null, opts: { resume: true } });
+ });
+
+ test('model loads the brand record', async function (assert) {
+ const route = this.owner.lookup('route:onboard/index');
+ route.store.findRecord = (type, id) => Promise.resolve(`${type}:${id}`);
+
+ assert.strictEqual(await route.model(), 'brand:1');
});
});
diff --git a/console/tests/unit/routes/virtual-test.js b/console/tests/unit/routes/virtual-test.js
index fbeab170..41a1df8f 100644
--- a/console/tests/unit/routes/virtual-test.js
+++ b/console/tests/unit/routes/virtual-test.js
@@ -4,8 +4,38 @@ import { setupTest } from '@fleetbase/console/tests/helpers';
module('Unit | Route | virtual', function (hooks) {
setupTest(hooks);
- test('it exists', function (assert) {
- let route = this.owner.lookup('route:virtual');
- assert.ok(route);
+ test('the view query param refreshes the model', function (assert) {
+ const route = this.owner.lookup('route:virtual');
+
+ assert.true(route.queryParams.view.refreshModel);
+ });
+
+ test('model resolves the auth:login menu item for the slug and transition view', function (assert) {
+ const route = this.owner.lookup('route:virtual');
+ const transition = { to: { queryParams: { view: 'signup' } } };
+
+ route.universe.getViewFromTransition = (t) => t.to.queryParams.view;
+
+ let lookedUp;
+ route.menuService.lookupMenuItem = (...args) => {
+ lookedUp = args;
+ return 'menu-item';
+ };
+
+ assert.strictEqual(route.model({ slug: 'welcome' }, transition), 'menu-item');
+ assert.deepEqual(lookedUp, ['auth:login', 'welcome', 'signup']);
+ });
+
+ test('beforeModel and afterModel fire their universe hooks', async function (assert) {
+ const route = this.owner.lookup('route:virtual');
+ const transition = { to: { queryParams: {} } };
+
+ const executed = [];
+ route.hookService.execute = (name) => executed.push(name);
+
+ await route.beforeModel(transition);
+ await route.afterModel({}, transition);
+
+ assert.deepEqual(executed, ['virtual:before-model', 'virtual:after-model']);
});
});
diff --git a/console/tests/unit/services/installation-test.js b/console/tests/unit/services/installation-test.js
index 448c46ad..9088218b 100644
--- a/console/tests/unit/services/installation-test.js
+++ b/console/tests/unit/services/installation-test.js
@@ -46,19 +46,21 @@ module('Unit | Service | installation', function (hooks) {
}
}
- class RouterStub extends Service {
- currentRouteName = 'auth.login';
+ this.owner.register('service:fetch', FetchStub);
+
+ const service = this.owner.lookup('service:installation');
- transitionTo(routeName) {
+ // Ember's built-in RouterService can't be replaced via owner.register in setupTest —
+ // patch the injected instance the service actually calls.
+ Object.defineProperty(service.router, 'currentRouteName', { configurable: true, value: 'auth.login' });
+ Object.defineProperty(service.router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => {
transitionedTo = routeName;
return 'install-transition';
- }
- }
-
- this.owner.register('service:fetch', FetchStub);
- this.owner.register('service:router', RouterStub);
+ },
+ });
- const service = this.owner.lookup('service:installation');
const result = await service.checkOnboarding();
assert.true(result.notConfigured);
@@ -98,17 +100,18 @@ module('Unit | Service | installation', function (hooks) {
}
}
- class RouterStub extends Service {
- transitionTo(routeName) {
- transitionedTo = routeName;
- return 'onboard-transition';
- }
- }
-
this.owner.register('service:fetch', FetchStub);
- this.owner.register('service:router', RouterStub);
const service = this.owner.lookup('service:installation');
+
+ Object.defineProperty(service.router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => {
+ transitionedTo = routeName;
+ return 'onboard-transition';
+ },
+ });
+
const result = await service.redirectIfConfiguredFromInstall();
assert.strictEqual(result, 'onboard-transition');
@@ -126,17 +129,18 @@ module('Unit | Service | installation', function (hooks) {
}
}
- class RouterStub extends Service {
- transitionTo(routeName) {
- transitionedTo = routeName;
- return 'login-transition';
- }
- }
-
this.owner.register('service:fetch', FetchStub);
- this.owner.register('service:router', RouterStub);
const service = this.owner.lookup('service:installation');
+
+ Object.defineProperty(service.router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => {
+ transitionedTo = routeName;
+ return 'login-transition';
+ },
+ });
+
const result = await service.redirectIfConfiguredFromInstall();
assert.strictEqual(result, 'login-transition');