Skip to content

Modular logistics and supply chain operating system (LSOS)

fix(console): pass the dashboard count formatters their real arguments

Ronald A. Richardson4b820458684e
diff --git a/console/app/components/dashboard/count.js b/console/app/components/dashboard/count.js
index f1a542b8..c2d75f01 100644
--- a/console/app/components/dashboard/count.js
+++ b/console/app/components/dashboard/count.js
@@ -55,25 +55,30 @@ export default class DashboardCountComponent extends Component {
let { format, currency, dateFormat, value } = options;
+ // These are plain utils taking positional arguments, not helpers taking a params
+ // array. Passing `[value, currency]` meant the currency and date format were never
+ // read, and date-fns rejects an array outright, so a count configured with
+ // format: 'date' threw "RangeError: Invalid time value" and broke the render.
switch (format) {
case 'money':
- value = formatCurrency([value, currency]);
+ value = formatCurrency(value, currency);
break;
case 'meters':
- value = formatMeters([value]);
+ value = formatMeters(value);
break;
case 'bytes':
- value = formatBytes([value]);
+ value = formatBytes(value);
break;
case 'duration':
- value = formatDuration([value]);
+ value = formatDuration(value);
break;
case 'date':
- value = formatDate([value, dateFormat]);
+ // date-fns only accepts a Date or a timestamp, and API values arrive serialized.
+ value = formatDate(new Date(value), dateFormat);
break;
default:
diff --git a/console/app/components/impersonator-tray.js b/console/app/components/impersonator-tray.js
index 0533b83d..33b69846 100644
--- a/console/app/components/impersonator-tray.js
+++ b/console/app/components/impersonator-tray.js
@@ -24,7 +24,10 @@ export default class ImpersonatorTrayComponent extends Component {
await this.router.transitionTo('console');
this.session.manuallyAuthenticate(token);
this.notifications.info(`Ending impersonation session.`);
- later(
+
+ // Handed back so the caller can cancel the pending reload. Without this the
+ // timer is unreachable once scheduled and always reloads the window.
+ return later(
this,
() => {
window.location.reload();
diff --git a/console/tests/integration/components/admin/table/cell/owner-test.js b/console/tests/integration/components/admin/table/cell/owner-test.js
new file mode 100644
index 00000000..f26c76d3
--- /dev/null
+++ b/console/tests/integration/components/admin/table/cell/owner-test.js
@@ -0,0 +1,61 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
+import { render } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+import AdminTableCellOwnerComponent from '@fleetbase/console/components/admin/table/cell/owner';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
+
+/**
+ * The cell renders whatever `owner` resolves to. `resolveBelongsTo` exists to unwrap an
+ * Ember Data belongsTo proxy without ever showing a half-loaded record, so each of its
+ * shapes is asserted on the captured instance.
+ */
+module('Integration | Component | admin/table/cell/owner', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ const captured = captureComponent(this.owner, 'admin/table/cell/owner', AdminTableCellOwnerComponent);
+ this.build = async () => {
+ await render(hbs`<Admin::Table::Cell::Owner @row={{this.row}} />`);
+ return captured.instance;
+ };
+ });
+
+ test('a row with no owner resolves to null', async function (assert) {
+ this.set('row', {});
+ const component = await this.build();
+
+ assert.strictEqual(component.owner, null);
+ });
+
+ test('a missing row resolves to null rather than throwing', async function (assert) {
+ this.set('row', undefined);
+ const component = await this.build();
+
+ assert.strictEqual(component.owner, null);
+ });
+
+ test('a resolved belongsTo proxy is unwrapped to its content', async function (assert) {
+ const record = { name: 'Fleetbase' };
+ this.set('row', { owner: { content: record, isFulfilled: true } });
+ const component = await this.build();
+
+ assert.strictEqual(component.owner, record, 'the underlying record is shown');
+ });
+
+ test('a plain record is used as-is', async function (assert) {
+ const record = { name: 'Fleetbase' };
+ this.set('row', { owner: record });
+ const component = await this.build();
+
+ assert.strictEqual(component.owner, record);
+ });
+
+ test('an unresolved belongsTo proxy is withheld until it loads', async function (assert) {
+ const component = await this.build();
+
+ assert.strictEqual(component.resolveBelongsTo({ isPending: true }), null, 'a pending proxy shows nothing');
+ assert.strictEqual(component.resolveBelongsTo({ isFulfilled: false }), null, 'an unfulfilled proxy shows nothing');
+ assert.strictEqual(component.resolveBelongsTo({ then: () => {} }), null, 'a bare thenable shows nothing');
+ });
+});
diff --git a/console/tests/integration/components/admin/widget/chart-panel-test.js b/console/tests/integration/components/admin/widget/chart-panel-test.js
new file mode 100644
index 00000000..31ce8c70
--- /dev/null
+++ b/console/tests/integration/components/admin/widget/chart-panel-test.js
@@ -0,0 +1,81 @@
+import { module, test } from 'qunit';
+import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
+import { render } from '@ember/test-helpers';
+import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
+import AdminWidgetChartPanelComponent from '@fleetbase/console/components/admin/widget/chart-panel';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
+
+module('Integration | Component | admin/widget/chart-panel', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.requested = [];
+ this.getResponse = { labels: ['Jan', 'Feb'], datasets: [{ label: 'Orders', data: [1, 2] }] };
+ const context = this;
+
+ class FetchStub extends Service {
+ async get(endpoint) {
+ context.requested.push(endpoint);
+ return context.getResponse;
+ }
+ }
+
+ this.owner.register('service:fetch', FetchStub);
+
+ const captured = captureComponent(this.owner, 'admin/widget/chart-panel', AdminWidgetChartPanelComponent);
+ this.build = async () => {
+ await render(hbs`<Admin::Widget::ChartPanel @options={{this.options}} />`);
+ return captured.instance;
+ };
+ });
+
+ test('the platform-growth widget is served by its own endpoint', async function (assert) {
+ this.set('options', { slug: 'platform-growth' });
+ const component = await this.build();
+
+ assert.strictEqual(component.endpoint, 'metrics/admin/growth', 'growth has a dedicated endpoint');
+ assert.deepEqual(this.requested, ['metrics/admin/growth']);
+ });
+
+ test('any other slug falls back to the generic widget endpoint', async function (assert) {
+ this.set('options', { slug: 'order-volume' });
+ const component = await this.build();
+
+ assert.strictEqual(component.endpoint, 'metrics/admin/widgets/order-volume', 'inherited from the list panel');
+ assert.deepEqual(this.requested, ['metrics/admin/widgets/order-volume']);
+ });
+
+ test('it exposes the loaded labels and datasets to the chart', async function (assert) {
+ this.set('options', { slug: 'platform-growth' });
+ const component = await this.build();
+
+ assert.deepEqual(component.chartLabels, ['Jan', 'Feb']);
+ // The rendered chart normalises the dataset objects it receives, so assert their
+ // shape rather than deep-equalling the literal the stub handed over.
+ assert.strictEqual(component.chartDatasets.length, 1);
+ assert.strictEqual(component.chartDatasets[0].label, 'Orders');
+ assert.deepEqual(component.chartDatasets[0].data, [1, 2]);
+ });
+
+ test('a response with no chart data yields empty labels and no datasets', async function (assert) {
+ this.getResponse = {};
+ this.set('options', { slug: 'platform-growth' });
+ const component = await this.build();
+
+ assert.deepEqual(component.chartLabels, [], 'labels default to empty');
+ assert.strictEqual(component.chartDatasets, null, 'a missing dataset reads as null so the chart can hide');
+ });
+
+ test('the chart options pin the legend and axes', async function (assert) {
+ this.set('options', { slug: 'platform-growth' });
+ const component = await this.build();
+ const options = component.chartOptions;
+
+ assert.true(options.responsive);
+ assert.false(options.maintainAspectRatio, 'the chart fills its panel rather than keeping a ratio');
+ assert.deepEqual(options.plugins.legend, { display: true, position: 'bottom' });
+ assert.false(options.scales.x.grid.display, 'the x gridlines are hidden');
+ assert.true(options.scales.y.beginAtZero);
+ });
+});
diff --git a/console/tests/integration/components/admin/widget/list-panel-test.js b/console/tests/integration/components/admin/widget/list-panel-test.js
index bca3dc58..a6761fe1 100644
--- a/console/tests/integration/components/admin/widget/list-panel-test.js
+++ b/console/tests/integration/components/admin/widget/list-panel-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 AdminWidgetListPanelComponent from '@fleetbase/console/components/admin/widget/list-panel';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
module('Integration | Component | admin/widget/list-panel', function (hooks) {
setupRenderingTest(hooks);
@@ -137,3 +139,159 @@ module('Integration | Component | admin/widget/list-panel', function (hooks) {
assert.strictEqual(this.requested.length, 2, 'the endpoint is requested again');
});
});
+
+/**
+ * The panel's getters all fall back through options -> loaded data -> a default, and its
+ * drilldown handlers are bound to click targets that only exist when data is present.
+ */
+module('Integration | Component | admin/widget/list-panel | behaviour', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.getResponse = {};
+ this.getRejectsWith = null;
+ const context = this;
+
+ class FetchStub extends Service {
+ async get() {
+ if (context.getRejectsWith) {
+ throw context.getRejectsWith;
+ }
+
+ return context.getResponse;
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const captured = captureComponent(this.owner, 'admin/widget/list-panel', AdminWidgetListPanelComponent);
+ this.build = async () => {
+ await render(hbs`<Admin::Widget::ListPanel @options={{this.options}} />`);
+ const component = captured.instance;
+
+ this.transitions = [];
+ Object.defineProperty(component.router, 'transitionTo', {
+ configurable: true,
+ value: (...args) => {
+ this.transitions.push(args);
+ return 'transition';
+ },
+ });
+
+ return component;
+ };
+ });
+
+ test('a widget with no slug reports the misconfiguration instead of requesting', async function (assert) {
+ this.set('options', {});
+ const component = await this.build();
+
+ assert.strictEqual(component.error, 'Missing dashboard widget slug.');
+ assert.strictEqual(component.data, null);
+ });
+
+ test('the panel falls back through options, loaded data and defaults', async function (assert) {
+ this.getResponse = { title: 'From data', subtitle: 'Data subtitle', icon: 'chart', items: [{ id: 1 }], empty: 'Nothing here' };
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.title, 'From data', 'the loaded title is used when options omit one');
+ assert.strictEqual(component.subtitle, 'Data subtitle');
+ assert.strictEqual(component.icon, 'chart');
+ assert.deepEqual(component.items, [{ id: 1 }]);
+ assert.strictEqual(component.emptyText, 'Nothing here');
+ assert.strictEqual(component.endpoint, 'metrics/admin/widgets/attention');
+ });
+
+ test('options win over the loaded data', async function (assert) {
+ this.getResponse = { title: 'From data', subtitle: 'Data subtitle', icon: 'chart' };
+ this.set('options', { slug: 'attention', title: 'From options', subtitle: 'Options subtitle', icon: 'flag' });
+ const component = await this.build();
+
+ assert.strictEqual(component.title, 'From options');
+ assert.strictEqual(component.subtitle, 'Options subtitle');
+ assert.strictEqual(component.icon, 'flag');
+ });
+
+ test('an empty widget falls back to its built-in labels', async function (assert) {
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.title, 'Admin Summary');
+ assert.strictEqual(component.subtitle, undefined);
+ assert.strictEqual(component.icon, 'list');
+ assert.deepEqual(component.items, []);
+ assert.strictEqual(component.emptyText, 'No items require attention.');
+ assert.false(component.hasDrilldown, 'with no route there is nothing to drill into');
+ });
+
+ test('a failed load records the error message', async function (assert) {
+ this.getRejectsWith = new Error('widget endpoint down');
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.error, 'widget endpoint down');
+ });
+
+ test('a failure with no message falls back to a generic one', async function (assert) {
+ this.getRejectsWith = {};
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.error, 'Unable to load dashboard widget.');
+ });
+
+ test('openItem transitions with the models and query params on the item', async function (assert) {
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ component.openItem({ route: 'console.admin.users', routeModels: ['abc'], queryParams: { status: 'active' } });
+
+ assert.deepEqual(this.transitions, [['console.admin.users', 'abc', { queryParams: { status: 'active' } }]]);
+ });
+
+ test('openItem defaults the models and query params when the item omits them', async function (assert) {
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ component.openItem({ route: 'console.admin.users' });
+
+ assert.deepEqual(this.transitions, [['console.admin.users', { queryParams: {} }]]);
+ });
+
+ test('openItem ignores an item with no route', async function (assert) {
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.openItem({}), undefined);
+ assert.strictEqual(component.openItem(undefined), undefined, 'a missing item is handled too');
+ assert.deepEqual(this.transitions, [], 'nothing navigates');
+ });
+
+ test('openDrilldown uses the loaded route and query params', async function (assert) {
+ this.getResponse = { route: 'console.admin.organizations', queryParams: { attention: true } };
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.true(component.hasDrilldown);
+ component.openDrilldown();
+
+ assert.deepEqual(this.transitions, [['console.admin.organizations', { queryParams: { attention: true } }]]);
+ });
+
+ test('openDrilldown falls back to the options route and an empty query', async function (assert) {
+ this.set('options', { slug: 'attention', route: 'console.admin.users' });
+ const component = await this.build();
+
+ component.openDrilldown();
+
+ assert.deepEqual(this.transitions, [['console.admin.users', { queryParams: {} }]]);
+ });
+
+ test('openDrilldown does nothing when no route is configured', async function (assert) {
+ this.set('options', { slug: 'attention' });
+ const component = await this.build();
+
+ assert.strictEqual(component.openDrilldown(), undefined);
+ assert.deepEqual(this.transitions, []);
+ });
+});
diff --git a/console/tests/integration/components/dashboard/count-test.js b/console/tests/integration/components/dashboard/count-test.js
index 091801e0..690d7c17 100644
--- a/console/tests/integration/components/dashboard/count-test.js
+++ b/console/tests/integration/components/dashboard/count-test.js
@@ -2,6 +2,8 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import DashboardCountComponent from '@fleetbase/console/components/dashboard/count';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
module('Integration | Component | dashboard/count', function (hooks) {
setupRenderingTest(hooks);
@@ -37,3 +39,84 @@ module('Integration | Component | dashboard/count', function (hooks) {
assert.dom(this.element).containsText('7');
});
});
+
+/**
+ * The value shown is derived from an options hash by a formatter chosen per `format`, so
+ * assert each branch of that switch.
+ */
+module('Integration | Component | dashboard/count | formatting', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ const captured = captureComponent(this.owner, 'dashboard/count', DashboardCountComponent);
+ this.build = async () => {
+ await render(hbs`<Dashboard::Count @title={{this.title}} @options={{this.options}} @value={{this.value}} />`);
+ return captured.instance;
+ };
+ });
+
+ test('an explicit value wins over anything in the options', async function (assert) {
+ this.set('title', 'Orders');
+ this.set('value', 'explicit');
+ this.set('options', { format: 'money', value: 1000 });
+
+ const component = await this.build();
+
+ assert.strictEqual(component.title, 'Orders');
+ assert.strictEqual(component.value, 'explicit', 'the options are not consulted when a value is given');
+ });
+
+ test('an unformatted option value is passed through untouched', async function (assert) {
+ this.set('options', { value: 42 });
+
+ const component = await this.build();
+
+ assert.strictEqual(component.value, 42);
+ });
+
+ test('money, meters, bytes, duration and date each get their own formatter', async function (assert) {
+ this.set('options', { value: 'seed' });
+ const component = await this.build();
+
+ // Drive the switch directly: re-rendering once per format would rebuild the
+ // component for no benefit.
+ component.createRenderValueFromOptions({ format: 'meters', value: 1500 });
+ assert.strictEqual(component.value, '2km', 'meters are rounded to kilometres');
+
+ component.createRenderValueFromOptions({ format: 'bytes', value: 2048 });
+ assert.strictEqual(component.value, '2 KB', 'bytes are scaled');
+
+ component.createRenderValueFromOptions({ format: 'duration', value: 3600 });
+ assert.notStrictEqual(component.value, 3600, `duration is formatted (got ${component.value})`);
+ assert.ok(String(component.value).length > 0);
+
+ component.createRenderValueFromOptions({ format: 'date', value: '2026-01-15T12:00:00Z', dateFormat: 'yyyy-MM-dd' });
+ assert.strictEqual(component.value, '2026-01-15', 'the configured date format is applied');
+
+ component.createRenderValueFromOptions({ format: 'unknown-format', value: 'passed through' });
+ assert.strictEqual(component.value, 'passed through', 'an unrecognised format is left alone');
+ });
+
+ test('the configured currency is used for money values', async function (assert) {
+ this.set('options', { value: 'seed' });
+ const component = await this.build();
+
+ component.createRenderValueFromOptions({ format: 'money', value: 1234, currency: 'USD' });
+ const inDollars = component.value;
+
+ component.createRenderValueFromOptions({ format: 'money', value: 1234, currency: 'EUR' });
+ const inEuros = component.value;
+
+ assert.notStrictEqual(inDollars, 1234, `money is formatted (got ${inDollars})`);
+ assert.notStrictEqual(inDollars, inEuros, `the currency changes the output (${inDollars} vs ${inEuros})`);
+ });
+
+ test('a count with no options at all still builds', async function (assert) {
+ this.set('options', undefined);
+ this.set('value', undefined);
+
+ const component = await this.build();
+
+ assert.strictEqual(component.value, undefined, 'nothing to derive a value from');
+ });
+});
diff --git a/console/tests/integration/components/dashboard/query-params-test.js b/console/tests/integration/components/dashboard/query-params-test.js
index 83505a78..8e5d6a66 100644
--- a/console/tests/integration/components/dashboard/query-params-test.js
+++ b/console/tests/integration/components/dashboard/query-params-test.js
@@ -2,6 +2,8 @@ import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import DashboardQueryParamsComponent from '@fleetbase/console/components/dashboard/query-params';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
module('Integration | Component | dashboard/query-params', function (hooks) {
setupRenderingTest(hooks);
@@ -27,3 +29,66 @@ module('Integration | Component | dashboard/query-params', function (hooks) {
assert.dom(this.element).hasText('');
});
});
+
+/**
+ * onChange is wired to third-party controls (selects and a date picker), so drive it on
+ * the captured instance.
+ */
+module('Integration | Component | dashboard/query-params | onChange', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.changes = [];
+ this.set('onChange', (params) => this.changes.push(params));
+ this.set('params', {
+ range: { label: 'Range', component: 'select', options: ['7d', '30d'] },
+ start: { label: 'Start', component: 'date-picker' },
+ });
+
+ const captured = captureComponent(this.owner, 'dashboard/query-params', DashboardQueryParamsComponent);
+ this.build = async () => {
+ await render(hbs`<Dashboard::QueryParams @params={{this.params}} @onChange={{this.onChange}} />`);
+ return captured.instance;
+ };
+ this.buildBare = async () => {
+ await render(hbs`<Dashboard::QueryParams @params={{this.params}} />`);
+ return captured.instance;
+ };
+ });
+
+ test('a plain param change is accumulated and reported', async function (assert) {
+ const component = await this.build();
+
+ component.onChange('range', '30d');
+
+ assert.deepEqual(component.changedParams, { range: '30d' });
+ assert.deepEqual(this.changes, [{ range: '30d' }], 'the caller receives the whole set');
+ });
+
+ test('a date picker change is reduced to its formatted date', async function (assert) {
+ const component = await this.build();
+
+ component.onChange('start', { formattedDate: '2026-01-01', date: new Date() });
+
+ assert.deepEqual(component.changedParams, { start: '2026-01-01' }, 'only the formatted date is kept');
+ });
+
+ test('successive changes accumulate rather than replace', async function (assert) {
+ const component = await this.build();
+
+ component.onChange('range', '7d');
+ component.onChange('start', { formattedDate: '2026-02-01' });
+ component.onChange('range', '30d');
+
+ assert.deepEqual(component.changedParams, { range: '30d', start: '2026-02-01' }, 'the latest value of each param is kept');
+ assert.strictEqual(this.changes.length, 3, 'every change is reported');
+ });
+
+ test('it works without an onChange listener', async function (assert) {
+ const component = await this.buildBare();
+
+ component.onChange('range', '7d');
+
+ assert.deepEqual(component.changedParams, { range: '7d' }, 'state still updates with nothing listening');
+ });
+});
diff --git a/console/tests/integration/components/fleetbase-blog-test.js b/console/tests/integration/components/fleetbase-blog-test.js
index cbfed904..f9f6b13c 100644
--- a/console/tests/integration/components/fleetbase-blog-test.js
+++ b/console/tests/integration/components/fleetbase-blog-test.js
@@ -4,6 +4,8 @@ import Service from '@ember/service';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import { _resetStorages } from 'ember-local-storage/helpers/storage';
+import FleetbaseBlogComponent from '@fleetbase/console/components/fleetbase-blog';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
module('Integration | Component | fleetbase-blog', function (hooks) {
setupRenderingTest(hooks);
@@ -65,3 +67,76 @@ module('Integration | Component | fleetbase-blog', function (hooks) {
assert.dom('.fleetbase-blog').containsText('No blog posts are available right now.');
});
});
+
+/**
+ * The blog falls back to the API when its local cache is empty or stale, and formats each
+ * post's publish date defensively.
+ */
+module('Integration | Component | fleetbase-blog | loading', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ _resetStorages();
+ window.localStorage.clear();
+
+ this.getResponse = [{ title: 'Fleetbase 0.8', pubDate: '2026-01-15T00:00:00Z' }];
+ this.getRejectsWith = null;
+ const context = this;
+
+ class FetchStub extends Service {
+ async get() {
+ if (context.getRejectsWith) {
+ throw context.getRejectsWith;
+ }
+
+ return context.getResponse;
+ }
+ }
+ this.owner.register('service:fetch', FetchStub);
+
+ const captured = captureComponent(this.owner, 'fleetbase-blog', FleetbaseBlogComponent);
+ this.build = async () => {
+ await render(hbs`<FleetbaseBlog />`);
+ return captured.instance;
+ };
+ });
+
+ hooks.afterEach(function () {
+ _resetStorages();
+ window.localStorage.clear();
+ });
+
+ test('an empty cache loads the posts and caches them', async function (assert) {
+ const component = await this.build();
+
+ assert.deepEqual(component.posts, this.getResponse);
+ assert.deepEqual(component.localCache.get('fleetbase-blog-data'), this.getResponse, 'the posts are cached');
+ assert.ok(component.localCache.get('fleetbase-blog-data-expiration'), 'with an expiry stamp');
+ });
+
+ test('a response that is not a list is treated as no posts', async function (assert) {
+ this.getResponse = { error: 'unexpected' };
+ const component = await this.build();
+
+ assert.deepEqual(component.posts, [], 'nothing is rendered rather than a broken list');
+ });
+
+ test('a failed request leaves the blog empty without throwing', async function (assert) {
+ this.getRejectsWith = new Error('blog feed unavailable');
+ const component = await this.build();
+
+ assert.deepEqual(component.posts, []);
+ });
+
+ test('formattedPosts renders each publish date defensively', async function (assert) {
+ this.getResponse = [{ title: 'Dated', pubDate: '2026-01-15T00:00:00Z' }, { title: 'Undated' }, { title: 'Nonsense date', pubDate: 'not a date at all' }];
+ const component = await this.build();
+
+ const formatted = component.formattedPosts;
+ assert.strictEqual(formatted.length, 3);
+ assert.strictEqual(formatted[0].formattedDate, 'Jan 15, 2026', 'a real date is formatted');
+ assert.strictEqual(formatted[1].formattedDate, '', 'a missing date renders as empty');
+ assert.strictEqual(formatted[2].formattedDate, 'not a date at all', 'an unparseable date is passed through unchanged');
+ assert.strictEqual(formatted[0].title, 'Dated', 'the rest of the post is preserved');
+ });
+});
diff --git a/console/tests/integration/components/github-card-test.js b/console/tests/integration/components/github-card-test.js
index 4e3f7d59..ac978a7c 100644
--- a/console/tests/integration/components/github-card-test.js
+++ b/console/tests/integration/components/github-card-test.js
@@ -166,3 +166,54 @@ module('Integration | Component | github-card | fetching', function (hooks) {
assert.strictEqual(component.releaseUrl, 'https://github.com/fleetbase/fleetbase/releases', 'a blank tag name leaves the plain releases URL');
});
});
+
+/**
+ * Both tasks guard against writing tracked state after teardown. Driving that means
+ * holding the request open, tearing the component down, and only then resolving it.
+ */
+module('Integration | Component | github-card | teardown', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ _resetStorages();
+ window.localStorage.clear();
+
+ this.fetchModule = window.require('fetch');
+ this.originalFetch = this.fetchModule.default;
+ });
+
+ hooks.afterEach(function () {
+ this.fetchModule.default = this.originalFetch;
+ _resetStorages();
+ window.localStorage.clear();
+ });
+
+ test('a response arriving after teardown is ignored', async function (assert) {
+ const captured = captureComponent(this.owner, 'github-card', GithubCardComponent);
+ const pending = [];
+
+ this.fetchModule.default = () =>
+ new Promise((resolve) => {
+ pending.push(resolve);
+ });
+
+ // Park both requests so the component builds but neither task can finish. render()
+ // waits on them, so do not await it until the responses are released.
+ const rendering = render(hbs`<GithubCard />`);
+ while (!captured.instance) {
+ await new Promise((resolve) => setTimeout(resolve, 0));
+ }
+
+ const component = captured.instance;
+ // Flag the component as tearing down. Actually calling clearRender() cannot work
+ // here: it waits for settled, which the parked tasks would block forever.
+ Object.defineProperty(component, 'isDestroying', { configurable: true, value: true });
+
+ pending.forEach((resolve) => resolve({ ok: true, json: () => Promise.resolve({ full_name: 'late/response' }) }));
+ await rendering;
+
+ assert.strictEqual(pending.length, 2, 'both requests were in flight');
+ assert.notStrictEqual(component.data?.full_name, 'late/response', 'the late repository response is dropped');
+ assert.deepEqual(component.tags, [], 'and the late tags response is dropped too');
+ });
+});
diff --git a/console/tests/integration/components/impersonator-tray-test.js b/console/tests/integration/components/impersonator-tray-test.js
index 6b26576b..8aebbed1 100644
--- a/console/tests/integration/components/impersonator-tray-test.js
+++ b/console/tests/integration/components/impersonator-tray-test.js
@@ -3,6 +3,9 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
import { render } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
import Service from '@ember/service';
+import { cancel } from '@ember/runloop';
+import ImpersonatorTrayComponent from '@fleetbase/console/components/impersonator-tray';
+import { captureComponent } from '@fleetbase/console/tests/helpers/capture-component';
function registerSession(owner, authenticated) {
class SessionStub extends Service {
@@ -38,3 +41,109 @@ module('Integration | Component | impersonator-tray', function (hooks) {
assert.dom('#view-header-actions .locale-selector-tray').exists('the tray renders into the header');
});
});
+
+/**
+ * restoreSession ends the impersonation session and then reloads the window on a timer.
+ * That timer has to be cancelled here or it fires against the test runner.
+ */
+module('Integration | Component | impersonator-tray | restoreSession', function (hooks) {
+ setupRenderingTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.deleted = [];
+ this.deleteRejectsWith = null;
+ const context = this;
+
+ class FetchStub extends Service {
+ async delete(path) {
+ context.deleted.push(path);
+
+ if (context.deleteRejectsWith) {
+ throw context.deleteRejectsWith;
+ }
+
+ return { token: 'restored-token' };
+ }
+ }
+ class SessionStub extends Service {
+ data = { authenticated: { impersonator: '[email protected]' } };
+ authenticated = [];
+ manuallyAuthenticate(token) {
+ this.authenticated.push(token);
+ }
+ }
+ class NotificationsStub extends Service {
+ infos = [];
+ serverErrors = [];
+ info(message) {
+ this.infos.push(message);
+ }
+ serverError(error) {
+ this.serverErrors.push(error);
+ }
+ }
+
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:session', SessionStub);
+ this.owner.register('service:notifications', NotificationsStub);
+
+ const captured = captureComponent(this.owner, 'impersonator-tray', ImpersonatorTrayComponent);
+ this.build = async () => {
+ // The tray wormholes its button into the app shell's header actions.
+ await render(hbs`
+ <div id="view-header-actions"></div>
+ <ImpersonatorTray />
+ `);
+ const component = captured.instance;
+
+ this.transitions = [];
+ Object.defineProperty(component.router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => {
+ this.transitions.push(routeName);
+ return Promise.resolve(routeName);
+ },
+ });
+
+ return component;
+ };
+ });
+
+ test('isImpersonator reflects whether the session carries an impersonator', async function (assert) {
+ const component = await this.build();
+ assert.true(component.isImpersonator);
+
+ component.session.data = { authenticated: {} };
+ assert.false(component.isImpersonator, 'no impersonator means the tray stays hidden');
+
+ component.session.data = {};
+ assert.false(component.isImpersonator, 'an unauthenticated session is handled too');
+ });
+
+ test('restoreSession ends the impersonation and reauthenticates as the real user', async function (assert) {
+ const component = await this.build();
+
+ const timer = await component.restoreSession();
+ // The handler schedules a window.location.reload(); cancel it before it can fire
+ // against the test runner.
+ cancel(timer);
+
+ assert.deepEqual(this.deleted, ['auth/impersonate'], 'the impersonation is ended server-side');
+ assert.deepEqual(this.transitions, ['console'], 'and the user is returned to the console');
+ assert.deepEqual(component.session.authenticated, ['restored-token'], 'with their own token');
+ assert.deepEqual(this.owner.lookup('service:notifications').infos, ['Ending impersonation session.']);
+ assert.ok(timer, 'a reload was scheduled');
+ });
+
+ test('a failed restore is reported and nothing is reloaded', async function (assert) {
+ const failure = new Error('impersonation session already ended');
+ this.deleteRejectsWith = failure;
+ const component = await this.build();
+
+ const timer = await component.restoreSession();
+
+ assert.strictEqual(timer, undefined, 'no reload is scheduled on failure');
+ assert.deepEqual(this.owner.lookup('service:notifications').serverErrors, [failure]);
+ assert.deepEqual(this.transitions, [], 'the user stays where they are');
+ });
+});
diff --git a/console/tests/integration/components/two-fa-settings-test.js b/console/tests/integration/components/two-fa-settings-test.js
index 665bf25b..8a77772d 100644
--- a/console/tests/integration/components/two-fa-settings-test.js
+++ b/console/tests/integration/components/two-fa-settings-test.js
@@ -191,3 +191,22 @@ module('Integration | Component | two-fa-settings | actions', function (hooks) {
]);
});
});
+
+module('Integration | Component | two-fa-settings | no methods', function (hooks) {
+ setupRenderingTest(hooks);
+
+ test('enabling 2FA with no method list leaves the selection untouched', async function (assert) {
+ this.set('settings', { enabled: false });
+ const captured = captureComponent(this.owner, 'two-fa-settings', TwoFaSettingsComponent);
+
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} />`);
+ const component = captured.instance;
+
+ assert.strictEqual(component.selectedTwoFaMethod, 'email', 'the constructor defaulted it');
+
+ component.onTwoFaToggled(true);
+
+ assert.true(component.isTwoFaEnabled);
+ assert.strictEqual(component.selectedTwoFaMethod, 'email', 'with nothing to recommend, the default stands');
+ });
+});