Files
threshold-ui/ui/desktop/tests/unit/controllers/application-test.js
T

59 lines
1.9 KiB
JavaScript
Raw Normal View History

/**
2026-01-28 17:09:06 -08:00
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
2020-11-13 15:20:26 -05:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { authenticateSession } from 'ember-simple-auth/test-support';
import { setupDesktopContextBridgeApiMock } from '../../helpers/desktop-context-bridge-api-mock';
2026-05-20 16:36:16 -04:00
import sinon from 'sinon';
2020-11-13 15:20:26 -05:00
2020-11-16 15:08:59 -05:00
module('Unit | Controller | application', function (hooks) {
2020-11-13 15:20:26 -05:00
setupTest(hooks);
setupDesktopContextBridgeApiMock(hooks);
2020-11-13 15:20:26 -05:00
let controller;
let clusterUrl;
let session;
hooks.beforeEach(async function () {
await authenticateSession({});
controller = this.owner.lookup('controller:application');
session = this.owner.lookup('service:session');
clusterUrl = this.owner.lookup('service:cluster-url');
});
2020-11-16 15:08:59 -05:00
test('it exists', function (assert) {
2020-11-13 15:20:26 -05:00
assert.ok(controller);
assert.ok(controller.minimize);
assert.ok(controller.toggleFullScreen);
assert.ok(controller.close);
assert.ok(controller.confirmCloseSessions);
assert.ok(controller.showModalOrLogout);
});
test('toggleTheme action sets theme to specified value', function (assert) {
assert.notOk(session.data.theme);
controller.toggleTheme('light');
assert.strictEqual(session.data.theme, 'light');
});
2026-05-20 16:36:16 -04:00
test('disconnect action de-authenticates a user and keeps last cluster url', async function (assert) {
const url = 'http://localhost:9200';
await clusterUrl.setClusterUrl(url);
assert.true(session.isAuthenticated);
assert.strictEqual(await window.desktop.cluster.getClusterUrl(), url);
2026-05-20 16:36:16 -04:00
assert.strictEqual(clusterUrl.adapter.host, url);
2026-05-20 16:36:16 -04:00
sinon.stub(controller.router, 'replaceWith');
await controller.disconnect();
assert.false(session.isAuthenticated);
2026-05-20 16:36:16 -04:00
assert.strictEqual(await window.desktop.cluster.getClusterUrl(), url);
assert.strictEqual(clusterUrl.adapter.host, url);
2020-11-13 15:20:26 -05:00
});
});