Files
threshold-ui/ui/desktop/tests/unit/services/cluster-url-test.js
T
Priya Patel 392e49bf49 refactor: 💡 window postmessage pattern -> contextbridge boundary api (#3167)
* refactor: 💡 postmessage pattern -> contextbridge boundary api

* refactor: 💡 use sinon stub for boundary api mock test helper

* refactor: 💡 updated tests

* refactor: 💡 renamed boundary mock api

* chore: 🤖 addressed feedback

* refactor: 💡 updated context bridge name, added nested objects
2026-03-13 15:14:38 -07:00

54 lines
2.1 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import { setupDesktopContextBridgeApiMock } from '../../helpers/desktop-context-bridge-api-mock';
module('Unit | Service | clusterUrl', function (hooks) {
setupTest(hooks);
setupDesktopContextBridgeApiMock(hooks);
let service;
hooks.beforeEach(function () {
service = this.owner.lookup('service:clusterUrl');
});
test('resets clusterUrl on error', async function (assert) {
assert.expect(4);
await service.setClusterUrl(window.location.origin);
assert.strictEqual(service.rendererClusterUrl, window.location.origin);
assert.strictEqual(service.adapter.host, window.location.origin);
window.desktop.cluster.setClusterUrl.rejects();
service.setClusterUrl('invalid-origin').catch(() => {
assert.notOk(service.rendererClusterUrl);
assert.strictEqual(service.adapter.host, window.location.origin);
});
});
test('drops trailing slashes from clusterUrl on setClusterUrl', async function (assert) {
assert.expect(4);
await service.setClusterUrl(`${window.location.origin}/`);
assert.strictEqual(service.rendererClusterUrl, window.location.origin);
assert.strictEqual(service.adapter.host, window.location.origin);
await service.setClusterUrl(`${window.location.origin}//////`);
assert.strictEqual(service.rendererClusterUrl, window.location.origin);
assert.strictEqual(service.adapter.host, window.location.origin);
});
test('trim spaces from clusterUrl on setClusterUrl', async function (assert) {
assert.expect(4);
await service.setClusterUrl(` ${window.location.origin}/ `);
assert.strictEqual(service.rendererClusterUrl, window.location.origin);
assert.strictEqual(service.adapter.host, window.location.origin);
await service.setClusterUrl(` ${window.location.origin} `);
assert.strictEqual(service.rendererClusterUrl, window.location.origin);
assert.strictEqual(service.adapter.host, window.location.origin);
});
});