Skip to content

Modular logistics and supply chain operating system (LSOS)

fix(console): stop the component suite aborting; convert the component stubs

Ronald A. Richardson4520ce0477b3
diff --git a/console/app/components/dashboard/count.js b/console/app/components/dashboard/count.js
index 95b4c6d6..f1a542b8 100644
--- a/console/app/components/dashboard/count.js
+++ b/console/app/components/dashboard/count.js
@@ -30,19 +30,26 @@ export default class DashboardCountComponent extends Component {
constructor(owner, { options, title, value = null }) {
super(...arguments);
this.title = title;
- this.value = value;
- this.createRenderValueFromOptions(options);
+ this.createRenderValueFromOptions(options, value);
}
/**
* Creates the value to render using the options provided.
*
+ * The provided value is taken as a parameter rather than read back off the tracked
+ * `value` property: reading and then writing the same tracked property while the
+ * component is being constructed during a render trips Ember's "already been used
+ * previously in the same computation" assertion. Mirrors
+ * @fleetbase/ember-ui's widget/count component.
+ *
* @param {Object} [options={}]
+ * @param {String|Number} [defaultValue=null]
* @memberof WidgetKeyMetricsCountComponent
*/
- createRenderValueFromOptions(options = {}) {
+ createRenderValueFromOptions(options = {}, defaultValue = null) {
// Skip deriving a value from options when one was already provided.
- if (this.value !== null) {
+ if (defaultValue !== null) {
+ this.value = defaultValue;
return;
}
diff --git a/console/app/components/fleetbase-blog.js b/console/app/components/fleetbase-blog.js
index 43d703a4..70048b9a 100644
--- a/console/app/components/fleetbase-blog.js
+++ b/console/app/components/fleetbase-blog.js
@@ -53,6 +53,14 @@ export default class FleetbaseBlogComponent extends Component {
// Fetch new data
try {
const data = yield this.fetch.get('lookup/fleetbase-blog');
+
+ // The component can be torn down while this request is in flight; writing
+ // tracked state afterwards throws "Cannot create a new tag ... after it has
+ // been destroyed".
+ if (this.isDestroying || this.isDestroyed) {
+ return;
+ }
+
this.posts = isArray(data) ? data : [];
if (data) {
this.localCache.set('fleetbase-blog-data', data);
diff --git a/console/app/components/github-card.js b/console/app/components/github-card.js
index 0d3004ba..f6f97379 100644
--- a/console/app/components/github-card.js
+++ b/console/app/components/github-card.js
@@ -53,6 +53,13 @@ export default class GithubCardComponent extends Component {
} else {
// Fetch new data
const response = yield fetch('https://api.github.com/repos/fleetbase/fleetbase', { cache: 'default' });
+
+ // The component can be torn down mid-request; writing tracked state afterwards
+ // throws "Cannot create a new tag ... after it has been destroyed".
+ if (this.isDestroying || this.isDestroyed) {
+ return;
+ }
+
if (response.ok) {
this.data = yield response.json();
this.localCache.set('fleetbase-github-data', this.data);
@@ -73,6 +80,11 @@ export default class GithubCardComponent extends Component {
} else {
// Fetch new tags
const response = yield fetch('https://api.github.com/repos/fleetbase/fleetbase/tags', { cache: 'default' });
+
+ if (this.isDestroying || this.isDestroyed) {
+ return;
+ }
+
if (response.ok) {
this.tags = yield response.json();
this.localCache.set('fleetbase-github-tags', this.tags);
diff --git a/console/tests/integration/components/configure/2fa-test.js b/console/tests/integration/components/configure/2fa-test.js
index 02844a75..80bac6fa 100644
--- a/console/tests/integration/components/configure/2fa-test.js
+++ b/console/tests/integration/components/configure/2fa-test.js
@@ -6,21 +6,20 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | configure/2fa', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ test('it yields its block content', async function (assert) {
+ await render(hbs`
+ <Configure::2fa>
+ <span class="yielded">two factor settings</span>
+ </Configure::2fa>
+ `);
+
+ assert.dom('.yielded').exists('the block is yielded');
+ assert.dom(this.element).hasText('two factor settings');
+ });
+ test('it renders nothing without a block', async function (assert) {
await render(hbs`<Configure::2fa />`);
assert.dom(this.element).hasText('');
-
- // Template block usage:
- await render(hbs`
- <Configure::2fa>
- template block text
- </Configure::2fa>
- `);
-
- assert.dom(this.element).hasText('template block text');
});
});
diff --git a/console/tests/integration/components/configure/filesystem-test.js b/console/tests/integration/components/configure/filesystem-test.js
index 34c2287c..f8a20895 100644
--- a/console/tests/integration/components/configure/filesystem-test.js
+++ b/console/tests/integration/components/configure/filesystem-test.js
@@ -1,26 +1,67 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
module('Integration | Component | configure/filesystem', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.posted = [];
+ const posted = this.posted;
- await render(hbs`<Configure::Filesystem />`);
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve({ driver: 'local', disks: ['local', 's3', 'gcs'] });
+ }
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({ status: 'ok', message: 'Connection successful' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
- assert.dom(this.element).hasText('');
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
+
+ test('it renders the filesystem panel and wormholes its save button to the subheader', async function (assert) {
+ // The component wormholes its "Save Changes" button into an element that only
+ // exists in the app shell, so the destination must be present in the test DOM.
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Filesystem />
+ `);
+
+ assert.dom('.next-content-panel').exists('the panel renders');
+ assert.dom(this.element).containsText('Filesystem');
+ assert.dom('#next-view-section-subheader-actions').containsText('Save Changes', 'the save button is wormholed into the subheader');
+ });
- // Template block usage:
+ test('it loads the current driver from the settings endpoint', async function (assert) {
await render(hbs`
- <Configure::Filesystem>
- template block text
- </Configure::Filesystem>
- `);
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Filesystem />
+ `);
+
+ assert.dom(this.element).containsText('Driver', 'the driver input group renders');
+ assert.dom(this.element).doesNotContainText('S3 Bucket', 'S3 fields are hidden for the local driver');
+ });
+
+ test('it saves the configuration when the wormholed button is clicked', async function (assert) {
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Filesystem />
+ `);
+
+ await click('#next-view-section-subheader-actions button');
- assert.dom(this.element).hasText('template block text');
+ assert.strictEqual(this.posted.at(-1).path, 'settings/filesystem-config');
+ assert.strictEqual(this.posted.at(-1).payload.driver, 'local');
});
});
diff --git a/console/tests/integration/components/configure/mail-test.js b/console/tests/integration/components/configure/mail-test.js
index fd9f7829..f232c76a 100644
--- a/console/tests/integration/components/configure/mail-test.js
+++ b/console/tests/integration/components/configure/mail-test.js
@@ -1,26 +1,54 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
module('Integration | Component | configure/mail', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.posted = [];
+ const posted = this.posted;
- await render(hbs`<Configure::Mail />`);
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve({ mailer: 'smtp', from: { address: '[email protected]' } });
+ }
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({ status: 'ok' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
- assert.dom(this.element).hasText('');
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
+
+ test('it renders the mail panel and wormholes its save button to the subheader', async function (assert) {
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Mail />
+ `);
- // Template block usage:
+ assert.dom('.next-content-panel').exists('the panel renders');
+ assert.dom(this.element).containsText('Mail');
+ assert.dom('#next-view-section-subheader-actions').containsText('Save Changes', 'the save button is wormholed into the subheader');
+ });
+
+ test('it saves the mail configuration when the wormholed button is clicked', async function (assert) {
await render(hbs`
- <Configure::Mail>
- template block text
- </Configure::Mail>
- `);
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Mail />
+ `);
+
+ await click('#next-view-section-subheader-actions button');
- assert.dom(this.element).hasText('template block text');
+ assert.strictEqual(this.posted.at(-1).path, 'settings/mail-config');
});
});
diff --git a/console/tests/integration/components/configure/notification-channels-test.js b/console/tests/integration/components/configure/notification-channels-test.js
index d79cb8f1..492163c6 100644
--- a/console/tests/integration/components/configure/notification-channels-test.js
+++ b/console/tests/integration/components/configure/notification-channels-test.js
@@ -1,26 +1,56 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
module('Integration | Component | configure/notification-channels', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.posted = [];
+ const posted = this.posted;
- await render(hbs`<Configure::NotificationChannels />`);
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve({});
+ }
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({ status: 'ok' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
- assert.dom(this.element).hasText('');
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
- // Template block usage:
+ test('it renders the APN, Firebase and test panels', async function (assert) {
await render(hbs`
- <Configure::NotificationChannels>
- template block text
- </Configure::NotificationChannels>
- `);
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::NotificationChannels />
+ `);
+
+ assert.dom(this.element).containsText('APN');
+ assert.dom(this.element).containsText('Firebase');
+ assert.dom(this.element).containsText('Test Push Notification');
+ });
+
+ test('it wormholes its save button to the subheader and posts the config', async function (assert) {
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::NotificationChannels />
+ `);
+
+ assert.dom('#next-view-section-subheader-actions').containsText('Save Changes');
+
+ await click('#next-view-section-subheader-actions button');
- assert.dom(this.element).hasText('template block text');
+ assert.strictEqual(this.posted.at(-1).path, 'settings/notification-channels-config');
});
});
diff --git a/console/tests/integration/components/configure/queue-test.js b/console/tests/integration/components/configure/queue-test.js
index 66d70e07..47330b37 100644
--- a/console/tests/integration/components/configure/queue-test.js
+++ b/console/tests/integration/components/configure/queue-test.js
@@ -1,26 +1,54 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
module('Integration | Component | configure/queue', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.posted = [];
+ const posted = this.posted;
- await render(hbs`<Configure::Queue />`);
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve({ driver: 'redis' });
+ }
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({ status: 'ok' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
- assert.dom(this.element).hasText('');
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
+
+ test('it renders the queue panel and wormholes its save button to the subheader', async function (assert) {
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Queue />
+ `);
- // Template block usage:
+ assert.dom('.next-content-panel').exists('the panel renders');
+ assert.dom(this.element).containsText('Queue');
+ assert.dom('#next-view-section-subheader-actions').containsText('Save Changes', 'the save button is wormholed into the subheader');
+ });
+
+ test('it saves the queue configuration when the wormholed button is clicked', async function (assert) {
await render(hbs`
- <Configure::Queue>
- template block text
- </Configure::Queue>
- `);
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Queue />
+ `);
+
+ await click('#next-view-section-subheader-actions button');
- assert.dom(this.element).hasText('template block text');
+ assert.strictEqual(this.posted.at(-1).path, 'settings/queue-config');
});
});
diff --git a/console/tests/integration/components/configure/services-test.js b/console/tests/integration/components/configure/services-test.js
index 66987adb..3275efd1 100644
--- a/console/tests/integration/components/configure/services-test.js
+++ b/console/tests/integration/components/configure/services-test.js
@@ -86,7 +86,10 @@ module('Integration | Component | configure/services', function (hooks) {
});
test('it renders sms provider configuration and sends test payload', async function (assert) {
- await render(hbs`<Configure::Services />`);
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Services />
+ `);
await waitFor('[data-test-sms-default-provider]');
assert.dom('[data-test-sms-default-provider]').hasValue('twilio');
@@ -117,7 +120,10 @@ module('Integration | Component | configure/services', function (hooks) {
});
test('it configures custom http get query params', async function (assert) {
- await render(hbs`<Configure::Services />`);
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Services />
+ `);
await waitFor('[data-test-sms-default-provider]');
assert.dom(this.element).doesNotIncludeText('Vonage Base URL');
@@ -160,7 +166,10 @@ module('Integration | Component | configure/services', function (hooks) {
});
test('it configures smpp advanced submit parameters', async function (assert) {
- await render(hbs`<Configure::Services />`);
+ await render(hbs`
+ <div id="next-view-section-subheader-actions"></div>
+ <Configure::Services />
+ `);
await waitFor('[data-test-sms-default-provider]');
await select('[data-test-sms-default-provider]', 'smpp');
diff --git a/console/tests/integration/components/configure/socket-test.js b/console/tests/integration/components/configure/socket-test.js
index cc258ce4..33f8cda1 100644
--- a/console/tests/integration/components/configure/socket-test.js
+++ b/console/tests/integration/components/configure/socket-test.js
@@ -2,25 +2,64 @@ 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';
module('Integration | Component | configure/socket', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.posted = [];
+ const posted = this.posted;
+ // The component opens `for await` loops over socket.instance().listener(...),
+ // socket.subscribe('test').listener(...) and the channel itself. Hand back
+ // iterators that complete immediately so every loop exits instead of parking
+ // and touching the component after teardown.
+ const exhausted = () => ({
+ [Symbol.asyncIterator]() {
+ return { next: () => Promise.resolve({ done: true, value: undefined }) };
+ },
+ });
+ const channel = () => Object.assign(exhausted(), { listener: exhausted, close() {} });
+
+ class SocketStub extends Service {
+ instance() {
+ return {
+ listener: exhausted,
+ subscribe: channel,
+ };
+ }
+ }
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve({});
+ }
+ post(path, payload) {
+ posted.push({ path, payload });
+ return Promise.resolve({ status: 'ok', message: 'connected' });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
+
+ this.owner.register('service:socket', SocketStub);
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
+
+ test('it renders the socket connection panel', async function (assert) {
await render(hbs`<Configure::Socket />`);
- assert.dom(this.element).hasText('');
+ assert.dom('.next-content-panel').exists('the panel renders');
+ assert.dom(this.element).containsText('SocketCluster Connection');
+ });
- // Template block usage:
- await render(hbs`
- <Configure::Socket>
- template block text
- </Configure::Socket>
- `);
+ test('testSocketConnection posts to the test endpoint', async function (assert) {
+ await render(hbs`<Configure::Socket />`);
- assert.dom(this.element).hasText('template block text');
+ assert.deepEqual(this.posted, [], 'nothing is posted on render');
});
});
diff --git a/console/tests/integration/components/console-wormhole-test.js b/console/tests/integration/components/console-wormhole-test.js
index d6cf4e09..6d9c3b69 100644
--- a/console/tests/integration/components/console-wormhole-test.js
+++ b/console/tests/integration/components/console-wormhole-test.js
@@ -6,21 +6,9 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | console-wormhole', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
-
+ test('it renders the console wormhole destination element', async function (assert) {
await render(hbs`<ConsoleWormhole />`);
- assert.dom().hasText('');
-
- // Template block usage:
- await render(hbs`
- <ConsoleWormhole>
- template block text
- </ConsoleWormhole>
- `);
-
- assert.dom().hasText('template block text');
+ assert.dom('#console-wormhole').exists('other components can wormhole into this element');
});
});
diff --git a/console/tests/integration/components/dashboard/count-test.js b/console/tests/integration/components/dashboard/count-test.js
index b7ccc203..091801e0 100644
--- a/console/tests/integration/components/dashboard/count-test.js
+++ b/console/tests/integration/components/dashboard/count-test.js
@@ -6,21 +6,34 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | dashboard/count', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ test('it renders the title and an explicit value', async function (assert) {
+ await render(hbs`<Dashboard::Count @title="Orders" @value="42" />`);
- await render(hbs`<Dashboard::Count />`);
+ assert.dom(this.element).containsText('Orders');
+ assert.dom(this.element).containsText('42');
+ });
+
+ test('an explicit value wins over the options format', async function (assert) {
+ await render(hbs`<Dashboard::Count @title="Revenue" @value="explicit" @options={{hash format="money" value=1000 currency="USD"}} />`);
+
+ assert.dom(this.element).containsText('explicit', 'the provided value is not reformatted');
+ });
+
+ test('it formats a money value from options', async function (assert) {
+ await render(hbs`<Dashboard::Count @title="Revenue" @options={{hash format="money" value=1000 currency="USD"}} />`);
- assert.dom(this.element).hasText('');
+ assert.dom(this.element).containsText('$', 'the money format is applied');
+ });
+
+ test('it formats a bytes value from options', async function (assert) {
+ await render(hbs`<Dashboard::Count @title="Storage" @options={{hash format="bytes" value=1024}} />`);
+
+ assert.dom(this.element).doesNotContainText('1024', 'the raw byte count is formatted');
+ });
- // Template block usage:
- await render(hbs`
- <Dashboard::Count>
- template block text
- </Dashboard::Count>
- `);
+ test('an unrecognized format passes the value through unchanged', async function (assert) {
+ await render(hbs`<Dashboard::Count @title="Drivers" @options={{hash value=7}} />`);
- assert.dom(this.element).hasText('template block text');
+ assert.dom(this.element).containsText('7');
});
});
diff --git a/console/tests/integration/components/dashboard/query-params-test.js b/console/tests/integration/components/dashboard/query-params-test.js
index 5af3349b..83505a78 100644
--- a/console/tests/integration/components/dashboard/query-params-test.js
+++ b/console/tests/integration/components/dashboard/query-params-test.js
@@ -6,21 +6,24 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | dashboard/query-params', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ test('it renders a labelled control for each param', async function (assert) {
+ this.set('params', {
+ status: { component: 'input' },
+ driver_name: { component: 'input' },
+ });
- await render(hbs`<Dashboard::QueryParams />`);
+ await render(hbs`<Dashboard::QueryParams @params={{this.params}} />`);
- assert.dom(this.element).hasText('');
+ // humanize() only upper-cases the first character: driver_name -> "Driver name".
+ assert.dom(this.element).containsText('Status');
+ assert.dom(this.element).containsText('Driver name', 'param keys are humanized into labels');
+ });
- // Template block usage:
- await render(hbs`
- <Dashboard::QueryParams>
- template block text
- </Dashboard::QueryParams>
- `);
+ test('it renders nothing for an empty param set', async function (assert) {
+ this.set('params', {});
- assert.dom(this.element).hasText('template block text');
+ await render(hbs`<Dashboard::QueryParams @params={{this.params}} />`);
+
+ assert.dom(this.element).hasText('');
});
});
diff --git a/console/tests/integration/components/fleetbase-blog-test.js b/console/tests/integration/components/fleetbase-blog-test.js
index 057e7087..cbfed904 100644
--- a/console/tests/integration/components/fleetbase-blog-test.js
+++ b/console/tests/integration/components/fleetbase-blog-test.js
@@ -3,11 +3,18 @@ import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
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';
module('Integration | Component | fleetbase-blog', function (hooks) {
setupRenderingTest(hooks);
hooks.beforeEach(function () {
+ // storageFor() memoizes its buckets in a module-level cache, so the 'local-cache'
+ // object is shared by every test container and outlives the one that created it.
+ // Left alone, the first test's cached posts get served to the second, and touching
+ // the stale object throws "Cannot create a new tag ... after it has been destroyed".
+ // _resetStorages() drops that memo so each test builds its own bucket.
+ _resetStorages();
window.localStorage.clear();
class FetchStub extends Service {
@@ -44,9 +51,12 @@ module('Integration | Component | fleetbase-blog', function (hooks) {
assert.deepEqual(fetch.requests, ['lookup/fleetbase-blog']);
assert.dom('.fleetbase-blog').containsText('Fleetbase Blog');
- assert.dom('a[href="https://www.fleetbase.io/blog/first-ghost-post"]').hasText('First Ghost Post');
- assert.dom('a[href="https://www.fleetbase.io/blog/second-ghost-post"]').hasText('Second Ghost Post');
- assert.dom('.fleetbase-blog').containsText('Wed, 06 May 2026 14:31:46 GMT');
+ // Each post link renders the title and the formatted date side by side, so the
+ // anchor's text is "<title> <date>" — match on containment, not equality.
+ assert.dom('a[href="https://www.fleetbase.io/blog/first-ghost-post"]').containsText('First Ghost Post');
+ assert.dom('a[href="https://www.fleetbase.io/blog/second-ghost-post"]').containsText('Second Ghost Post');
+ // pubDate is rendered through formatPublishedDate as 'MMM d, yyyy', not raw.
+ assert.dom('.fleetbase-blog').containsText('May 6, 2026');
});
test('it renders an empty state when no posts are available', async function (assert) {
diff --git a/console/tests/integration/components/github-card-test.js b/console/tests/integration/components/github-card-test.js
index c09218b5..7fa56445 100644
--- a/console/tests/integration/components/github-card-test.js
+++ b/console/tests/integration/components/github-card-test.js
@@ -2,25 +2,54 @@ 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 { _resetStorages } from 'ember-local-storage/helpers/storage';
+import { add } from 'date-fns';
+
+// Matches config/environment.js: namespace '@fleetbase' + keyDelimiter '/'.
+const LOCAL_CACHE_KEY = '@fleetbase/storage:local-cache';
module('Integration | Component | github-card', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ // storageFor() memoizes its buckets in a module-level cache that outlives the
+ // per-test container, so reset it and seed localStorage directly — the bucket
+ // hydrates from localStorage when the component first builds it. A live cache
+ // entry keeps the component from calling the real GitHub API.
+ _resetStorages();
+ window.localStorage.clear();
+
+ const notExpired = add(new Date(), { hours: 6 }).toISOString();
+ window.localStorage.setItem(
+ LOCAL_CACHE_KEY,
+ JSON.stringify({
+ 'fleetbase-github-data': {
+ full_name: 'fleetbase/fleetbase',
+ html_url: 'https://github.com/fleetbase/fleetbase',
+ owner: { avatar_url: '/images/fleetbase-logo-svg.svg' },
+ },
+ 'fleetbase-github-data-expiration': notExpired,
+ 'fleetbase-github-tags': [{ name: 'v0.7.53' }],
+ 'fleetbase-github-tags-expiration': notExpired,
+ })
+ );
+ });
+ hooks.afterEach(function () {
+ _resetStorages();
+ window.localStorage.clear();
+ });
+
+ test('it renders the repository card from cached data', async function (assert) {
await render(hbs`<GithubCard />`);
- assert.dom(this.element).hasText('');
+ assert.dom('.fleetbase-github-card').exists('the card renders');
+ assert.dom(this.element).containsText('fleetbase/fleetbase');
+ });
- // Template block usage:
- await render(hbs`
- <GithubCard>
- template block text
- </GithubCard>
- `);
+ test('it shows the latest cached release tag', async function (assert) {
+ await render(hbs`<GithubCard />`);
- assert.dom(this.element).hasText('template block text');
+ assert.dom(this.element).containsText('v0.7.53');
});
});
diff --git a/console/tests/integration/components/impersonator-tray-test.js b/console/tests/integration/components/impersonator-tray-test.js
index 435bbe1d..6b26576b 100644
--- a/console/tests/integration/components/impersonator-tray-test.js
+++ b/console/tests/integration/components/impersonator-tray-test.js
@@ -2,25 +2,39 @@ 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';
+
+function registerSession(owner, authenticated) {
+ class SessionStub extends Service {
+ data = { authenticated };
+ manuallyAuthenticate() {}
+ }
+ owner.register('service:session', SessionStub);
+}
module('Integration | Component | impersonator-tray', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ test('it renders nothing when the session is not an impersonation', async function (assert) {
+ registerSession(this.owner, {});
+
+ await render(hbs`
+ <div id="view-header-actions"></div>
+ <ImpersonatorTray />
+ `);
- await render(hbs`<ImpersonatorTray />`);
+ assert.dom('.locale-selector-tray').doesNotExist('the tray stays hidden for a normal session');
+ });
- assert.dom().hasText('');
+ test('it wormholes the tray into the header while impersonating', async function (assert) {
+ registerSession(this.owner, { impersonator: '[email protected]' });
- // Template block usage:
+ // The component wormholes into an element that only exists in the app shell.
await render(hbs`
- <ImpersonatorTray>
- template block text
- </ImpersonatorTray>
- `);
+ <div id="view-header-actions"></div>
+ <ImpersonatorTray />
+ `);
- assert.dom().hasText('template block text');
+ assert.dom('#view-header-actions .locale-selector-tray').exists('the tray renders into the header');
});
});
diff --git a/console/tests/integration/components/modals/edit-organization-test.js b/console/tests/integration/components/modals/edit-organization-test.js
index c30e0bbc..6c7fee39 100644
--- a/console/tests/integration/components/modals/edit-organization-test.js
+++ b/console/tests/integration/components/modals/edit-organization-test.js
@@ -6,21 +6,27 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | modals/edit-organization', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ // Components using {{t}} need the locale resolved before render, otherwise
+ // ember-intl sets _locale mid-render and trips the tracked-property assertion.
+ this.owner.lookup('service:intl').setLocale('en-us');
+ });
- await render(hbs`<Modals::EditOrganization />`);
+ test('it renders the organization fields bound to the modal options', async function (assert) {
+ this.set('options', {
+ title: 'Edit Organization',
+ organization: { name: 'Acme', description: 'Movers', phone: '+15550000', currency: 'USD' },
+ });
- assert.dom().hasText('');
+ await render(hbs`<Modals::EditOrganization @modalIsOpened={{true}} @options={{this.options}} />`);
- // Template block usage:
- await render(hbs`
- <Modals::EditOrganization>
- template block text
- </Modals::EditOrganization>
- `);
+ assert.dom(this.element).containsText('Organization name');
+ assert.dom(this.element).containsText('Organization description');
- assert.dom().hasText('template block text');
+ // The inputs receive their value as a property, not a value="" attribute, so an
+ // attribute selector would not match.
+ const values = [...this.element.querySelectorAll('input')].map((input) => input.value);
+ assert.ok(values.includes('Acme'), 'the organization name is bound');
+ assert.ok(values.includes('Movers'), 'the organization description is bound');
});
});
diff --git a/console/tests/integration/components/modals/leave-organization-test.js b/console/tests/integration/components/modals/leave-organization-test.js
index 81fec47b..7c276804 100644
--- a/console/tests/integration/components/modals/leave-organization-test.js
+++ b/console/tests/integration/components/modals/leave-organization-test.js
@@ -6,21 +6,28 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | modals/leave-organization', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ test('an owner with other members is asked to nominate a new owner', async function (assert) {
+ this.set('options', {
+ isOwner: true,
+ hasOtherMembers: true,
+ organization: { name: 'Acme', users: [] },
+ });
- await render(hbs`<Modals::LeaveOrganization />`);
+ await render(hbs`<Modals::LeaveOrganization @modalIsOpened={{true}} @options={{this.options}} />`);
- assert.dom().hasText('');
+ assert.dom(this.element).containsText('nominate a new owner');
+ assert.dom(this.element).containsText('Acme');
+ });
+
+ test('a non-owner is not asked to transfer ownership', async function (assert) {
+ this.set('options', {
+ isOwner: false,
+ hasOtherMembers: true,
+ organization: { name: 'Acme', users: [] },
+ });
- // Template block usage:
- await render(hbs`
- <Modals::LeaveOrganization>
- template block text
- </Modals::LeaveOrganization>
- `);
+ await render(hbs`<Modals::LeaveOrganization @modalIsOpened={{true}} @options={{this.options}} />`);
- assert.dom().hasText('template block text');
+ assert.dom(this.element).doesNotContainText('nominate a new owner');
});
});
diff --git a/console/tests/integration/components/modals/set-password-test.js b/console/tests/integration/components/modals/set-password-test.js
index 4ee7a530..08a98426 100644
--- a/console/tests/integration/components/modals/set-password-test.js
+++ b/console/tests/integration/components/modals/set-password-test.js
@@ -6,21 +6,18 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | modals/set-password', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
-
- await render(hbs`<Modals::SetPassword />`);
+ hooks.beforeEach(function () {
+ // Components using {{t}} need the locale resolved before render, otherwise
+ // ember-intl sets _locale mid-render and trips the tracked-property assertion.
+ this.owner.lookup('service:intl').setLocale('en-us');
+ });
- assert.dom().hasText('');
+ test('it renders the set-password modal body', async function (assert) {
+ this.set('options', { title: 'Set Password' });
- // Template block usage:
- await render(hbs`
- <Modals::SetPassword>
- template block text
- </Modals::SetPassword>
- `);
+ await render(hbs`<Modals::SetPassword @modalIsOpened={{true}} @options={{this.options}} />`);
- assert.dom().hasText('template block text');
+ assert.dom('.modal-body-container').exists('the modal body renders');
+ assert.dom('input[type="password"]').exists({ count: 2 }, 'a password and confirmation field are offered');
});
});
diff --git a/console/tests/integration/components/modals/validate-password-test.js b/console/tests/integration/components/modals/validate-password-test.js
index 2df98c8f..5978dccd 100644
--- a/console/tests/integration/components/modals/validate-password-test.js
+++ b/console/tests/integration/components/modals/validate-password-test.js
@@ -2,25 +2,43 @@ 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';
module('Integration | Component | modals/validate-password', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ class FetchStub extends Service {
+ post() {
+ return Promise.resolve({ valid: true });
+ }
+ }
+ class NotificationsStub extends Service {
+ success() {}
+ error() {}
+ serverError() {}
+ }
+ this.owner.register('service:fetch', FetchStub);
+ this.owner.register('service:notifications', NotificationsStub);
+ });
+
+ test('it renders the password fields and the supplied body', async function (assert) {
+ this.set('options', { body: 'Validate your current password.' });
- await render(hbs`<Modals::ValidatePassword />`);
+ await render(hbs`<Modals::ValidatePassword @modalIsOpened={{true}} @options={{this.options}} />`);
+
+ assert.dom(this.element).containsText('Validate your current password.');
+ assert.dom('input[type="password"]').exists({ count: 2 });
+ });
- assert.dom().hasText('');
+ test('it rewrites the modal options on setup', async function (assert) {
+ this.set('options', {});
- // Template block usage:
- await render(hbs`
- <Modals::ValidatePassword>
- template block text
- </Modals::ValidatePassword>
- `);
+ await render(hbs`<Modals::ValidatePassword @modalIsOpened={{true}} @options={{this.options}} />`);
- assert.dom().hasText('template block text');
+ assert.strictEqual(this.options.title, 'Validate Current Password');
+ assert.strictEqual(this.options.acceptButtonText, 'Validate Password');
+ assert.true(this.options.declineButtonHidden, 'the decline button is hidden');
+ assert.strictEqual(typeof this.options.confirm, 'function', 'a confirm handler is installed');
});
});
diff --git a/console/tests/integration/components/onboarding/form-test.js b/console/tests/integration/components/onboarding/form-test.js
index b43f7eb2..2909587c 100644
--- a/console/tests/integration/components/onboarding/form-test.js
+++ b/console/tests/integration/components/onboarding/form-test.js
@@ -1,26 +1,44 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, fillIn } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | onboarding/form', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ // Components using {{t}} need the locale resolved before render, otherwise
+ // ember-intl sets _locale mid-render and trips the tracked-property assertion.
+ this.owner.lookup('service:intl').setLocale('en-us');
+ });
+
+ test('it renders the onboarding form with a disabled submit button', async function (assert) {
+ await render(hbs`<Onboarding::Form />`);
+
+ assert.dom('form').exists('the signup form renders');
+ // The submit button is bound to {{not this.filled}}, so an empty form is disabled.
+ assert.dom('button[type="submit"]').isDisabled('submitting is blocked until every field is filled');
+ });
+ test('the phone number is required before the form can be submitted', async function (assert) {
await render(hbs`<Onboarding::Form />`);
- assert.dom().hasText('');
+ // Every text field is filled here, but `phone` is bound through PhoneInput's
+ // @onInput rather than a plain value binding, so typing into the DOM inputs alone
+ // leaves it blank — and `filled` requires all six values.
+ const inputs = [...this.element.querySelectorAll('form input')];
+ assert.ok(inputs.length >= 6, 'precondition: the form renders all of its fields');
+
+ for (const input of inputs) {
+ await fillIn(input, input.type === 'email' ? '[email protected]' : 'a-value');
+ }
+
+ assert.dom('button[type="submit"]').isDisabled('submitting stays blocked until the phone number is captured');
+ });
- // Template block usage:
- await render(hbs`
- <Onboarding::Form>
- template block text
- </Onboarding::Form>
- `);
+ test('it renders the brand logo when a brand is supplied', async function (assert) {
+ await render(hbs`<Onboarding::Form @brand={{hash logo_url="/images/fleetbase-logo-svg.svg"}} />`);
- assert.dom().hasText('template block text');
+ assert.dom('img').exists('the brand logo renders');
});
});
diff --git a/console/tests/integration/components/onboarding/verify-email-test.js b/console/tests/integration/components/onboarding/verify-email-test.js
index f1b7067d..532589e5 100644
--- a/console/tests/integration/components/onboarding/verify-email-test.js
+++ b/console/tests/integration/components/onboarding/verify-email-test.js
@@ -2,25 +2,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 Service from '@ember/service';
+import { tracked } from '@glimmer/tracking';
module('Integration | Component | onboarding/verify-email', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ // Components using {{t}} need the locale resolved before render, otherwise
+ // ember-intl sets _locale mid-render and trips the tracked-property assertion.
+ this.owner.lookup('service:intl').setLocale('en-us');
- await render(hbs`<Onboarding::VerifyEmail />`);
+ const started = [];
- assert.dom().hasText('');
+ // The real user-verification service schedules a 75s `later` in start(), which
+ // would keep settled() waiting for the whole timeout. The template also binds
+ // several of its members directly, so the stub has to provide them all.
+ class VerificationStub extends Service {
+ @tracked ready = false;
+ @tracked waiting = false;
- // Template block usage:
- await render(hbs`
- <Onboarding::VerifyEmail>
- template block text
- </Onboarding::VerifyEmail>
- `);
+ start(options) {
+ started.push(options);
+ }
+ validateInput() {}
+ didntReceiveCode() {}
+ resendBySms() {}
+ resendEmail() {}
+ }
+ class UrlSearchParamsStub extends Service {
+ params = { code: '123456', session: 'sess_from_url' };
+ get(key) {
+ return this.params[key];
+ }
+ }
- assert.dom().hasText('template block text');
+ this.owner.register('service:user-verification', VerificationStub);
+ this.owner.register('service:url-search-params', UrlSearchParamsStub);
+ this.started = started;
+ });
+
+ test('it initializes from the URL params and starts verification', async function (assert) {
+ this.set('context', { get: () => undefined });
+
+ await render(hbs`<Onboarding::VerifyEmail @context={{this.context}} />`);
+
+ assert.strictEqual(this.started.length, 1, 'verification is started');
+ assert.dom('form').exists('the verification form renders once initialized');
+ });
+
+ test('the onboarding context session wins over the URL session', async function (assert) {
+ this.set('context', { get: (key) => (key === 'session' ? 'sess_from_context' : undefined) });
+
+ await render(hbs`<Onboarding::VerifyEmail @context={{this.context}} />`);
+
+ assert.strictEqual(this.started.length, 1, 'verification is started once');
+ assert.dom('form').exists();
});
});
diff --git a/console/tests/integration/components/onboarding/yield-test.js b/console/tests/integration/components/onboarding/yield-test.js
index 0be6b22e..e18fe0e3 100644
--- a/console/tests/integration/components/onboarding/yield-test.js
+++ b/console/tests/integration/components/onboarding/yield-test.js
@@ -6,21 +6,38 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | onboarding/yield', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
-
+ test('it renders a spinner until initialization completes', async function (assert) {
await render(hbs`<Onboarding::Yield />`);
- assert.dom().hasText('');
+ assert.dom('.onboarding.step-host').exists('the step host renders');
+ });
+
+ test('it sends the requested step to the orchestrator', async function (assert) {
+ const orchestrator = this.owner.lookup('service:onboarding-orchestrator');
+
+ let wentTo;
+ Object.defineProperty(orchestrator, 'goto', {
+ configurable: true,
+ value: (step) => {
+ wentTo = step;
+ return Promise.resolve();
+ },
+ });
+
+ await render(hbs`<Onboarding::Yield @step="verify-email" />`);
+
+ assert.strictEqual(wentTo, 'verify-email');
+ });
+
+ test('it persists the session and code into the onboarding context', async function (assert) {
+ const orchestrator = this.owner.lookup('service:onboarding-orchestrator');
+ Object.defineProperty(orchestrator, 'goto', { configurable: true, value: () => Promise.resolve() });
+
+ const context = this.owner.lookup('service:onboarding-context');
- // Template block usage:
- await render(hbs`
- <Onboarding::Yield>
- template block text
- </Onboarding::Yield>
- `);
+ await render(hbs`<Onboarding::Yield @session="sess_1" @code="123456" />`);
- assert.dom().hasText('template block text');
+ assert.strictEqual(context.get('session'), 'sess_1', 'the session is persisted');
+ assert.strictEqual(context.get('code'), '123456', 'the code is stored');
});
});
diff --git a/console/tests/integration/components/two-fa-enforcement-alert-test.js b/console/tests/integration/components/two-fa-enforcement-alert-test.js
index aa3ecd94..c4ef3706 100644
--- a/console/tests/integration/components/two-fa-enforcement-alert-test.js
+++ b/console/tests/integration/components/two-fa-enforcement-alert-test.js
@@ -1,26 +1,68 @@
import { module, test } from 'qunit';
import { setupRenderingTest } from '@fleetbase/console/tests/helpers';
-import { render } from '@ember/test-helpers';
+import { render, click } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';
+import Service from '@ember/service';
+
+function registerFetch(owner, response) {
+ class FetchStub extends Service {
+ get() {
+ return Promise.resolve(response);
+ }
+ }
+ owner.register('service:fetch', FetchStub);
+}
module('Integration | Component | two-fa-enforcement-alert', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ // Components using {{t}} need the locale resolved before render, otherwise
+ // ember-intl sets _locale mid-render and trips the tracked-property assertion.
+ this.owner.lookup('service:intl').setLocale('en-us');
+ });
+
+ test('it renders the alert when 2FA is enforced', async function (assert) {
+ registerFetch(this.owner, { shouldEnforce: true });
+
+ await render(hbs`<TwoFaEnforcementAlert />`);
+
+ assert.dom('.two-fa-enforcement-alert').exists('the alert is shown');
+ assert.dom('#two-fa-setup-button').exists('the setup button is offered');
+ });
+
+ test('it renders nothing when 2FA is not enforced', async function (assert) {
+ registerFetch(this.owner, { shouldEnforce: false });
+
+ await render(hbs`<TwoFaEnforcementAlert />`);
+
+ assert.dom('.two-fa-enforcement-alert').doesNotExist();
+ });
+
+ test('it renders nothing when the enforcement check returns nothing', async function (assert) {
+ registerFetch(this.owner, null);
+
+ await render(hbs`<TwoFaEnforcementAlert />`);
+
+ assert.dom('.two-fa-enforcement-alert').doesNotExist();
+ });
+
+ test('the setup button transitions to the account auth settings', async function (assert) {
+ registerFetch(this.owner, { shouldEnforce: true });
await render(hbs`<TwoFaEnforcementAlert />`);
- assert.dom().hasText('');
+ // RouterService can't be swapped via owner.register; patch the instance the
+ // component resolves.
+ let transitionedTo;
+ const router = this.owner.lookup('service:router');
+ Object.defineProperty(router, 'transitionTo', {
+ configurable: true,
+ value: (routeName) => (transitionedTo = routeName),
+ });
- // Template block usage:
- await render(hbs`
- <TwoFaEnforcementAlert>
- template block text
- </TwoFaEnforcementAlert>
- `);
+ await click('#two-fa-setup-button');
- assert.dom().hasText('template block text');
+ assert.strictEqual(transitionedTo, 'console.account.auth');
});
});
diff --git a/console/tests/integration/components/two-fa-settings-test.js b/console/tests/integration/components/two-fa-settings-test.js
index 0ed2986d..5dd57be9 100644
--- a/console/tests/integration/components/two-fa-settings-test.js
+++ b/console/tests/integration/components/two-fa-settings-test.js
@@ -6,21 +6,45 @@ import { hbs } from 'ember-cli-htmlbars';
module('Integration | Component | two-fa-settings', function (hooks) {
setupRenderingTest(hooks);
- test('it renders', async function (assert) {
- // Set any properties with this.set('myProperty', 'value');
- // Handle any actions with this.set('myAction', function(val) { ... });
+ hooks.beforeEach(function () {
+ this.set('methods', [
+ { key: 'email', name: 'Email' },
+ { key: 'sms', name: 'SMS', recommended: true },
+ ]);
+ });
+
+ test('it renders the enable toggle and hides the details when 2FA is off', async function (assert) {
+ this.set('settings', { enabled: false });
+
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} @twoFaMethods={{this.methods}} />`);
+
+ assert.dom(this.element).containsText('Enable Two-Factor Authentication');
+ assert.dom(this.element).doesNotContainText('Choose an authentication method', 'method selection is hidden while disabled');
+ });
+
+ test('it shows the method selection when 2FA is enabled', async function (assert) {
+ this.set('settings', { enabled: true, method: 'sms' });
- await render(hbs`<TwoFaSettings />`);
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} @twoFaMethods={{this.methods}} />`);
+
+ assert.dom(this.element).containsText('Choose an authentication method');
+ });
+
+ test('the enforce option is only offered when requested', async function (assert) {
+ this.set('settings', { enabled: true, enforced: true });
+
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} @twoFaMethods={{this.methods}} />`);
+ assert.dom(this.element).doesNotContainText('Require Users to Set-Up 2FA', 'hidden by default');
+
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} @twoFaMethods={{this.methods}} @showEnforceOption={{true}} />`);
+ assert.dom(this.element).containsText('Require Users to Set-Up 2FA');
+ });
- assert.dom(this.element).hasText('');
+ test('method selection can be suppressed', async function (assert) {
+ this.set('settings', { enabled: true, method: 'email' });
- // Template block usage:
- await render(hbs`
- <TwoFaSettings>
- template block text
- </TwoFaSettings>
- `);
+ await render(hbs`<TwoFaSettings @twoFaSettings={{this.settings}} @twoFaMethods={{this.methods}} @showMethodSelection={{false}} />`);
- assert.dom(this.element).hasText('template block text');
+ assert.dom(this.element).doesNotContainText('Choose an authentication method');
});
});