mirror of
https://github.com/home-assistant/frontend.git
synced 2026-05-08 17:28:46 +01:00
@@ -1,10 +1,10 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import durationToSeconds from '../../../src/common/datetime/duration_to_seconds.js';
|
||||
import durationToSeconds from "../../../src/common/datetime/duration_to_seconds.js";
|
||||
|
||||
describe('durationToSeconds', () => {
|
||||
it('works', () => {
|
||||
assert.strictEqual(durationToSeconds('0:01:05'), 65);
|
||||
assert.strictEqual(durationToSeconds('11:01:05'), 39665);
|
||||
describe("durationToSeconds", () => {
|
||||
it("works", () => {
|
||||
assert.strictEqual(durationToSeconds("0:01:05"), 65);
|
||||
assert.strictEqual(durationToSeconds("11:01:05"), 39665);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import formatDate from '../../../src/common/datetime/format_date';
|
||||
import formatDate from "../../../src/common/datetime/format_date";
|
||||
|
||||
describe('formatDate', () => {
|
||||
const dateObj = new Date(
|
||||
2017, 10, 18,
|
||||
11, 12, 13, 1400,
|
||||
);
|
||||
describe("formatDate", () => {
|
||||
const dateObj = new Date(2017, 10, 18, 11, 12, 13, 1400);
|
||||
|
||||
it('Formats English dates', () => {
|
||||
assert.strictEqual(formatDate(dateObj, 'en'), 'November 18, 2017');
|
||||
it("Formats English dates", () => {
|
||||
assert.strictEqual(formatDate(dateObj, "en"), "November 18, 2017");
|
||||
});
|
||||
|
||||
// Node only contains intl support for english formats. This test at least ensures
|
||||
// the fallback to a different locale
|
||||
it('Formats other dates', () => {
|
||||
assert.strictEqual(formatDate(dateObj, 'fr'), '2017 M11 18');
|
||||
it("Formats other dates", () => {
|
||||
assert.strictEqual(formatDate(dateObj, "fr"), "2017 M11 18");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import formatDateTime from '../../../src/common/datetime/format_date_time';
|
||||
import formatDateTime from "../../../src/common/datetime/format_date_time";
|
||||
|
||||
describe('formatDateTime', () => {
|
||||
const dateObj = new Date(
|
||||
2017, 10, 18,
|
||||
11, 12, 13, 1400,
|
||||
);
|
||||
describe("formatDateTime", () => {
|
||||
const dateObj = new Date(2017, 10, 18, 11, 12, 13, 1400);
|
||||
|
||||
it('Formats English date times', () => {
|
||||
assert.strictEqual(formatDateTime(dateObj, 'en'), 'November 18, 2017, 11:12 AM');
|
||||
it("Formats English date times", () => {
|
||||
assert.strictEqual(
|
||||
formatDateTime(dateObj, "en"),
|
||||
"November 18, 2017, 11:12 AM"
|
||||
);
|
||||
});
|
||||
|
||||
// Node only contains intl support for english formats. This test at least ensures
|
||||
// the fallback to a different locale
|
||||
it('Formats other date times', () => {
|
||||
assert.strictEqual(formatDateTime(dateObj, 'fr'), '2017 M11 18 11:12');
|
||||
it("Formats other date times", () => {
|
||||
assert.strictEqual(formatDateTime(dateObj, "fr"), "2017 M11 18 11:12");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import formatTime from '../../../src/common/datetime/format_time';
|
||||
import formatTime from "../../../src/common/datetime/format_time";
|
||||
|
||||
describe('formatTime', () => {
|
||||
const dateObj = new Date(
|
||||
2017, 10, 18,
|
||||
11, 12, 13, 1400,
|
||||
);
|
||||
describe("formatTime", () => {
|
||||
const dateObj = new Date(2017, 10, 18, 11, 12, 13, 1400);
|
||||
|
||||
it('Formats English times', () => {
|
||||
assert.strictEqual(formatTime(dateObj, 'en'), '11:12 AM');
|
||||
it("Formats English times", () => {
|
||||
assert.strictEqual(formatTime(dateObj, "en"), "11:12 AM");
|
||||
});
|
||||
|
||||
// Node only contains intl support for english formats. This test at least ensures
|
||||
// the fallback to a different locale
|
||||
it('Formats other times', () => {
|
||||
assert.strictEqual(formatTime(dateObj, 'fr'), '11:12');
|
||||
it("Formats other times", () => {
|
||||
assert.strictEqual(formatTime(dateObj, "fr"), "11:12");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import secondsToDuration from '../../../src/common/datetime/seconds_to_duration.js';
|
||||
import secondsToDuration from "../../../src/common/datetime/seconds_to_duration.js";
|
||||
|
||||
describe('secondsToDuration', () => {
|
||||
it('works', () => {
|
||||
describe("secondsToDuration", () => {
|
||||
it("works", () => {
|
||||
assert.strictEqual(secondsToDuration(0), null);
|
||||
assert.strictEqual(secondsToDuration(65), '1:05');
|
||||
assert.strictEqual(secondsToDuration(3665), '1:01:05');
|
||||
assert.strictEqual(secondsToDuration(39665), '11:01:05');
|
||||
assert.strictEqual(secondsToDuration(65), "1:05");
|
||||
assert.strictEqual(secondsToDuration(3665), "1:01:05");
|
||||
assert.strictEqual(secondsToDuration(39665), "11:01:05");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,32 +1,26 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import attributeClassNames from '../../../src/common/entity/attribute_class_names';
|
||||
import attributeClassNames from "../../../src/common/entity/attribute_class_names";
|
||||
|
||||
describe('attributeClassNames', () => {
|
||||
const attrs = ['mock_attr1', 'mock_attr2'];
|
||||
describe("attributeClassNames", () => {
|
||||
const attrs = ["mock_attr1", "mock_attr2"];
|
||||
|
||||
it('Skips null states', () => {
|
||||
it("Skips null states", () => {
|
||||
const stateObj = null;
|
||||
assert.strictEqual(
|
||||
attributeClassNames(stateObj, attrs),
|
||||
''
|
||||
);
|
||||
assert.strictEqual(attributeClassNames(stateObj, attrs), "");
|
||||
});
|
||||
|
||||
it('Matches no attrbutes', () => {
|
||||
it("Matches no attrbutes", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
other_attr_1: 1,
|
||||
other_attr_2: 2,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
attributeClassNames(stateObj, attrs),
|
||||
''
|
||||
);
|
||||
assert.strictEqual(attributeClassNames(stateObj, attrs), "");
|
||||
});
|
||||
|
||||
it('Matches one attrbute', () => {
|
||||
it("Matches one attrbute", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
other_attr_1: 1,
|
||||
@@ -34,13 +28,10 @@ describe('attributeClassNames', () => {
|
||||
mock_attr1: 3,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
attributeClassNames(stateObj, attrs),
|
||||
'has-mock_attr1'
|
||||
);
|
||||
assert.strictEqual(attributeClassNames(stateObj, attrs), "has-mock_attr1");
|
||||
});
|
||||
|
||||
it('Matches two attrbutes', () => {
|
||||
it("Matches two attrbutes", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
other_attr_1: 1,
|
||||
@@ -51,7 +42,7 @@ describe('attributeClassNames', () => {
|
||||
};
|
||||
assert.strictEqual(
|
||||
attributeClassNames(stateObj, attrs),
|
||||
'has-mock_attr1 has-mock_attr2'
|
||||
"has-mock_attr1 has-mock_attr2"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import canToggleDomain from '../../../src/common/entity/can_toggle_domain';
|
||||
import canToggleDomain from "../../../src/common/entity/can_toggle_domain";
|
||||
|
||||
describe('canToggleDomain', () => {
|
||||
describe("canToggleDomain", () => {
|
||||
const hass = {
|
||||
services: {
|
||||
light: {
|
||||
@@ -19,19 +19,19 @@ describe('canToggleDomain', () => {
|
||||
},
|
||||
};
|
||||
|
||||
it('Detects lights toggle', () => {
|
||||
assert.isTrue(canToggleDomain(hass, 'light'));
|
||||
it("Detects lights toggle", () => {
|
||||
assert.isTrue(canToggleDomain(hass, "light"));
|
||||
});
|
||||
|
||||
it('Detects locks toggle', () => {
|
||||
assert.isTrue(canToggleDomain(hass, 'lock'));
|
||||
it("Detects locks toggle", () => {
|
||||
assert.isTrue(canToggleDomain(hass, "lock"));
|
||||
});
|
||||
|
||||
it('Detects sensors do not toggle', () => {
|
||||
assert.isFalse(canToggleDomain(hass, 'sensor'));
|
||||
it("Detects sensors do not toggle", () => {
|
||||
assert.isFalse(canToggleDomain(hass, "sensor"));
|
||||
});
|
||||
|
||||
it('Detects binary sensors do not toggle', () => {
|
||||
assert.isFalse(canToggleDomain(hass, 'binary_sensor'));
|
||||
it("Detects binary sensors do not toggle", () => {
|
||||
assert.isFalse(canToggleDomain(hass, "binary_sensor"));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import canToggleState from '../../../src/common/entity/can_toggle_state';
|
||||
import canToggleState from "../../../src/common/entity/can_toggle_state";
|
||||
|
||||
describe('canToggleState', () => {
|
||||
describe("canToggleState", () => {
|
||||
const hass = {
|
||||
services: {
|
||||
light: {
|
||||
@@ -12,33 +12,33 @@ describe('canToggleState', () => {
|
||||
},
|
||||
};
|
||||
|
||||
it('Detects lights toggle', () => {
|
||||
it("Detects lights toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'light.bla',
|
||||
state: 'on',
|
||||
entity_id: "light.bla",
|
||||
state: "on",
|
||||
};
|
||||
assert.isTrue(canToggleState(hass, stateObj));
|
||||
});
|
||||
|
||||
it('Detects group with toggle', () => {
|
||||
it("Detects group with toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'group.bla',
|
||||
state: 'on',
|
||||
entity_id: "group.bla",
|
||||
state: "on",
|
||||
};
|
||||
assert.isTrue(canToggleState(hass, stateObj));
|
||||
});
|
||||
|
||||
it('Detects group without toggle', () => {
|
||||
it("Detects group without toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'group.devices',
|
||||
state: 'home',
|
||||
entity_id: "group.devices",
|
||||
state: "home",
|
||||
};
|
||||
assert.isFalse(canToggleState(hass, stateObj));
|
||||
});
|
||||
|
||||
it('Detects climate with toggle', () => {
|
||||
it("Detects climate with toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'climate.bla',
|
||||
entity_id: "climate.bla",
|
||||
attributes: {
|
||||
supported_features: 4096,
|
||||
},
|
||||
@@ -46,9 +46,9 @@ describe('canToggleState', () => {
|
||||
assert.isTrue(canToggleState(hass, stateObj));
|
||||
});
|
||||
|
||||
it('Detects climate without toggle', () => {
|
||||
it("Detects climate without toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'climate.bla',
|
||||
entity_id: "climate.bla",
|
||||
};
|
||||
assert.isFalse(canToggleState(hass, stateObj));
|
||||
});
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import computeDomain from '../../../src/common/entity/compute_domain';
|
||||
import computeDomain from "../../../src/common/entity/compute_domain";
|
||||
|
||||
describe('computeDomain', () => {
|
||||
it('Returns domains', () => {
|
||||
assert.equal(computeDomain('sensor.bla'), 'sensor');
|
||||
assert.equal(computeDomain('switch.bla'), 'switch');
|
||||
assert.equal(computeDomain('light.bla'), 'light');
|
||||
assert.equal(computeDomain('persistent_notification.bla'), 'persistent_notification');
|
||||
describe("computeDomain", () => {
|
||||
it("Returns domains", () => {
|
||||
assert.equal(computeDomain("sensor.bla"), "sensor");
|
||||
assert.equal(computeDomain("switch.bla"), "switch");
|
||||
assert.equal(computeDomain("light.bla"), "light");
|
||||
assert.equal(
|
||||
computeDomain("persistent_notification.bla"),
|
||||
"persistent_notification"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,108 +1,125 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import computeStateDisplay from '../../../src/common/entity/compute_state_display';
|
||||
import computeStateDisplay from "../../../src/common/entity/compute_state_display";
|
||||
|
||||
describe('computeStateDisplay', () => {
|
||||
const localize = function (message, ...args) {
|
||||
describe("computeStateDisplay", () => {
|
||||
const localize = function(message, ...args) {
|
||||
// Mock Localize function for testing
|
||||
return message + (args.length ? ': ' + args.join(',') : '');
|
||||
return message + (args.length ? ": " + args.join(",") : "");
|
||||
};
|
||||
|
||||
it('Localizes binary sensor defaults', () => {
|
||||
it("Localizes binary sensor defaults", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'binary_sensor.test',
|
||||
state: 'off',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "binary_sensor.test",
|
||||
state: "off",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.binary_sensor.default.off');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.binary_sensor.default.off"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes binary sensor device class', () => {
|
||||
it("Localizes binary sensor device class", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'binary_sensor.test',
|
||||
state: 'off',
|
||||
entity_id: "binary_sensor.test",
|
||||
state: "off",
|
||||
attributes: {
|
||||
device_class: 'moisture',
|
||||
device_class: "moisture",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.binary_sensor.moisture.off');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.binary_sensor.moisture.off"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes binary sensor invalid device class', () => {
|
||||
const altLocalize = function (message, ...args) {
|
||||
if (message === 'state.binary_sensor.invalid_device_class.off') return null;
|
||||
it("Localizes binary sensor invalid device class", () => {
|
||||
const altLocalize = function(message, ...args) {
|
||||
if (message === "state.binary_sensor.invalid_device_class.off")
|
||||
return null;
|
||||
return localize(message, ...args);
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'binary_sensor.test',
|
||||
state: 'off',
|
||||
entity_id: "binary_sensor.test",
|
||||
state: "off",
|
||||
attributes: {
|
||||
device_class: 'invalid_device_class',
|
||||
device_class: "invalid_device_class",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'state.binary_sensor.default.off');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"state.binary_sensor.default.off"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes sensor value with units', () => {
|
||||
it("Localizes sensor value with units", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: '123',
|
||||
entity_id: "sensor.test",
|
||||
state: "123",
|
||||
attributes: {
|
||||
unit_of_measurement: 'm',
|
||||
unit_of_measurement: "m",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), '123 m');
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, "en"), "123 m");
|
||||
});
|
||||
|
||||
it('Localizes unknown sensor value with units', () => {
|
||||
const altLocalize = function (message, ...args) {
|
||||
if (message === 'state.sensor.unknown') return null;
|
||||
it("Localizes unknown sensor value with units", () => {
|
||||
const altLocalize = function(message, ...args) {
|
||||
if (message === "state.sensor.unknown") return null;
|
||||
return localize(message, ...args);
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: 'unknown',
|
||||
entity_id: "sensor.test",
|
||||
state: "unknown",
|
||||
attributes: {
|
||||
unit_of_measurement: 'm',
|
||||
unit_of_measurement: "m",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'state.default.unknown');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"state.default.unknown"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes unavailable sensor value with units', () => {
|
||||
const altLocalize = function (message, ...args) {
|
||||
if (message === 'state.sensor.unavailable') return null;
|
||||
it("Localizes unavailable sensor value with units", () => {
|
||||
const altLocalize = function(message, ...args) {
|
||||
if (message === "state.sensor.unavailable") return null;
|
||||
return localize(message, ...args);
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: 'unavailable',
|
||||
entity_id: "sensor.test",
|
||||
state: "unavailable",
|
||||
attributes: {
|
||||
unit_of_measurement: 'm',
|
||||
unit_of_measurement: "m",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'state.default.unavailable');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes sensor value with component translation', () => {
|
||||
const altLocalize = function (message, ...args) {
|
||||
if (message !== 'component.sensor.state.custom_state') return null;
|
||||
it("Localizes sensor value with component translation", () => {
|
||||
const altLocalize = function(message, ...args) {
|
||||
if (message !== "component.sensor.state.custom_state") return null;
|
||||
return localize(message, ...args);
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: 'custom_state',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "sensor.test",
|
||||
state: "custom_state",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'component.sensor.state.custom_state');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"component.sensor.state.custom_state"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes input_datetime with full date time', () => {
|
||||
it("Localizes input_datetime with full date time", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'input_datetime.test',
|
||||
state: '123',
|
||||
entity_id: "input_datetime.test",
|
||||
state: "123",
|
||||
attributes: {
|
||||
has_date: true,
|
||||
has_time: true,
|
||||
@@ -114,13 +131,16 @@ describe('computeStateDisplay', () => {
|
||||
second: 13,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'November 18, 2017, 11:12 AM');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"November 18, 2017, 11:12 AM"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes input_datetime with date', () => {
|
||||
it("Localizes input_datetime with date", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'input_datetime.test',
|
||||
state: '123',
|
||||
entity_id: "input_datetime.test",
|
||||
state: "123",
|
||||
attributes: {
|
||||
has_date: true,
|
||||
has_time: false,
|
||||
@@ -132,13 +152,16 @@ describe('computeStateDisplay', () => {
|
||||
second: 13,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'November 18, 2017');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"November 18, 2017"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes input_datetime with time', () => {
|
||||
it("Localizes input_datetime with time", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'input_datetime.test',
|
||||
state: '123',
|
||||
entity_id: "input_datetime.test",
|
||||
state: "123",
|
||||
attributes: {
|
||||
has_date: false,
|
||||
has_time: true,
|
||||
@@ -150,79 +173,99 @@ describe('computeStateDisplay', () => {
|
||||
second: 13,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), '11:12 AM');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"11:12 AM"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes zwave ready', () => {
|
||||
it("Localizes zwave ready", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'zwave.test',
|
||||
state: 'ready',
|
||||
entity_id: "zwave.test",
|
||||
state: "ready",
|
||||
attributes: {
|
||||
query_stage: 'Complete',
|
||||
query_stage: "Complete",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.zwave.default.ready');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.zwave.default.ready"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes zwave initializing', () => {
|
||||
it("Localizes zwave initializing", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'zwave.test',
|
||||
state: 'initializing',
|
||||
entity_id: "zwave.test",
|
||||
state: "initializing",
|
||||
attributes: {
|
||||
query_stage: 'Probe',
|
||||
query_stage: "Probe",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.zwave.query_stage.initializing: query_stage,Probe');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.zwave.query_stage.initializing: query_stage,Probe"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes cover open', () => {
|
||||
it("Localizes cover open", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'cover.test',
|
||||
state: 'open',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "cover.test",
|
||||
state: "open",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.cover.open');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.cover.open"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes unavailable', () => {
|
||||
const altLocalize = function (message, ...args) {
|
||||
if (message === 'state.sensor.unavailable') return null;
|
||||
it("Localizes unavailable", () => {
|
||||
const altLocalize = function(message, ...args) {
|
||||
if (message === "state.sensor.unavailable") return null;
|
||||
return localize(message, ...args);
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: 'unavailable',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "sensor.test",
|
||||
state: "unavailable",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'state.default.unavailable');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"state.default.unavailable"
|
||||
);
|
||||
});
|
||||
|
||||
it('Localizes custom state', () => {
|
||||
const altLocalize = function () {
|
||||
it("Localizes custom state", () => {
|
||||
const altLocalize = function() {
|
||||
// No matches can be found
|
||||
return null;
|
||||
};
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
state: 'My Custom State',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "sensor.test",
|
||||
state: "My Custom State",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(altLocalize, stateObj, 'en'), 'My Custom State');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(altLocalize, stateObj, "en"),
|
||||
"My Custom State"
|
||||
);
|
||||
});
|
||||
|
||||
it('Only calculates state display once per immutable state object', () => {
|
||||
it("Only calculates state display once per immutable state object", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'cover.test',
|
||||
state: 'open',
|
||||
attributes: {
|
||||
},
|
||||
entity_id: "cover.test",
|
||||
state: "open",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.cover.open');
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.cover.open"
|
||||
);
|
||||
|
||||
stateObj.state = 'closing';
|
||||
assert.strictEqual(computeStateDisplay(localize, stateObj, 'en'), 'state.cover.open');
|
||||
stateObj.state = "closing";
|
||||
assert.strictEqual(
|
||||
computeStateDisplay(localize, stateObj, "en"),
|
||||
"state.cover.open"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import computeStateDomain from '../../../src/common/entity/compute_state_domain.js';
|
||||
import computeStateDomain from "../../../src/common/entity/compute_state_domain.js";
|
||||
|
||||
describe('computeStateDomain', () => {
|
||||
it('Detects sensor domain', () => {
|
||||
describe("computeStateDomain", () => {
|
||||
it("Detects sensor domain", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.test',
|
||||
entity_id: "sensor.test",
|
||||
};
|
||||
assert.strictEqual(computeStateDomain(stateObj), 'sensor');
|
||||
assert.strictEqual(computeStateDomain(stateObj), "sensor");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import assert from 'assert';
|
||||
import assert from "assert";
|
||||
|
||||
import extractViews from '../../../src/common/entity/extract_views.js';
|
||||
import extractViews from "../../../src/common/entity/extract_views.js";
|
||||
|
||||
import {
|
||||
createEntities,
|
||||
createView,
|
||||
} from './test_util';
|
||||
import { createEntities, createView } from "./test_util";
|
||||
|
||||
describe('extractViews', () => {
|
||||
it('should work', () => {
|
||||
describe("extractViews", () => {
|
||||
it("should work", () => {
|
||||
const entities = createEntities(10);
|
||||
const view1 = createView({ attributes: { order: 10 } });
|
||||
entities[view1.entity_id] = view1;
|
||||
@@ -17,8 +14,8 @@ describe('extractViews', () => {
|
||||
entities[view2.entity_id] = view2;
|
||||
|
||||
const view3 = createView({
|
||||
entity_id: 'group.default_view',
|
||||
attributes: { order: 8 }
|
||||
entity_id: "group.default_view",
|
||||
attributes: { order: 8 },
|
||||
});
|
||||
entities[view3.entity_id] = view3;
|
||||
|
||||
|
||||
@@ -1,36 +1,30 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import featureClassNames from '../../../src/common/entity/feature_class_names';
|
||||
import featureClassNames from "../../../src/common/entity/feature_class_names";
|
||||
|
||||
describe('featureClassNames', () => {
|
||||
describe("featureClassNames", () => {
|
||||
const classNames = {
|
||||
1: 'has-feature_a',
|
||||
2: 'has-feature_b',
|
||||
4: 'has-feature_c',
|
||||
8: 'has-feature_d',
|
||||
1: "has-feature_a",
|
||||
2: "has-feature_b",
|
||||
4: "has-feature_c",
|
||||
8: "has-feature_d",
|
||||
};
|
||||
|
||||
it('Skips null states', () => {
|
||||
it("Skips null states", () => {
|
||||
const stateObj = null;
|
||||
assert.strictEqual(
|
||||
featureClassNames(stateObj, classNames),
|
||||
''
|
||||
);
|
||||
assert.strictEqual(featureClassNames(stateObj, classNames), "");
|
||||
});
|
||||
|
||||
it('Matches no features', () => {
|
||||
it("Matches no features", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
supported_features: 64,
|
||||
},
|
||||
};
|
||||
assert.strictEqual(
|
||||
featureClassNames(stateObj, classNames),
|
||||
''
|
||||
);
|
||||
assert.strictEqual(featureClassNames(stateObj, classNames), "");
|
||||
});
|
||||
|
||||
it('Matches one feature', () => {
|
||||
it("Matches one feature", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
supported_features: 72,
|
||||
@@ -38,11 +32,11 @@ describe('featureClassNames', () => {
|
||||
};
|
||||
assert.strictEqual(
|
||||
featureClassNames(stateObj, classNames),
|
||||
'has-feature_d'
|
||||
"has-feature_d"
|
||||
);
|
||||
});
|
||||
|
||||
it('Matches two features', () => {
|
||||
it("Matches two features", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
supported_features: 73,
|
||||
@@ -50,7 +44,7 @@ describe('featureClassNames', () => {
|
||||
};
|
||||
assert.strictEqual(
|
||||
featureClassNames(stateObj, classNames),
|
||||
'has-feature_a has-feature_d'
|
||||
"has-feature_a has-feature_d"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
import assert from 'assert';
|
||||
import assert from "assert";
|
||||
|
||||
import getGroupEntities from '../../../src/common/entity/get_group_entities.js';
|
||||
import getGroupEntities from "../../../src/common/entity/get_group_entities.js";
|
||||
|
||||
import { createEntities, createGroup, entityMap } from './test_util';
|
||||
import { createEntities, createGroup, entityMap } from "./test_util";
|
||||
|
||||
describe('getGroupEntities', () => {
|
||||
it('works if all entities exist', () => {
|
||||
describe("getGroupEntities", () => {
|
||||
it("works if all entities exist", () => {
|
||||
const entities = createEntities(5);
|
||||
const entityIds = Object.keys(entities);
|
||||
|
||||
const group = createGroup({ attributes: { entity_id: entityIds.splice(0, 2) } });
|
||||
const group = createGroup({
|
||||
attributes: { entity_id: entityIds.splice(0, 2) },
|
||||
});
|
||||
|
||||
const groupEntities = entityMap(group.attributes.entity_id.map(ent => entities[ent]));
|
||||
const groupEntities = entityMap(
|
||||
group.attributes.entity_id.map((ent) => entities[ent])
|
||||
);
|
||||
assert.deepEqual(groupEntities, getGroupEntities(entities, group));
|
||||
});
|
||||
|
||||
@@ -24,7 +28,11 @@ describe('getGroupEntities', () => {
|
||||
entities[entityIds[1]],
|
||||
]);
|
||||
|
||||
const group = createGroup({ attributes: { entity_id: entityIds.splice(0, 2).concat('light.does_not_exist') } });
|
||||
const group = createGroup({
|
||||
attributes: {
|
||||
entity_id: entityIds.splice(0, 2).concat("light.does_not_exist"),
|
||||
},
|
||||
});
|
||||
|
||||
assert.deepEqual(groupEntities, getGroupEntities(entities, group));
|
||||
});
|
||||
|
||||
@@ -1,50 +1,61 @@
|
||||
import assert from 'assert';
|
||||
import assert from "assert";
|
||||
|
||||
import getViewEntities from '../../../src/common/entity/get_view_entities.js';
|
||||
import getViewEntities from "../../../src/common/entity/get_view_entities.js";
|
||||
|
||||
import {
|
||||
createEntities,
|
||||
createEntity,
|
||||
createGroup,
|
||||
createView,
|
||||
entityMap
|
||||
} from './test_util';
|
||||
entityMap,
|
||||
} from "./test_util";
|
||||
|
||||
describe('getViewEntities', () => {
|
||||
it('should work', () => {
|
||||
describe("getViewEntities", () => {
|
||||
it("should work", () => {
|
||||
const entities = createEntities(10);
|
||||
const entityIds = Object.keys(entities);
|
||||
|
||||
const group1 = createGroup({ attributes: { entity_id: entityIds.splice(0, 2) } });
|
||||
const group1 = createGroup({
|
||||
attributes: { entity_id: entityIds.splice(0, 2) },
|
||||
});
|
||||
entities[group1.entity_id] = group1;
|
||||
|
||||
const group2 = createGroup({ attributes: { entity_id: entityIds.splice(0, 3) } });
|
||||
const group2 = createGroup({
|
||||
attributes: { entity_id: entityIds.splice(0, 3) },
|
||||
});
|
||||
entities[group2.entity_id] = group2;
|
||||
|
||||
const view = createView({
|
||||
attributes: {
|
||||
entity_id: [group1.entity_id, group2.entity_id].concat(entityIds.splice(0, 2))
|
||||
}
|
||||
entity_id: [group1.entity_id, group2.entity_id].concat(
|
||||
entityIds.splice(0, 2)
|
||||
),
|
||||
},
|
||||
});
|
||||
|
||||
const expectedEntities = entityMap(view.attributes.entity_id.map(ent => entities[ent]));
|
||||
Object.assign(
|
||||
expectedEntities,
|
||||
entityMap(group1.attributes.entity_id.map(ent => entities[ent]))
|
||||
const expectedEntities = entityMap(
|
||||
view.attributes.entity_id.map((ent) => entities[ent])
|
||||
);
|
||||
Object.assign(
|
||||
expectedEntities,
|
||||
entityMap(group2.attributes.entity_id.map(ent => entities[ent]))
|
||||
entityMap(group1.attributes.entity_id.map((ent) => entities[ent]))
|
||||
);
|
||||
Object.assign(
|
||||
expectedEntities,
|
||||
entityMap(group2.attributes.entity_id.map((ent) => entities[ent]))
|
||||
);
|
||||
|
||||
assert.deepEqual(expectedEntities, getViewEntities(entities, view));
|
||||
});
|
||||
|
||||
it('should not include hidden entities inside groups', () => {
|
||||
it("should not include hidden entities inside groups", () => {
|
||||
const visibleEntity = createEntity({ attributes: { hidden: false } });
|
||||
const hiddenEntity = createEntity({ attributes: { hidden: true } });
|
||||
const group1 = createGroup({ attributes: { entity_id: [
|
||||
visibleEntity.entity_id, hiddenEntity.entity_id] } });
|
||||
const group1 = createGroup({
|
||||
attributes: {
|
||||
entity_id: [visibleEntity.entity_id, hiddenEntity.entity_id],
|
||||
},
|
||||
});
|
||||
|
||||
const entities = {
|
||||
[visibleEntity.entity_id]: visibleEntity,
|
||||
|
||||
@@ -1,37 +1,36 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import hasLocation from '../../../src/common/entity/has_location.js';
|
||||
import hasLocation from "../../../src/common/entity/has_location.js";
|
||||
|
||||
describe('hasLocation', () => {
|
||||
it('flags states with location', () => {
|
||||
describe("hasLocation", () => {
|
||||
it("flags states with location", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
latitude: 12.34,
|
||||
longitude: 12.34
|
||||
}
|
||||
longitude: 12.34,
|
||||
},
|
||||
};
|
||||
assert(hasLocation(stateObj));
|
||||
});
|
||||
it('does not flag states with only latitude', () => {
|
||||
it("does not flag states with only latitude", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
latitude: 12.34,
|
||||
}
|
||||
},
|
||||
};
|
||||
assert(!hasLocation(stateObj));
|
||||
});
|
||||
it('does not flag states with only longitude', () => {
|
||||
it("does not flag states with only longitude", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
longitude: 12.34
|
||||
}
|
||||
longitude: 12.34,
|
||||
},
|
||||
};
|
||||
assert(!hasLocation(stateObj));
|
||||
});
|
||||
it('does not flag states with no location', () => {
|
||||
it("does not flag states with no location", () => {
|
||||
const stateObj = {
|
||||
attributes: {
|
||||
}
|
||||
attributes: {},
|
||||
};
|
||||
assert(!hasLocation(stateObj));
|
||||
});
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import assert from 'assert';
|
||||
import assert from "assert";
|
||||
|
||||
import splitByGroups from '../../../src/common/entity/split_by_groups.js';
|
||||
import splitByGroups from "../../../src/common/entity/split_by_groups.js";
|
||||
|
||||
import { createEntities, createGroup, entityMap } from './test_util';
|
||||
import { createEntities, createGroup, entityMap } from "./test_util";
|
||||
|
||||
describe('splitByGroups', () => {
|
||||
it('splitByGroups splits correctly', () => {
|
||||
describe("splitByGroups", () => {
|
||||
it("splitByGroups splits correctly", () => {
|
||||
const entities = createEntities(7);
|
||||
const entityIds = Object.keys(entities);
|
||||
|
||||
@@ -26,11 +26,13 @@ describe('splitByGroups', () => {
|
||||
entities[group2.entity_id] = group2;
|
||||
|
||||
const result = splitByGroups(entities);
|
||||
result.groups.sort((gr1, gr2) => gr1.attributes.order - gr2.attributes.order);
|
||||
result.groups.sort(
|
||||
(gr1, gr2) => gr1.attributes.order - gr2.attributes.order
|
||||
);
|
||||
|
||||
const expected = {
|
||||
groups: [group2, group1],
|
||||
ungrouped: entityMap(entityIds.map(ent => entities[ent])),
|
||||
ungrouped: entityMap(entityIds.map((ent) => entities[ent])),
|
||||
};
|
||||
|
||||
assert.deepEqual(expected, result);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import stateCardType from '../../../src/common/entity/state_card_type.js';
|
||||
import stateCardType from "../../../src/common/entity/state_card_type.js";
|
||||
|
||||
describe('stateCardType', () => {
|
||||
describe("stateCardType", () => {
|
||||
const hass = {
|
||||
services: {
|
||||
light: {
|
||||
@@ -12,42 +12,42 @@ describe('stateCardType', () => {
|
||||
},
|
||||
};
|
||||
|
||||
it('Returns display for unavailable states', () => {
|
||||
it("Returns display for unavailable states", () => {
|
||||
const stateObj = {
|
||||
state: 'unavailable',
|
||||
state: "unavailable",
|
||||
};
|
||||
assert.strictEqual(stateCardType(hass, stateObj), 'display');
|
||||
assert.strictEqual(stateCardType(hass, stateObj), "display");
|
||||
});
|
||||
|
||||
it('Returns media_player for media_player states', () => {
|
||||
it("Returns media_player for media_player states", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'media_player.bla',
|
||||
entity_id: "media_player.bla",
|
||||
};
|
||||
assert.strictEqual(stateCardType(hass, stateObj), 'media_player');
|
||||
assert.strictEqual(stateCardType(hass, stateObj), "media_player");
|
||||
});
|
||||
|
||||
it('Returns toggle for states that can toggle', () => {
|
||||
it("Returns toggle for states that can toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'light.bla',
|
||||
entity_id: "light.bla",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(stateCardType(hass, stateObj), 'toggle');
|
||||
assert.strictEqual(stateCardType(hass, stateObj), "toggle");
|
||||
});
|
||||
|
||||
it('Returns display for states with hidden control', () => {
|
||||
it("Returns display for states with hidden control", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'light.bla',
|
||||
entity_id: "light.bla",
|
||||
attributes: {
|
||||
control: 'hidden',
|
||||
control: "hidden",
|
||||
},
|
||||
};
|
||||
assert.strictEqual(stateCardType(hass, stateObj), 'display');
|
||||
assert.strictEqual(stateCardType(hass, stateObj), "display");
|
||||
});
|
||||
|
||||
it('Returns display for entities that cannot toggle', () => {
|
||||
it("Returns display for entities that cannot toggle", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'sensor.bla',
|
||||
entity_id: "sensor.bla",
|
||||
};
|
||||
assert.strictEqual(stateCardType(hass, stateObj), 'display');
|
||||
assert.strictEqual(stateCardType(hass, stateObj), "display");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
import { assert } from 'chai';
|
||||
import { assert } from "chai";
|
||||
|
||||
import stateMoreInfoType from '../../../src/common/entity/state_more_info_type.js';
|
||||
import stateMoreInfoType from "../../../src/common/entity/state_more_info_type.js";
|
||||
|
||||
describe('stateMoreInfoType', () => {
|
||||
it('Returns media_player for media_player states', () => {
|
||||
describe("stateMoreInfoType", () => {
|
||||
it("Returns media_player for media_player states", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'media_player.bla',
|
||||
entity_id: "media_player.bla",
|
||||
};
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), 'media_player');
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), "media_player");
|
||||
});
|
||||
|
||||
it('Returns hidden for input_select states', () => {
|
||||
it("Returns hidden for input_select states", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'input_select.bla',
|
||||
entity_id: "input_select.bla",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), 'hidden');
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), "hidden");
|
||||
});
|
||||
|
||||
it('Returns default for switch states', () => {
|
||||
it("Returns default for switch states", () => {
|
||||
const stateObj = {
|
||||
entity_id: 'switch.bla',
|
||||
entity_id: "switch.bla",
|
||||
attributes: {},
|
||||
};
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), 'default');
|
||||
assert.strictEqual(stateMoreInfoType(stateObj), "default");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ let mockState = 1;
|
||||
export function createEntity(entity) {
|
||||
mockState++;
|
||||
entity.entity_id = entity.entity_id || `test.test_${mockState}`;
|
||||
entity.last_changed = entity.last_changed || (new Date()).toISOString();
|
||||
entity.last_changed = entity.last_changed || new Date().toISOString();
|
||||
entity.last_updated = entity.last_updated || entity.last_changed;
|
||||
entity.attributes = entity.attributes || {};
|
||||
return entity;
|
||||
@@ -13,9 +13,9 @@ export function createEntity(entity) {
|
||||
export function createGroup(entity) {
|
||||
mockState++;
|
||||
entity.entity_id = entity.entity_id || `group.test_${mockState}`;
|
||||
entity.state = entity.state || 'on';
|
||||
entity.state = entity.state || "on";
|
||||
entity.attributes = entity.attributes || {};
|
||||
if (!('order' in entity.attributes)) {
|
||||
if (!("order" in entity.attributes)) {
|
||||
entity.attributes.order = 0;
|
||||
}
|
||||
return createEntity(entity);
|
||||
@@ -34,7 +34,7 @@ export function createLightEntity(isOn) {
|
||||
}
|
||||
return createEntity({
|
||||
entity_id: `light.mock_${mockState}`,
|
||||
state: isOn ? 'on' : 'off',
|
||||
state: isOn ? "on" : "off",
|
||||
});
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ export function createEntities(count) {
|
||||
|
||||
export function entityMap(entityList) {
|
||||
const entities = {};
|
||||
entityList.forEach((entity) => { entities[entity.entity_id] = entity; });
|
||||
entityList.forEach((entity) => {
|
||||
entities[entity.entity_id] = entity;
|
||||
});
|
||||
return entities;
|
||||
}
|
||||
|
||||
@@ -1,43 +1,52 @@
|
||||
import { assert } from 'chai';
|
||||
import sinon from 'sinon';
|
||||
import { assert } from "chai";
|
||||
import sinon from "sinon";
|
||||
|
||||
import timerTimeRemaining from '../../../src/common/entity/timer_time_remaining.js';
|
||||
import timerTimeRemaining from "../../../src/common/entity/timer_time_remaining.js";
|
||||
|
||||
describe('timerTimeRemaining', () => {
|
||||
it('works with idle timers', () => {
|
||||
assert.strictEqual(timerTimeRemaining({
|
||||
state: 'idle',
|
||||
attributes: {
|
||||
remaining: '0:01:05'
|
||||
}
|
||||
}), 65);
|
||||
describe("timerTimeRemaining", () => {
|
||||
it("works with idle timers", () => {
|
||||
assert.strictEqual(
|
||||
timerTimeRemaining({
|
||||
state: "idle",
|
||||
attributes: {
|
||||
remaining: "0:01:05",
|
||||
},
|
||||
}),
|
||||
65
|
||||
);
|
||||
});
|
||||
|
||||
it('works with paused timers', () => {
|
||||
assert.strictEqual(timerTimeRemaining({
|
||||
state: 'paused',
|
||||
attributes: {
|
||||
remaining: '0:01:05'
|
||||
}
|
||||
}), 65);
|
||||
it("works with paused timers", () => {
|
||||
assert.strictEqual(
|
||||
timerTimeRemaining({
|
||||
state: "paused",
|
||||
attributes: {
|
||||
remaining: "0:01:05",
|
||||
},
|
||||
}),
|
||||
65
|
||||
);
|
||||
});
|
||||
|
||||
describe('active timers', () => {
|
||||
describe("active timers", () => {
|
||||
let clock;
|
||||
beforeEach(() => {
|
||||
clock = sinon.useFakeTimers(new Date('2018-01-17T16:15:30Z'));
|
||||
clock = sinon.useFakeTimers(new Date("2018-01-17T16:15:30Z"));
|
||||
});
|
||||
afterEach(() => {
|
||||
clock.restore();
|
||||
});
|
||||
it('works', () => {
|
||||
assert.strictEqual(timerTimeRemaining({
|
||||
state: 'active',
|
||||
attributes: {
|
||||
remaining: '0:01:05'
|
||||
},
|
||||
last_changed: '2018-01-17T16:15:12Z',
|
||||
}), 47);
|
||||
it("works", () => {
|
||||
assert.strictEqual(
|
||||
timerTimeRemaining({
|
||||
state: "active",
|
||||
attributes: {
|
||||
remaining: "0:01:05",
|
||||
},
|
||||
last_changed: "2018-01-17T16:15:12Z",
|
||||
}),
|
||||
47
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,53 +1,53 @@
|
||||
import assert from 'assert';
|
||||
import assert from "assert";
|
||||
|
||||
import parseAspectRatio from '../../../src/common/util/parse-aspect-ratio.js';
|
||||
import parseAspectRatio from "../../../src/common/util/parse-aspect-ratio.js";
|
||||
|
||||
describe('parseAspectRatio', () => {
|
||||
describe("parseAspectRatio", () => {
|
||||
const ratio16by9 = { w: 16, h: 9 };
|
||||
const ratio178 = { w: 1.78, h: 1 };
|
||||
|
||||
it('Parses 16x9', () => {
|
||||
const r = parseAspectRatio('16x9');
|
||||
it("Parses 16x9", () => {
|
||||
const r = parseAspectRatio("16x9");
|
||||
assert.deepEqual(r, ratio16by9);
|
||||
});
|
||||
|
||||
it('Parses 16:9', () => {
|
||||
const r = parseAspectRatio('16:9');
|
||||
it("Parses 16:9", () => {
|
||||
const r = parseAspectRatio("16:9");
|
||||
assert.deepEqual(r, ratio16by9);
|
||||
});
|
||||
|
||||
it('Parses 1.78x1', () => {
|
||||
const r = parseAspectRatio('1.78x1');
|
||||
it("Parses 1.78x1", () => {
|
||||
const r = parseAspectRatio("1.78x1");
|
||||
assert.deepEqual(r, ratio178);
|
||||
});
|
||||
|
||||
it('Parses 1.78:1', () => {
|
||||
const r = parseAspectRatio('1.78:1');
|
||||
it("Parses 1.78:1", () => {
|
||||
const r = parseAspectRatio("1.78:1");
|
||||
assert.deepEqual(r, ratio178);
|
||||
});
|
||||
|
||||
it('Parses 1.78', () => {
|
||||
const r = parseAspectRatio('1.78');
|
||||
it("Parses 1.78", () => {
|
||||
const r = parseAspectRatio("1.78");
|
||||
assert.deepEqual(r, ratio178);
|
||||
});
|
||||
|
||||
it('Skips null states', () => {
|
||||
it("Skips null states", () => {
|
||||
const r = parseAspectRatio(null);
|
||||
assert.equal(r, null);
|
||||
});
|
||||
|
||||
it('Skips empty states', () => {
|
||||
const r = parseAspectRatio(' ');
|
||||
it("Skips empty states", () => {
|
||||
const r = parseAspectRatio(" ");
|
||||
assert.equal(r, null);
|
||||
});
|
||||
|
||||
it('Skips invalid input', () => {
|
||||
const r = parseAspectRatio('mary had a little lamb');
|
||||
it("Skips invalid input", () => {
|
||||
const r = parseAspectRatio("mary had a little lamb");
|
||||
assert.equal(r, null);
|
||||
});
|
||||
|
||||
it('Skips invalid, but close input', () => {
|
||||
const r = parseAspectRatio('mary:lamb');
|
||||
it("Skips invalid, but close input", () => {
|
||||
const r = parseAspectRatio("mary:lamb");
|
||||
assert.equal(r, null);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user