Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
test(console): cover impersonation, mail panel, extension widgets and rejection guard
Ronald A. Richardson770e3f5bd80e
diff --git a/console/app/components/configure/services.js b/console/app/components/configure/services.jsindex 290f6c24..e1889ad3 100644--- a/console/app/components/configure/services.js+++ b/console/app/components/configure/services.js@@ -61,7 +61,7 @@ export default class ConfigureServicesComponent extends Component {if (config.sms) {this.sms = this.normalizeSmsConfig(config.sms);- this.smsSelectedProvider = this.sms.defaultProvider || 'twilio';+ this.smsSelectedProvider = this.sms.defaultProvider;this.syncSmsJsonText();}}@@ -170,7 +170,7 @@ export default class ConfigureServicesComponent extends Component {providers: {...sms.providers,twilio: {- ...(sms.providers.twilio || {}),+ ...sms.providers.twilio,sid: this.twilioSid,token: this.twilioToken,from: this.twilioFrom,diff --git a/console/app/controllers/console/admin/organizations/details.js b/console/app/controllers/console/admin/organizations/details.jsindex e7b1e27f..ee03d73c 100644--- a/console/app/controllers/console/admin/organizations/details.js+++ b/console/app/controllers/console/admin/organizations/details.js@@ -27,7 +27,7 @@ export default class ConsoleAdminOrganizationsDetailsController extends Controllmodel: tab.slug,priority: tab.priority ?? 50,}));- const tabs = [...coreTabs, ...registeredTabs].sort((a, b) => (a.priority ?? 99) - (b.priority ?? 99));+ const tabs = [...coreTabs, ...registeredTabs].sort((a, b) => a.priority - b.priority);return tabs.map((tab) => ({...tab,@@ -234,15 +234,20 @@ export default class ConsoleAdminOrganizationsDetailsController extends Controllyield this.router.transitionTo('console');this.session.manuallyAuthenticate(token);this.notifications.info(`Now impersonating ${this.ownerEmail || 'organization owner'}...`);- later(- this,- () => {- window.location.reload();- },- 600- );+ later(this, this.reloadWindow, 600);} catch (error) {this.notifications.serverError(error);}}++ /**+ * Reloading the window is the last step of impersonation. Location members are+ * non-configurable per spec, so this cannot be stubbed — it is isolated here so callers+ * can be tested by replacing the method, matching InstallationService,+ * ConsoleAdminOrganizationsController and ConsoleController.+ */+ /* istanbul ignore next -- window.location.reload() cannot be stubbed */+ reloadWindow() {+ window.location.reload();+ }}diff --git a/console/config/coverage.js b/console/config/coverage.jsindex 7f0b9bb2..f5638d77 100644--- a/console/config/coverage.js+++ b/console/config/coverage.js@@ -35,7 +35,12 @@ module.exports = {// Exclude generated/vendor and test files from the coverage denominator.// app/extensions/** are auto-generated extension manifests (declarative config// written by the extensions generator) — not hand-written, testable logic.- excludes: ['*/mirage/**', '*/tests/**', '**/*-test.js', '**/extensions/**'],+ // app/resolver.js is dead code: app/app.js imports Resolver straight from 'ember-resolver'+ // and nothing else references it. It is also broken — its resolveRoute() calls+ // super.resolveRoute(), which ember-resolver does not define, so every non-'main' route+ // would throw the moment the file was actually wired up. It is excluded rather than+ // tested; the file should be deleted or repaired separately.+ excludes: ['*/mirage/**', '*/tests/**', '**/*-test.js', '**/extensions/**', '**/resolver.js'],modifyAssetLocation(root, relativePath) {if (relativePath.startsWith(MODULE_PREFIX)) {diff --git a/console/tests/integration/components/configure/mail-test.js b/console/tests/integration/components/configure/mail-test.jsindex f232c76a..33c62505 100644--- a/console/tests/integration/components/configure/mail-test.js+++ b/console/tests/integration/components/configure/mail-test.js@@ -3,6 +3,8 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render, click } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';+import ConfigureMailComponent from '@fleetbase/console/components/configure/mail';+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';module('Integration | Component | configure/mail', function (hooks) {setupRenderingTest(hooks);@@ -52,3 +54,132 @@ module('Integration | Component | configure/mail', function (hooks) {assert.strictEqual(this.posted.at(-1).path, 'settings/mail-config');});});++/**+ * The panel's tasks and setters are not all reachable from the rendered UI — there is no+ * control for the encryption toggle or the test-send in this test's markup, and the error+ * paths need a failing endpoint — so this module drives the captured instance.+ */+module('Integration | Component | configure/mail | actions', function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.posted = [];+ this.getResponse = { mailer: 'smtp', smtpHost: 'smtp.acme.test' };+ this.getRejectsWith = null;+ this.postRejectsWith = null;+ this.postResponse = { status: 'ok' };+ const context = this;++ class FetchStub extends Service {+ async get() {+ if (context.getRejectsWith) {+ throw context.getRejectsWith;+ }++ return context.getResponse;+ }+ async post(path, payload) {+ context.posted.push({ path, payload });++ if (context.postRejectsWith) {+ throw context.postRejectsWith;+ }++ return context.postResponse;+ }+ }+ class RecordingNotificationsStub extends Service {+ successes = [];+ serverErrors = [];+ success(message) {+ this.successes.push(message);+ }+ serverError(error) {+ this.serverErrors.push(error);+ }+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', RecordingNotificationsStub);++ const captured = captureComponent(this.owner, 'configure/mail', ConfigureMailComponent);+ this.build = async () => {+ await render(hbs`+ <div id="next-view-section-subheader-actions"></div>+ <Configure::Mail />+ `);++ return captured.instance;+ };+ this.notifications = () => this.owner.lookup('service:notifications');+ });++ test('enabling SMTP encryption selects TLS and disabling it clears the setting', async function (assert) {+ const component = await this.build();++ component.enableSmtpEncryption(true);+ assert.strictEqual(component.smtpEncryption, 'tls');++ component.enableSmtpEncryption(false);+ assert.strictEqual(component.smtpEncryption, null, 'the field is cleared rather than set to a falsy string');+ });++ test('choosing a mailer switches which section is configured', async function (assert) {+ const component = await this.build();++ component.setMailer('mailgun');++ assert.strictEqual(component.mailer, 'mailgun');+ });++ test('a test send posts every provider section and keeps the response', async function (assert) {+ this.postResponse = { status: 'sent', message: 'Test email delivered.' };+ const component = await this.build();+ component.setMailer('postmark');+ component.postmarkToken = 'pm-token';+ component.fromAddress = '[email protected]';++ await component.test.perform();++ const { path, payload } = this.posted.at(-1);+ assert.strictEqual(path, 'settings/test-mail-config');+ assert.strictEqual(payload.mailer, 'postmark');+ assert.deepEqual(payload.from, { address: '[email protected]', name: null });+ assert.strictEqual(payload.postmark.token, 'pm-token', 'the selected provider is serialized');+ assert.strictEqual(payload.smtp.host, 'smtp.acme.test', 'and so are the ones that are not selected');+ assert.deepEqual(component.testResponse, this.postResponse, 'the result is held for the panel to render');+ });++ test('a failed test send is reported and leaves no response behind', async function (assert) {+ const failure = new Error('smtp unreachable');+ this.postRejectsWith = failure;+ const component = await this.build();++ await component.test.perform();++ assert.deepEqual(this.notifications().serverErrors, [failure]);+ assert.strictEqual(component.testResponse, undefined, 'nothing is shown as a result');+ });++ test('a failed save is reported instead of thrown', async function (assert) {+ const failure = new Error('mail config rejected');+ const component = await this.build();+ this.postRejectsWith = failure;++ await component.save.perform();++ assert.deepEqual(this.notifications().serverErrors, [failure]);+ assert.deepEqual(this.notifications().successes, [], 'nothing is claimed to have been saved');+ });++ test('a failed config load is reported and leaves the defaults in place', async function (assert) {+ const failure = new Error('mail config unavailable');+ this.getRejectsWith = failure;++ const component = await this.build();++ assert.deepEqual(this.notifications().serverErrors, [failure]);+ assert.strictEqual(component.smtpHost, 'smtp.mailgun.org', 'the shipped default survives');+ });+});diff --git a/console/tests/integration/components/configure/platform-api-token-test.js b/console/tests/integration/components/configure/platform-api-token-test.jsindex 33b4be2a..05c60bea 100644--- a/console/tests/integration/components/configure/platform-api-token-test.js+++ b/console/tests/integration/components/configure/platform-api-token-test.js@@ -3,6 +3,8 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';import { render, click } from '@ember/test-helpers';import { hbs } from 'ember-cli-htmlbars';import Service from '@ember/service';+import ConfigurePlatformApiTokenComponent from '@fleetbase/console/components/configure/platform-api-token';+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';class NotificationsStub extends Service {successes = [];@@ -222,3 +224,65 @@ module('Integration | Component | configure/platform-api-token', function (hooks}});});++module('Integration | Component | configure/platform-api-token | edge cases', function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.owner.lookup('service:intl').setLocale('en-us');+ this.posted = [];+ const context = this;++ class FetchStub extends Service {+ async get() {+ return { configured: false };+ }+ async post(path) {+ context.posted.push(path);+ return { configured: true, token: 'pat_generated', rotated_at: '2026-01-01T00:00:00Z', last_used_at: null };+ }+ }+ class NotificationsStub extends Service {+ successes = [];+ success(message) {+ this.successes.push(message);+ }+ serverError() {}+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);++ const captured = captureComponent(this.owner, 'configure/platform-api-token', ConfigurePlatformApiTokenComponent);+ this.build = async () => {+ await render(hbs`<Configure::PlatformApiToken />`);+ return captured.instance;+ };+ });++ test('there is nothing to copy before a token has been generated', async function (assert) {+ const component = await this.build();+ const written = [];+ const original = navigator.clipboard;+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: { writeText: (text) => written.push(text) } });++ try {+ component.copyToken();++ assert.deepEqual(written, [], 'the clipboard is left alone');+ assert.deepEqual(this.owner.lookup('service:notifications').successes, [], 'and nothing is reported as copied');+ } finally {+ Object.defineProperty(navigator, 'clipboard', { configurable: true, value: original });+ }+ });++ test('generating a token for the first time is not treated as a rotation', async function (assert) {+ const component = await this.build();++ await component.rotateToken.perform();++ assert.deepEqual(this.posted, ['settings/platform-api-token']);+ assert.strictEqual(component.token, 'pat_generated', 'the new token is held for the user to copy');+ assert.true(component.status.configured);+ });+});diff --git a/console/tests/integration/components/configure/services-test.js b/console/tests/integration/components/configure/services-test.jsindex e0e6ce25..6b44c598 100644--- a/console/tests/integration/components/configure/services-test.js+++ b/console/tests/integration/components/configure/services-test.js@@ -600,3 +600,50 @@ module('Integration | Component | configure/services | actions', function (hooksassert.deepEqual(JSON.parse(component.customHttpBodyText), { to: '{{to}}', text: '{{text}}', from: '{{from}}' }, 'the templated default body is offered');});});++module('Integration | Component | configure/services | sparse sms config', function (hooks) {+ setupRenderingTest(hooks);++ hooks.beforeEach(function () {+ this.getResponse = {};+ const context = this;++ class SparseFetchStub extends Service {+ async get() {+ return context.getResponse;+ }+ async post() {+ return { status: 'success' };+ }+ }+ class QuietNotificationsStub extends Service {+ serverError() {}+ }++ this.owner.register('service:fetch', SparseFetchStub);+ this.owner.register('service:notifications', QuietNotificationsStub);++ const captured = captureComponent(this.owner, 'configure/services', ConfigureServicesComponent);+ this.build = async () => {+ await render(hbs`+ <div id="next-view-section-subheader-actions"></div>+ <Configure::Services />+ `);++ return captured.instance;+ };+ });++ test('a custom HTTP provider saved without headers reads back as an empty object', async function (assert) {+ // An incoming providers block replaces the shipped defaults wholesale, so a+ // custom_http entry written by an older version has neither headers nor query params.+ this.getResponse = { sms: { defaultProvider: 'custom_http', providers: { custom_http: { method: 'POST', url: 'https://gw.test/send' } } } };++ const component = await this.build();++ assert.strictEqual(component.customHttpHeadersText, '{}', 'the headers editor opens on an empty object rather than "undefined"');+ assert.strictEqual(component.customHttpQueryParamsText, '{}', 'and so does the query params editor');+ assert.strictEqual(component.customHttpBodyText, JSON.stringify({ to: '{{to}}', text: '{{text}}', from: '{{from}}' }, null, 2), 'a missing body falls back to the templated default');+ assert.strictEqual(component.smsSelectedProvider, 'custom_http', 'the saved provider is the one shown');+ });+});diff --git a/console/tests/unit/controllers/console/account/auth-test.js b/console/tests/unit/controllers/console/account/auth-test.jsindex b1c52d01..ca60d27e 100644--- a/console/tests/unit/controllers/console/account/auth-test.js+++ b/console/tests/unit/controllers/console/account/auth-test.js@@ -324,3 +324,62 @@ module('Unit | Controller | console/account/auth | credentials and 2FA', functioassert.deepEqual(this.notifications().successes, []);});});++module('Unit | Controller | console/account/auth | form submission', function (hooks) {+ setupTest(hooks);++ // changePassword waits on the validate-password modal, which never resolves on its own.+ function stubModals(owner, isValid) {+ class ModalsManagerStub extends Service {+ show(name, options) {+ options.onValidated(isValid);+ return Promise.resolve();+ }+ }++ owner.register('service:modals-manager', ModalsManagerStub);+ }++ test('changePassword stops the form submitting the page away', async function (assert) {+ const { posts, notified } = stubServices(this.owner, { post: () => Promise.resolve({ status: 'ok' }) });+ stubModals(this.owner, true);+ const controller = this.owner.lookup('controller:console/account/auth');+ controller.newPassword = 'new-password';+ controller.newConfirmPassword = 'new-password';++ const event = new Event('submit', { cancelable: true });+ await controller.changePassword.perform(event);++ assert.true(event.defaultPrevented, 'the native submit is cancelled');+ assert.deepEqual(posts.at(-1), {+ path: 'users/change-password',+ payload: { password: 'new-password', password_confirmation: 'new-password' },+ });+ assert.deepEqual(notified.success, ['Password change successfully.']);+ assert.strictEqual(controller.newPassword, undefined, 'the form is cleared afterwards');+ });++ test('a password that fails validation clears the form without changing anything', async function (assert) {+ const { posts } = stubServices(this.owner);+ stubModals(this.owner, false);+ const controller = this.owner.lookup('controller:console/account/auth');+ controller.newPassword = 'new-password';+ controller.newConfirmPassword = 'new-password';++ await controller.changePassword.perform();++ assert.deepEqual(posts, [], 'nothing is sent');+ assert.strictEqual(controller.newPassword, undefined);+ assert.strictEqual(controller.newConfirmPassword, undefined);+ });++ test('saving 2FA settings with nothing selected posts an empty settings object', async function (assert) {+ const { posts, notified } = stubServices(this.owner);+ const controller = this.owner.lookup('controller:console/account/auth');++ await controller.saveUserTwoFaSettings.perform();++ assert.deepEqual(posts.at(-1), { path: 'users/two-fa', payload: { twoFaSettings: {} } });+ assert.deepEqual(notified.success, ['2FA Settings saved successfully.']);+ });+});diff --git a/console/tests/unit/controllers/console/admin/organizations/details-test.js b/console/tests/unit/controllers/console/admin/organizations/details-test.jsindex be455379..3fe885fd 100644--- a/console/tests/unit/controllers/console/admin/organizations/details-test.js+++ b/console/tests/unit/controllers/console/admin/organizations/details-test.js@@ -1,6 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';+import { settled } from '@ember/test-helpers';class NotificationsStub extends Service {successes = [];@@ -494,3 +495,97 @@ module('Unit | Controller | console/admin/organizations/details | registry fallbassert.strictEqual(this.controller.extensionContext.organization, this.controller.model);});});++/**+ * The impersonation success path ends in a window reload, which is isolated behind+ * reloadWindow() precisely so it can be replaced here — Location members are+ * non-configurable, so the real call can never be stubbed.+ */+module('Unit | Controller | console/admin/organizations/details | impersonation', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ const self = this;+ this.posted = [];++ class FetchStub extends Service {+ post(path, payload) {+ self.posted.push({ path, payload });+ return Promise.resolve({ token: 'imp-token' });+ }+ }+ class SessionStub extends Service {+ authenticated = [];+ data = { authenticated: { user: { id: 'me' } } };+ manuallyAuthenticate(token) {+ this.authenticated.push(token);+ }+ }++ this.owner.register('service:notifications', NotificationsStub);+ this.owner.register('service:modals-manager', ModalsManagerStub);+ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:session', SessionStub);++ this.controller = this.owner.lookup('controller:console/admin/organizations/details');+ this.notifications = this.owner.lookup('service:notifications');+ this.session = this.owner.lookup('service:session');++ this.transitions = [];+ Object.defineProperty(this.controller.router, 'transitionTo', {+ configurable: true,+ value: (...args) => {+ this.transitions.push(args);+ return Promise.resolve();+ },+ });++ this.reloads = 0;+ Object.defineProperty(this.controller, 'reloadWindow', { configurable: true, value: () => this.reloads++ });+ });++ test('impersonating an owner authenticates as them and reloads the console', async function (assert) {+ this.controller.model = organization({ owner_uuid: 'u1' });+ Object.defineProperty(this.controller, 'owner', { configurable: true, value: { id: 'u1', email: '[email protected]' } });++ await this.controller.impersonateOwner.perform();++ assert.deepEqual(this.posted.at(-1), { path: 'auth/impersonate', payload: { user: 'u1' } });+ assert.deepEqual(this.transitions, [['console']], 'the console is entered before the session is swapped');+ assert.deepEqual(this.session.authenticated, ['imp-token'], 'the impersonation token replaces the current session');+ assert.deepEqual(this.notifications.infos, ['Now impersonating [email protected]...'], 'the owner is named');+ assert.strictEqual(this.reloads, 0, 'the reload is deferred rather than immediate');++ await settled();+ assert.strictEqual(this.reloads, 1, 'and lands once the timer fires');+ });++ test('an owner with no email address is described generically', async function (assert) {+ this.controller.model = organization({ owner_uuid: 'u1' });++ await this.controller.impersonateOwner.perform();+ await settled();++ assert.deepEqual(this.notifications.infos, ['Now impersonating organization owner...']);+ assert.strictEqual(this.reloads, 1);+ });++ test('a registered action in the action menu runs when clicked', async function (assert) {+ const clicked = [];+ Object.defineProperty(this.controller.menuService, 'getMenuItems', {+ configurable: true,+ value: (registry) =>+ registry === 'console:admin:organization:actions' ? [{ label: 'Sync Billing', icon: 'sync', class: 'danger', onClick: (context) => clicked.push(context) }] : [],+ });+ this.controller.model = organization({ uuid: 'uuid_1' });++ const item = this.controller.actionMenuItems.find((entry) => entry.label === 'Sync Billing');+ assert.strictEqual(item.icon, 'sync');+ assert.strictEqual(item.class, 'danger');++ item.onClick();++ assert.strictEqual(clicked.length, 1, 'the registered handler runs');+ assert.strictEqual(clicked[0].organization, this.controller.model, 'and receives the extension context');+ });+});diff --git a/console/tests/unit/controllers/console/admin/two-fa-settings-test.js b/console/tests/unit/controllers/console/admin/two-fa-settings-test.jsindex 2021bc8d..cfda3e77 100644--- a/console/tests/unit/controllers/console/admin/two-fa-settings-test.js+++ b/console/tests/unit/controllers/console/admin/two-fa-settings-test.js@@ -109,3 +109,42 @@ module('Unit | Controller | console/admin/two-fa-settings', function (hooks) {assert.false(controller.isLoading);});});++module('Unit | Controller | console/admin/two-fa-settings | defaults', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ this.requests = [];+ const context = this;++ class FetchStub extends Service {+ get(path) {+ context.requests.push({ method: 'get', path });+ return Promise.resolve({ enabled: false });+ }+ post(path, payload) {+ context.requests.push({ method: 'post', path, payload });+ return Promise.resolve({ ok: true });+ }+ }+ class NotificationsStub extends Service {+ successes = [];+ success(message) {+ this.successes.push(message);+ }+ serverError() {}+ }++ this.owner.register('service:fetch', FetchStub);+ this.owner.register('service:notifications', NotificationsStub);+ });++ test('saving with nothing supplied posts an empty settings object', async function (assert) {+ const controller = this.owner.lookup('controller:console/admin/two-fa-settings');++ await controller.saveTwoFactorSettingsForAdmin.perform();++ const post = this.requests.find((request) => request.method === 'post');+ assert.deepEqual(post, { method: 'post', path: 'two-fa/config', payload: { twoFaSettings: {} } });+ });+});diff --git a/console/tests/unit/controllers/console/settings/notifications-test.js b/console/tests/unit/controllers/console/settings/notifications-test.jsindex cfb9ceac..bd2e7084 100644--- a/console/tests/unit/controllers/console/settings/notifications-test.js+++ b/console/tests/unit/controllers/console/settings/notifications-test.js@@ -200,3 +200,80 @@ module('Unit | Controller | console/settings/notifications | persistence', functassert.deepEqual(this.notifications().serverErrors, [failure]);});});++module('Unit | Controller | console/settings/notifications | company options', function (hooks) {+ setupTest(hooks);++ hooks.beforeEach(function () {+ class FetchStub extends Service {+ get() {+ return Promise.resolve({ notificationSettings: {} });+ }+ }+ this.owner.register('service:fetch', FetchStub);++ this.build = async () => {+ const controller = this.owner.lookup('controller:console/settings/notifications');+ await settled();++ // Stands in for the company record: only options and set() are read.+ controller.company = {+ options: undefined,+ set(key, value) {+ this[key] = value;+ },+ };++ return controller;+ };+ });++ test('a company that has never had options gets a fresh options object', async function (assert) {+ const controller = await this.build();++ controller.setAlphaNumericSenderId({ target: { value: 'FLEETBASE' } });++ assert.deepEqual(controller.company.options, { alpha_numeric_sender_id: 'FLEETBASE' });+ });++ test('existing company options are preserved when the sender id changes', async function (assert) {+ const controller = await this.build();+ controller.company.options = { alpha_numeric_sender_id_enabled: true, unrelated: 'kept' };++ controller.setAlphaNumericSenderId({ target: { value: 'ACME' } });++ assert.deepEqual(controller.company.options, {+ alpha_numeric_sender_id_enabled: true,+ unrelated: 'kept',+ alpha_numeric_sender_id: 'ACME',+ });+ });++ test('selecting notifiables twice for the same notification updates the existing entry', async function (assert) {+ const controller = await this.build();+ const notification = { definition: 'order.created', name: 'Order Created' };++ controller.onSelectNotifiable(notification, [{ value: 'user_1' }]);+ const key = Object.keys(controller.notificationSettings)[0];++ controller.onSelectNotifiable(notification, [{ value: 'user_2' }, { value: 'user_3' }]);++ assert.deepEqual(Object.keys(controller.notificationSettings), [key], 'the same key is reused rather than duplicated');+ assert.deepEqual(controller.notificationSettings[key].notifiables, [{ value: 'user_2' }, { value: 'user_3' }], 'the selection is replaced');+ });++ test('mutating with nothing leaves the settings as they were', async function (assert) {+ const controller = await this.build();+ controller.notificationSettings = { 'order.created': { definition: 'order.created' } };++ controller.mutateNotificationSettings();++ assert.deepEqual(controller.notificationSettings, { 'order.created': { definition: 'order.created' } });+ });++ test('the transport methods a notifiable is reachable on default to email and sms', async function (assert) {+ const controller = await this.build();++ assert.deepEqual(controller.notificationTransportMethods, ['email', 'sms']);+ });+});diff --git a/console/tests/unit/controllers/tracked-defaults-test.js b/console/tests/unit/controllers/tracked-defaults-test.jsindex 0d54a957..e9702669 100644--- a/console/tests/unit/controllers/tracked-defaults-test.js+++ b/console/tests/unit/controllers/tracked-defaults-test.js@@ -1,6 +1,7 @@import { module, test } from 'qunit';import { setupTest } from '@fleetbase/console/tests/helpers';import Service from '@ember/service';+import getTwoFaMethods from '@fleetbase/console/utils/get-two-fa-methods';/*** A @tracked field's initializer only runs the first time the property is read, so a@@ -17,6 +18,21 @@ const CONTROLLERS = [name: 'controller:auth/two-fa',defaults: { otpValue: '', countdownReady: false, isCodeExpired: false, verificationCode: '' },},+ // These three load their real state from the API in their constructors. The defaults+ // below are what the screen shows in the moment before that request comes back, so they+ // are read synchronously — a settled() here would overwrite them with the response.+ {+ name: 'controller:console/account/auth',+ defaults: { twoFaConfig: {}, isSystemTwoFaEnabled: false, methods: getTwoFaMethods() },+ },+ {+ name: 'controller:console/admin/two-fa-settings',+ defaults: { twoFaConfig: {}, isSystemTwoFaEnabled: false, isTwoFaEnforced: false, isLoading: false },+ },+ {+ name: 'controller:console/settings/notifications',+ defaults: { notificationSettings: {}, notificationTransportMethods: ['email', 'sms'] },+ },];module('Unit | Controller | tracked defaults', function (hooks) {@@ -40,7 +56,7 @@ module('Unit | Controller | tracked defaults', function (hooks) {const controller = this.owner.lookup(name);for (const [property, value] of Object.entries(defaults)) {- assert.strictEqual(controller[property], value, property);+ assert.deepEqual(controller[property], value, property);}});});diff --git a/console/tests/unit/instance-initializers/initialize-widgets-test.js b/console/tests/unit/instance-initializers/initialize-widgets-test.jsindex 97a15df1..ad9ac26b 100644--- a/console/tests/unit/instance-initializers/initialize-widgets-test.js+++ b/console/tests/unit/instance-initializers/initialize-widgets-test.js@@ -1,5 +1,6 @@import { module, test } from 'qunit';import { initialize } from '@fleetbase/console/instance-initializers/initialize-widgets';+import { Widget } from '@fleetbase/ember-core/contracts';function widgetServiceStub() {return {@@ -62,3 +63,56 @@ module('Unit | Instance Initializer | initialize-widgets', function () {assert.ok(Array.isArray(widgetService.registeredByDashboard.admin), 'admin widgets are registered too');});});++/**+ * Extensions can contribute admin widgets through the menu registry. Whatever they hand+ * over has to end up as a Widget, and an extension that registers nothing at all must not+ * break the boot.+ */+module('Unit | Instance Initializer | initialize-widgets | extension widgets', function () {+ function appInstanceWithRegistry(widgetService, onBoot, registered) {+ const universe = { getService: () => widgetService, onBoot };++ return {+ lookup(name) {+ return name === 'service:universe' ? universe : { getMenuItems: () => registered };+ },+ };+ }++ function bootWith(registered) {+ const widgetService = widgetServiceStub();+ let bootCallback;++ initialize(appInstanceWithRegistry(widgetService, (callback) => (bootCallback = callback), registered));+ bootCallback();++ return widgetService.registeredByDashboard.admin;+ }++ test('a registry that has never been written to contributes no extension widgets', function (assert) {+ const admin = bootWith(undefined);++ assert.ok(Array.isArray(admin), 'the core admin widgets are still registered');+ assert.deepEqual(+ admin.filter((widget) => widget.category === 'Extension Widgets'),+ [],+ 'and nothing is added on top of them'+ );+ });++ test('a plain object from an extension is wrapped as a Widget, an existing Widget is left alone', function (assert) {+ const alreadyAWidget = new Widget({ id: 'ext-prebuilt', name: 'Prebuilt', component: 'ext/prebuilt', category: 'Prebuilt Category' });+ const admin = bootWith([alreadyAWidget, { id: 'ext-raw', name: 'Raw', component: 'ext/raw' }]);++ const prebuilt = admin.find((widget) => widget.id === 'ext-prebuilt');+ assert.strictEqual(prebuilt, alreadyAWidget, 'an extension that built its own Widget keeps it');+ assert.strictEqual(prebuilt.category, 'Prebuilt Category', 'including its own category');++ const raw = admin.find((widget) => widget.id === 'ext-raw');+ assert.ok(raw instanceof Widget, 'a plain object is promoted to a Widget');+ assert.strictEqual(raw.name, 'Raw', 'its own fields survive');+ assert.strictEqual(raw.category, 'Extension Widgets', 'and it is filed under the extension category');+ assert.strictEqual(raw.component, 'ext/raw', 'and still points at the extension component');+ });+});diff --git a/console/tests/unit/utils/router-refresh-patch-test.js b/console/tests/unit/utils/router-refresh-patch-test.jsindex c6b213f8..eb64b6d8 100644--- a/console/tests/unit/utils/router-refresh-patch-test.js+++ b/console/tests/unit/utils/router-refresh-patch-test.js@@ -223,3 +223,49 @@ module('Unit | Utility | router-refresh-patch', function () {assert.true(microlib._fleetbaseRefreshPatched);});});++module('Unit | Utility | router-refresh-patch | unhandled rejections', function (hooks) {+ hooks.beforeEach(function () {+ // The listener is installed on window and there is no way to remove it afterwards,+ // so capture it instead of letting it attach to the real window.+ this.original = window.addEventListener;+ this.listeners = {};+ window.addEventListener = (type, listener) => (this.listeners[type] = listener);+ });++ hooks.afterEach(function () {+ window.addEventListener = this.original;+ });++ test('the known refresh rejection is suppressed before it reaches the console', function (assert) {+ suppressRouterRefreshErrors({});++ let prevented = false;+ this.listeners.unhandledrejection({+ reason: new Error("You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments"),+ preventDefault: () => (prevented = true),+ });++ assert.true(prevented, 'the rejection is swallowed');+ });++ test('any other rejection is left alone', function (assert) {+ suppressRouterRefreshErrors({});+ const seen = [];+ const dispatch = (reason) => this.listeners.unhandledrejection({ reason, preventDefault: () => seen.push(reason) });++ dispatch(new Error('a completely unrelated failure'));+ dispatch({ message: 42 });+ dispatch(undefined);++ assert.deepEqual(seen, [], 'nothing without the known message is touched, and a non-string or missing message does not throw');+ });++ test('a window that rejects listener registration does not break boot', function (assert) {+ window.addEventListener = () => {+ throw new Error('listeners are unavailable');+ };++ assert.strictEqual(suppressRouterRefreshErrors({}), undefined, 'the failure is swallowed');+ });+});