Files
dashtab/tests/unit/config/home-assistant-test.js
2026-10-08 19:24:02 +02:00

60 lines
1.9 KiB
JavaScript

import { module, test } from 'qunit';
import {
integrationKey,
normalizeHomeAssistantUrl,
profileUrl,
websocketUrl,
} from 'dashtab/config/home-assistant';
module('Unit | Config | home-assistant', function () {
test('normalizeHomeAssistantUrl normalizes input and rejects junk', function (assert) {
assert.strictEqual(
normalizeHomeAssistantUrl('ha.example.com:8123'),
'https://ha.example.com:8123'
);
assert.strictEqual(
normalizeHomeAssistantUrl('https://ha.example.com:8123/'),
'https://ha.example.com:8123'
);
assert.strictEqual(
normalizeHomeAssistantUrl('http://192.168.1.10:8123'),
'http://192.168.1.10:8123'
);
assert.strictEqual(normalizeHomeAssistantUrl(''), null);
assert.strictEqual(normalizeHomeAssistantUrl(' '), null);
assert.strictEqual(normalizeHomeAssistantUrl('not a valid url'), null);
});
test('websocketUrl switches the scheme and appends the socket path', function (assert) {
assert.strictEqual(
websocketUrl('https://ha.example.com:8123'),
'wss://ha.example.com:8123/api/websocket'
);
assert.strictEqual(
websocketUrl('http://192.168.1.10:8123'),
'ws://192.168.1.10:8123/api/websocket'
);
assert.strictEqual(websocketUrl(''), null);
});
test('profileUrl points at the token page', function (assert) {
assert.strictEqual(
profileUrl('https://ha.example.com:8123'),
'https://ha.example.com:8123/profile/security'
);
assert.strictEqual(profileUrl(''), null);
});
test('integrationKey is unique per host and port', function (assert) {
assert.strictEqual(
integrationKey('https://ha.example.com'),
'homeassistant-ha.example.com'
);
assert.strictEqual(
integrationKey('https://ha.example.com:8123'),
'homeassistant-ha.example.com:8123'
);
assert.strictEqual(integrationKey(''), null);
});
});