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

69 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* 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 WindowMockIPC from '../../helpers/window-mock-ipc';
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);
let controller;
let session;
let clusterUrl;
let mockIPC;
const setupMockIpc = (test) => {
test.owner.register('service:browser/window', WindowMockIPC);
mockIPC = test.owner.lookup('service:browser/window').mockIPC;
};
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');
setupMockIpc(this);
});
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);
});
test('invalidateSession action de-authenticates a user', async function (assert) {
assert.true(session.isAuthenticated);
await controller.invalidateSession();
assert.false(session.isAuthenticated);
});
test('toggleTheme action sets theme to specified value', function (assert) {
assert.notOk(session.data.theme);
controller.toggleTheme('light');
assert.strictEqual(session.data.theme, 'light');
});
test('disconnect action de-authenticates a user and resets cluster url', async function (assert) {
const url = 'http://localhost:9200';
await clusterUrl.setClusterUrl(url);
assert.true(session.isAuthenticated);
assert.strictEqual(clusterUrl.rendererClusterUrl, url);
assert.strictEqual(mockIPC.clusterUrl, url);
await controller.disconnect();
assert.false(session.isAuthenticated);
assert.notOk(clusterUrl.rendererClusterUrl);
assert.notOk(mockIPC.clusterUrl);
2020-11-13 15:20:26 -05:00
});
});