2023-03-01 09:39:41 -06:00
|
|
|
/**
|
2026-01-28 17:09:06 -08:00
|
|
|
* Copyright IBM Corp. 2021, 2026
|
2024-05-31 11:29:24 -07:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-01 09:39:41 -06:00
|
|
|
*/
|
|
|
|
|
|
2020-11-13 15:20:26 -05:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2024-09-17 16:36:47 -07:00
|
|
|
import { authenticateSession } from 'ember-simple-auth/test-support';
|
2026-03-13 15:14:38 -07:00
|
|
|
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);
|
2026-03-13 15:14:38 -07:00
|
|
|
setupDesktopContextBridgeApiMock(hooks);
|
2020-11-13 15:20:26 -05:00
|
|
|
|
2024-09-17 16:36:47 -07:00
|
|
|
let controller;
|
|
|
|
|
let clusterUrl;
|
2025-08-04 16:44:27 -04:00
|
|
|
let session;
|
2024-09-17 16:36:47 -07:00
|
|
|
|
|
|
|
|
hooks.beforeEach(async function () {
|
2024-12-02 15:30:28 -08:00
|
|
|
await authenticateSession({});
|
2024-09-17 16:36:47 -07:00
|
|
|
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);
|
2024-09-17 16:36:47 -07:00
|
|
|
assert.ok(controller.minimize);
|
|
|
|
|
assert.ok(controller.toggleFullScreen);
|
|
|
|
|
assert.ok(controller.close);
|
2025-08-04 16:44:27 -04:00
|
|
|
assert.ok(controller.confirmCloseSessions);
|
|
|
|
|
assert.ok(controller.showModalOrLogout);
|
2024-09-17 16:36:47 -07:00
|
|
|
});
|
|
|
|
|
|
2024-11-12 09:27:07 -08:00
|
|
|
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) {
|
2024-09-17 16:36:47 -07:00
|
|
|
const url = 'http://localhost:9200';
|
|
|
|
|
await clusterUrl.setClusterUrl(url);
|
|
|
|
|
|
|
|
|
|
assert.true(session.isAuthenticated);
|
2026-03-13 15:14:38 -07:00
|
|
|
assert.strictEqual(await window.desktop.cluster.getClusterUrl(), url);
|
2026-05-20 16:36:16 -04:00
|
|
|
assert.strictEqual(clusterUrl.adapter.host, url);
|
2024-09-17 16:36:47 -07:00
|
|
|
|
2026-05-20 16:36:16 -04:00
|
|
|
sinon.stub(controller.router, 'replaceWith');
|
2024-09-17 16:36:47 -07:00
|
|
|
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
|
|
|
});
|
|
|
|
|
});
|