Skip to content

Modular logistics and supply chain operating system (LSOS)

test(console): cover the organization overview getters' fallback arms

Ronald A. Richardsonf12c030e7e9d
diff --git a/console/tests/unit/controllers/console/admin/organizations/details/index-test.js b/console/tests/unit/controllers/console/admin/organizations/details/index-test.js
index b0c6e29a..e7391962 100644
--- a/console/tests/unit/controllers/console/admin/organizations/details/index-test.js
+++ b/console/tests/unit/controllers/console/admin/organizations/details/index-test.js
@@ -58,3 +58,81 @@ module('Unit | Controller | console/admin/organizations/details/index', function
assert.strictEqual(controller.resolveBelongsTo({ isPending: true }), null);
});
});
+
+/**
+ * Every getter on this controller is a chain of optional access and fallbacks. The tests
+ * above cover the populated and owner-less shapes; these drive the arms neither reaches —
+ * no model at all, the alternate fallback in each `||`/`??`, and the opposite side of every
+ * ternary the KPI cards use to pick an icon and accent.
+ */
+module('Unit | Controller | console/admin/organizations/details/index | fallbacks', function (hooks) {
+ setupTest(hooks);
+
+ hooks.beforeEach(function () {
+ this.controller = this.owner.lookup('controller:console/admin/organizations/details/index');
+ });
+
+ test('every getter is safe before a model has loaded', function (assert) {
+ assert.strictEqual(this.controller.organization, undefined);
+ assert.strictEqual(this.controller.owner, null);
+ assert.strictEqual(this.controller.ownerName, undefined);
+ assert.strictEqual(this.controller.ownerEmail, undefined);
+ assert.strictEqual(this.controller.ownerPhone, undefined);
+ assert.strictEqual(this.controller.ownerState, 'Missing');
+ assert.strictEqual(this.controller.onboardingState, 'Incomplete');
+ assert.strictEqual(this.controller.statusLabel, 'active', 'an unknown organization is presented as active');
+ });
+
+ test('statusLabel prefers a supplied label over the raw status', function (assert) {
+ this.controller.model = { statusLabel: 'Suspended by billing', status: 'suspended' };
+
+ assert.strictEqual(this.controller.statusLabel, 'Suspended by billing');
+ });
+
+ test('the metrics fall back for an organization with no users, owner or status', function (assert) {
+ this.controller.model = { owner: null };
+
+ const [users, owner, onboarding, status] = this.controller.metrics;
+
+ assert.strictEqual(users.value, 0, 'an absent user count reads as zero');
+ assert.strictEqual(owner.value, 'Missing');
+ assert.strictEqual(owner.caption, 'Needs assignment', 'with no owner email the card says what to do');
+ assert.strictEqual(owner.icon, 'user-slash');
+ assert.true(owner.accentClass.endsWith('amber'), 'a missing owner is flagged amber');
+ assert.strictEqual(onboarding.caption, 'Needs review');
+ assert.strictEqual(onboarding.icon, 'triangle-exclamation');
+ assert.true(onboarding.accentClass.endsWith('amber'));
+ assert.strictEqual(status.value, 'active');
+ assert.strictEqual(status.icon, 'shield-check', 'an active organization gets the reassuring icon');
+ assert.true(status.accentClass.endsWith('green'));
+ });
+
+ test('the metrics reflect a fully set up, non-active organization', function (assert) {
+ this.controller.model = {
+ status: 'suspended',
+ users_count: 12,
+ onboarding_completed: true,
+ owner: { email: '[email protected]' },
+ };
+
+ const [users, owner, onboarding, status] = this.controller.metrics;
+
+ assert.strictEqual(users.value, 12);
+ assert.strictEqual(owner.caption, '[email protected]', 'the owner email is used as the caption');
+ assert.strictEqual(owner.icon, 'user-check');
+ assert.true(owner.accentClass.endsWith('green'));
+ assert.strictEqual(onboarding.caption, 'Ready for operations');
+ assert.strictEqual(onboarding.icon, 'circle-check');
+ assert.true(onboarding.accentClass.endsWith('green'));
+ assert.strictEqual(status.icon, 'circle-exclamation', 'a suspended organization is flagged');
+ assert.true(status.accentClass.endsWith('rose'));
+ });
+
+ test('resolveBelongsTo withholds every unresolved proxy shape and passes a record through', function (assert) {
+ const record = { id: 'user_1' };
+
+ assert.strictEqual(this.controller.resolveBelongsTo({ isFulfilled: false }), null, 'an unfulfilled proxy');
+ assert.strictEqual(this.controller.resolveBelongsTo({ then: () => {} }), null, 'a bare thenable');
+ assert.strictEqual(this.controller.resolveBelongsTo(record), record, 'a plain record is used as-is');
+ });
+});