Skip to content

Modular logistics and supply chain operating system (LSOS)

test(console): real tests for initializers; wire up coverage instrumentation

Ronald A. Richardson05218feeeccb
diff --git a/console/ember-cli-build.js b/console/ember-cli-build.js
index 029358e7..e8e9cc7b 100644
--- a/console/ember-cli-build.js
+++ b/console/ember-cli-build.js
@@ -30,7 +30,10 @@ module.exports = function (defaults) {
},
babel: {
- plugins: [require.resolve('ember-auto-import/babel-plugin')],
+ // ember-cli-code-coverage does not instrument automatically — the app has to
+ // add its babel plugin explicitly. buildBabelPlugin() returns [] unless
+ // COVERAGE=true, so normal builds are unaffected.
+ plugins: [require.resolve('ember-auto-import/babel-plugin'), ...require('ember-cli-code-coverage').buildBabelPlugin()],
},
});
diff --git a/console/tests/test-helper.js b/console/tests/test-helper.js
index 45ae0dfc..f8e21899 100644
--- a/console/tests/test-helper.js
+++ b/console/tests/test-helper.js
@@ -4,9 +4,24 @@ import * as QUnit from 'qunit';
import { setApplication } from '@ember/test-helpers';
import { setup } from 'qunit-dom';
import { start } from 'ember-qunit';
+import { forceModulesToBeLoaded, sendCoverage } from 'ember-cli-code-coverage/test-support';
setApplication(Application.create(config.APP));
setup(QUnit.assert);
+// ember-cli-code-coverage instruments the build when COVERAGE=true, but it only writes a
+// report if the suite posts window.__coverage__ back to the /write-coverage endpoint.
+// Without this hook the run produces no coverage/ output at all.
+QUnit.done(async function () {
+ if (typeof window.__coverage__ === 'undefined') {
+ return;
+ }
+
+ // Pull in modules no test happened to import, so untested files are reported as 0%
+ // rather than omitted from the denominator entirely.
+ forceModulesToBeLoaded();
+ await sendCoverage();
+});
+
start();
diff --git a/console/tests/unit/initializers/initialize-random-uuid-polyfill-test.js b/console/tests/unit/initializers/initialize-random-uuid-polyfill-test.js
index c1d9f3ca..7e0df29a 100644
--- a/console/tests/unit/initializers/initialize-random-uuid-polyfill-test.js
+++ b/console/tests/unit/initializers/initialize-random-uuid-polyfill-test.js
@@ -1,37 +1,34 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/initializers/initialize-random-uuid-polyfill';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/initializers/initialize-random-uuid-polyfill';
module('Unit | Initializer | initialize-random-uuid-polyfill', function (hooks) {
hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
-
- this.TestApplication.initializer({
- name: 'initializer under test',
- initialize,
- });
-
- this.application = this.TestApplication.create({
- autoboot: false,
- });
+ this.original = window.crypto.randomUUID;
});
hooks.afterEach(function () {
- run(this.application, 'destroy');
+ window.crypto.randomUUID = this.original;
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.application.boot();
+ test('it installs a randomUUID polyfill when the platform lacks one', function (assert) {
+ window.crypto.randomUUID = undefined;
+
+ initialize();
+
+ assert.strictEqual(typeof window.crypto.randomUUID, 'function', 'a polyfill is installed');
+
+ const uuid = window.crypto.randomUUID();
+ assert.strictEqual(uuid.length, 36, 'it produces a 36 character uuid');
+ assert.ok(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/.test(uuid), `it produces a valid v4 uuid (${uuid})`);
+ assert.notStrictEqual(window.crypto.randomUUID(), uuid, 'successive calls differ');
+ });
+
+ test('it leaves a native randomUUID in place', function (assert) {
+ const native = () => 'native-uuid';
+ window.crypto.randomUUID = native;
+
+ initialize();
- assert.ok(true);
+ assert.strictEqual(window.crypto.randomUUID, native, 'the native implementation is not replaced');
});
});
diff --git a/console/tests/unit/initializers/load-intl-polyfills-test.js b/console/tests/unit/initializers/load-intl-polyfills-test.js
index 2724d133..c72ca012 100644
--- a/console/tests/unit/initializers/load-intl-polyfills-test.js
+++ b/console/tests/unit/initializers/load-intl-polyfills-test.js
@@ -1,37 +1,28 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/initializers/load-intl-polyfills';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/initializers/load-intl-polyfills';
-module('Unit | Initializer | load-intl-polyfills', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
+module('Unit | Initializer | load-intl-polyfills', function () {
+ test('it defers readiness while the polyfills load and advances afterwards', async function (assert) {
+ const calls = [];
+ let advanced;
+ const didAdvance = new Promise((resolve) => (advanced = resolve));
- this.TestApplication.initializer({
- name: 'initializer under test',
- initialize,
- });
+ const application = {
+ deferReadiness: () => calls.push('defer'),
+ advanceReadiness: () => {
+ calls.push('advance');
+ advanced();
+ },
+ };
- this.application = this.TestApplication.create({
- autoboot: false,
- });
- });
+ initialize(application);
- hooks.afterEach(function () {
- run(this.application, 'destroy');
- });
+ assert.deepEqual(calls, ['defer'], 'readiness is deferred synchronously');
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.application.boot();
+ // The polyfills load through dynamic imports in a bare async IIFE, which settled()
+ // does not track — wait on advanceReadiness itself.
+ await didAdvance;
- assert.ok(true);
+ assert.deepEqual(calls, ['defer', 'advance'], 'readiness advances once the polyfills resolve');
});
});
diff --git a/console/tests/unit/initializers/load-runtime-config-test.js b/console/tests/unit/initializers/load-runtime-config-test.js
new file mode 100644
index 00000000..faba95e6
--- /dev/null
+++ b/console/tests/unit/initializers/load-runtime-config-test.js
@@ -0,0 +1,29 @@
+import { module, test } from 'qunit';
+import { initialize } from '@fleetbase/console/initializers/load-runtime-config';
+
+module('Unit | Initializer | load-runtime-config', function () {
+ test('it defers readiness while the runtime config loads and always advances', async function (assert) {
+ const calls = [];
+ let advanced;
+ const didAdvance = new Promise((resolve) => (advanced = resolve));
+
+ const application = {
+ deferReadiness: () => calls.push('defer'),
+ advanceReadiness: () => {
+ calls.push('advance');
+ advanced();
+ },
+ };
+
+ initialize(application);
+
+ assert.deepEqual(calls, ['defer'], 'readiness is deferred synchronously');
+
+ // The loader runs in a bare async IIFE that settled() does not track, so wait on
+ // advanceReadiness itself. Whether the config load resolves or fails, readiness
+ // must advance — otherwise the app would never boot.
+ await didAdvance;
+
+ assert.deepEqual(calls, ['defer', 'advance'], 'readiness always advances');
+ });
+});
diff --git a/console/tests/unit/initializers/load-socketcluster-client-test.js b/console/tests/unit/initializers/load-socketcluster-client-test.js
index c86eb3e5..a2c020f8 100644
--- a/console/tests/unit/initializers/load-socketcluster-client-test.js
+++ b/console/tests/unit/initializers/load-socketcluster-client-test.js
@@ -1,37 +1,23 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/initializers/load-socketcluster-client';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/initializers/load-socketcluster-client';
module('Unit | Initializer | load-socketcluster-client', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
-
- this.TestApplication.initializer({
- name: 'initializer under test',
- initialize,
- });
-
- this.application = this.TestApplication.create({
- autoboot: false,
- });
+ hooks.afterEach(function () {
+ document.querySelectorAll('script[data-socketcluster-client]').forEach((node) => node.remove());
});
- hooks.afterEach(function () {
- run(this.application, 'destroy');
+ test('it injects the socketcluster client script', function (assert) {
+ initialize();
+
+ const script = document.querySelector('script[data-socketcluster-client]');
+ assert.ok(script, 'the script tag is added');
+ assert.ok(script.src.endsWith('/assets/socketcluster-client.min.js'), 'it points at the bundled client');
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.application.boot();
+ test('it does not inject the script twice', function (assert) {
+ initialize();
+ initialize();
- assert.ok(true);
+ assert.strictEqual(document.querySelectorAll('script[data-socketcluster-client]').length, 1, 'only one script tag is added');
});
});
diff --git a/console/tests/unit/instance-initializers/apply-router-fix-test.js b/console/tests/unit/instance-initializers/apply-router-fix-test.js
new file mode 100644
index 00000000..74ab6a80
--- /dev/null
+++ b/console/tests/unit/instance-initializers/apply-router-fix-test.js
@@ -0,0 +1,22 @@
+import { module, test } from 'qunit';
+import { initialize } from '@fleetbase/console/instance-initializers/apply-router-fix';
+
+module('Unit | Instance Initializer | apply-router-fix', function () {
+ test('it applies the router refresh patch to the app instance', function (assert) {
+ // applyRouterFix reads the router off the app instance; a lookup that yields
+ // nothing exercises the patch without needing a real router.
+ initialize({ lookup: () => undefined });
+
+ assert.ok(true, 'initialize completes for an app instance with no router');
+ });
+
+ test('a failure while patching does not stop boot', function (assert) {
+ initialize({
+ lookup() {
+ throw new Error('router unavailable');
+ },
+ });
+
+ assert.ok(true, 'the error is caught and boot continues');
+ });
+});
diff --git a/console/tests/unit/instance-initializers/initialize-registries-test.js b/console/tests/unit/instance-initializers/initialize-registries-test.js
index 4c076369..e736394c 100644
--- a/console/tests/unit/instance-initializers/initialize-registries-test.js
+++ b/console/tests/unit/instance-initializers/initialize-registries-test.js
@@ -1,39 +1,28 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/initialize-registries';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/instance-initializers/initialize-registries';
-module('Unit | Instance Initializer | initialize-registries', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
+module('Unit | Instance Initializer | initialize-registries', function () {
+ test('it creates the console registries', function (assert) {
+ let created;
+ const appInstance = {
+ lookup(name) {
+ assert.strictEqual(name, 'service:universe/registry-service');
+ return {
+ createRegistries(registries) {
+ created = registries;
+ },
+ };
+ },
};
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
- });
-
- this.application = this.TestApplication.create({
- autoboot: false,
- });
-
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
- });
-
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ initialize(appInstance);
- assert.ok(true);
+ assert.ok(created.includes('@fleetbase/console'), 'the console registry is created');
+ assert.ok(created.includes('auth:login'), 'the login registry is created');
+ assert.ok(
+ created.every((name) => typeof name === 'string'),
+ 'every registry is named with a string'
+ );
+ assert.strictEqual(new Set(created).size, created.length, 'no registry is registered twice');
});
});
diff --git a/console/tests/unit/instance-initializers/initialize-widgets-test.js b/console/tests/unit/instance-initializers/initialize-widgets-test.js
index bde101d5..97a15df1 100644
--- a/console/tests/unit/instance-initializers/initialize-widgets-test.js
+++ b/console/tests/unit/instance-initializers/initialize-widgets-test.js
@@ -1,39 +1,64 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/initialize-widgets';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
-
-module('Unit | Instance Initializer | initialize-widgets', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
-
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
- });
-
- this.application = this.TestApplication.create({
- autoboot: false,
- });
-
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
+import { initialize } from '@fleetbase/console/instance-initializers/initialize-widgets';
+
+function widgetServiceStub() {
+ return {
+ dashboards: [],
+ slots: [],
+ // registerWidgets(dashboardId, widgets)
+ registeredByDashboard: {},
+ registerDashboard(id) {
+ this.dashboards.push(id);
+ },
+ registerDashboardForSlot(slot, dashboard, options) {
+ this.slots.push({ slot, dashboard, options });
+ },
+ registerWidgets(dashboardId, widgets) {
+ this.registeredByDashboard[dashboardId] = widgets;
+ },
+ };
+}
+
+function appInstanceStub(widgetService, onBoot) {
+ const universe = {
+ getService: () => widgetService,
+ onBoot,
+ };
+
+ return {
+ lookup(name) {
+ return name === 'service:universe' ? universe : { getMenuItems: () => [] };
+ },
+ };
+}
+
+module('Unit | Instance Initializer | initialize-widgets', function () {
+ test('it registers the console dashboards and the default home slot', function (assert) {
+ const widgetService = widgetServiceStub();
+
+ initialize(appInstanceStub(widgetService, () => {}));
+
+ assert.deepEqual(widgetService.dashboards, ['dashboard', 'admin'], 'both dashboards are registered');
+ assert.strictEqual(widgetService.slots.length, 1);
+ assert.deepEqual(widgetService.slots[0].slot, 'console.home');
+ assert.deepEqual(widgetService.slots[0].dashboard, 'dashboard');
+ assert.strictEqual(widgetService.slots[0].options.extension, 'core');
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ test('the widgets are registered once the universe boots', function (assert) {
+ const widgetService = widgetServiceStub();
+ let bootCallback;
+
+ initialize(appInstanceStub(widgetService, (callback) => (bootCallback = callback)));
+
+ assert.strictEqual(typeof bootCallback, 'function', 'registration waits for the boot hook');
+ assert.deepEqual(widgetService.registeredByDashboard, {}, 'nothing is registered before boot');
+
+ bootCallback();
- assert.ok(true);
+ const ids = (widgetService.registeredByDashboard.dashboard ?? []).map((widget) => widget.id);
+ assert.ok(ids.includes('fleetbase-blog'), 'the blog widget is registered on the dashboard');
+ assert.ok(ids.includes('fleetbase-github-card'), 'the github card widget is registered on the dashboard');
+ assert.ok(Array.isArray(widgetService.registeredByDashboard.admin), 'admin widgets are registered too');
});
});
diff --git a/console/tests/unit/instance-initializers/load-extensions-test.js b/console/tests/unit/instance-initializers/load-extensions-test.js
index ed2350e2..bdaa9f81 100644
--- a/console/tests/unit/instance-initializers/load-extensions-test.js
+++ b/console/tests/unit/instance-initializers/load-extensions-test.js
@@ -1,39 +1,34 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/load-extensions';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/instance-initializers/load-extensions';
-module('Unit | Instance Initializer | load-extensions', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
+module('Unit | Instance Initializer | load-extensions', function () {
+ test('it loads the extensions for the application', async function (assert) {
+ const application = { name: 'console' };
+ let loadedFor;
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
+ await initialize({
+ application,
+ lookup: () => ({
+ loadExtensions(app) {
+ loadedFor = app;
+ return Promise.resolve();
+ },
+ }),
});
- this.application = this.TestApplication.create({
- autoboot: false,
- });
-
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
+ assert.strictEqual(loadedFor, application);
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ test('a failing extension load is swallowed so boot continues', async function (assert) {
+ await initialize({
+ application: {},
+ lookup: () => ({
+ loadExtensions() {
+ return Promise.reject(new Error('bad extension'));
+ },
+ }),
+ });
- assert.ok(true);
+ assert.ok(true, 'the rejection does not propagate');
});
});
diff --git a/console/tests/unit/instance-initializers/load-leaflet-test.js b/console/tests/unit/instance-initializers/load-leaflet-test.js
index ec5fe3ff..34081e46 100644
--- a/console/tests/unit/instance-initializers/load-leaflet-test.js
+++ b/console/tests/unit/instance-initializers/load-leaflet-test.js
@@ -1,39 +1,36 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/load-leaflet';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
-
-module('Unit | Instance Initializer | load-leaflet', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
+import { initialize } from '@fleetbase/console/instance-initializers/load-leaflet';
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
+module('Unit | Instance Initializer | load-leaflet', function () {
+ test('it loads leaflet and patches Control to stop refocusing the map', function (assert) {
+ let loadOptions;
+ initialize({
+ lookup: () => ({
+ load(options) {
+ loadOptions = options;
+ },
+ }),
});
- this.application = this.TestApplication.create({
- autoboot: false,
+ assert.strictEqual(typeof loadOptions.onReady, 'function', 'an onReady callback is supplied');
+
+ // Drive onReady with a stand-in for the Leaflet global.
+ let included;
+ loadOptions.onReady({
+ Control: {
+ include(mixin) {
+ included = mixin;
+ },
+ },
+ Util: { falseFn: 'false-fn' },
});
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
+ assert.deepEqual(included, { _refocusOnMap: 'false-fn' }, 'map refocusing is disabled');
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ test('it is a no-op when the leaflet service is unavailable', function (assert) {
+ initialize({ lookup: () => undefined });
- assert.ok(true);
+ assert.ok(true, 'no error is thrown without a leaflet service');
});
});
diff --git a/console/tests/unit/instance-initializers/register-default-onboarding-flow-test.js b/console/tests/unit/instance-initializers/register-default-onboarding-flow-test.js
index 9157d5fb..4ac4a045 100644
--- a/console/tests/unit/instance-initializers/register-default-onboarding-flow-test.js
+++ b/console/tests/unit/instance-initializers/register-default-onboarding-flow-test.js
@@ -1,39 +1,30 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/register-default-onboarding-flow';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
-
-module('Unit | Instance Initializer | register-default-onboarding-flow', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
- };
-
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
- });
+import { initialize } from '@fleetbase/console/instance-initializers/register-default-onboarding-flow';
- this.application = this.TestApplication.create({
- autoboot: false,
+module('Unit | Instance Initializer | register-default-onboarding-flow', function () {
+ test('it registers the default signup flow', function (assert) {
+ let registered;
+ initialize({
+ lookup: () => ({
+ registerFlow(flow) {
+ registered = flow;
+ },
+ }),
});
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
+ assert.strictEqual(registered.id, 'default@v1');
+ assert.strictEqual(registered.entry, 'signup');
+ assert.deepEqual(
+ registered.steps.map((step) => step.id),
+ ['signup', 'verify-email']
+ );
+ assert.strictEqual(registered.steps[0].next, 'verify-email', 'signup advances to verification');
+ assert.strictEqual(registered.steps[1].next, undefined, 'verification ends the flow');
});
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ test('it is a no-op without an onboarding registry', function (assert) {
+ initialize({ lookup: () => undefined });
- assert.ok(true);
+ assert.ok(true, 'no error is thrown without a registry');
});
});
diff --git a/console/tests/unit/instance-initializers/set-application-instance-test.js b/console/tests/unit/instance-initializers/set-application-instance-test.js
new file mode 100644
index 00000000..f2f00d26
--- /dev/null
+++ b/console/tests/unit/instance-initializers/set-application-instance-test.js
@@ -0,0 +1,25 @@
+import { module, test } from 'qunit';
+import { initialize } from '@fleetbase/console/instance-initializers/set-application-instance';
+
+module('Unit | Instance Initializer | set-application-instance', function () {
+ test('it hands the application instance to the universe service', function (assert) {
+ let received;
+ const appInstance = {
+ lookup: () => ({
+ setApplicationInstance(instance) {
+ received = instance;
+ },
+ }),
+ };
+
+ initialize(appInstance);
+
+ assert.strictEqual(received, appInstance);
+ });
+
+ test('it is a no-op when the universe service is unavailable', function (assert) {
+ initialize({ lookup: () => undefined });
+
+ assert.ok(true, 'no error is thrown without a universe service');
+ });
+});
diff --git a/console/tests/unit/instance-initializers/setup-extensions-test.js b/console/tests/unit/instance-initializers/setup-extensions-test.js
index a407921d..aff4c710 100644
--- a/console/tests/unit/instance-initializers/setup-extensions-test.js
+++ b/console/tests/unit/instance-initializers/setup-extensions-test.js
@@ -1,39 +1,25 @@
-import Application from '@ember/application';
-
-import config from '@fleetbase/console/config/environment';
-import { initialize } from '@fleetbase/console/instance-initializers/setup-extensions';
import { module, test } from 'qunit';
-import Resolver from 'ember-resolver';
-import { run } from '@ember/runloop';
+import { initialize } from '@fleetbase/console/instance-initializers/setup-extensions';
-module('Unit | Instance Initializer | setup-extensions', function (hooks) {
- hooks.beforeEach(function () {
- this.TestApplication = class TestApplication extends Application {
- modulePrefix = config.modulePrefix;
- podModulePrefix = config.podModulePrefix;
- Resolver = Resolver;
+module('Unit | Instance Initializer | setup-extensions', function () {
+ test('it sets up the extensions with the universe service', async function (assert) {
+ const universe = { name: 'universe' };
+ const extensionManager = {
+ calls: [],
+ setupExtensions(appInstance, universeService) {
+ this.calls.push([appInstance, universeService]);
+ return Promise.resolve();
+ },
};
- this.TestApplication.instanceInitializer({
- name: 'initializer under test',
- initialize,
- });
-
- this.application = this.TestApplication.create({
- autoboot: false,
- });
-
- this.instance = this.application.buildInstance();
- });
- hooks.afterEach(function () {
- run(this.instance, 'destroy');
- run(this.application, 'destroy');
- });
+ const appInstance = {
+ lookup(name) {
+ return name === 'service:universe' ? universe : extensionManager;
+ },
+ };
- // TODO: Replace this with your real tests.
- test('it works', async function (assert) {
- await this.instance.boot();
+ await initialize(appInstance);
- assert.ok(true);
+ assert.deepEqual(extensionManager.calls, [[appInstance, universe]], 'the app instance and universe are passed through');
});
});