* Move computeDomain and format functions to js * Add tests for computeStateDisplay * Always recalculate state display * Remove LANGUAGE from hassUtils object * Move AppLocalizeBehavior import to mixins * Import mixins to state-card-display * Safety check on computeStateDisplay * Don't store computed domains on stateObj * Integration tests for state-card-display * Include extractDomain code in polymer repo * Remove util function null checking * Dont render test element without hass and stateObj * Revert "Don't store computed domains on stateObj" This reverts commit e3509d71823ff5e42a4dcf4849a98c5bb6cb391c. * Revert "Always recalculate state display" This reverts commit 27c24e2694ee6f7c147782532268b3a67998d49b.
100 lines
3.2 KiB
HTML
100 lines
3.2 KiB
HTML
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
|
|
<script src="../../web-component-tester/browser.js"></script>
|
|
<link rel="import" href="../src/components/entity/state-info.html">
|
|
</head>
|
|
<body>
|
|
<test-fixture id="stateInfoSecondaryLine">
|
|
<template>
|
|
<state-info secondary-line><my-elem>text</my-elem></state-info>
|
|
</template>
|
|
</test-fixture>
|
|
<test-fixture id="stateInfo">
|
|
<template>
|
|
<state-info></state-info>
|
|
</template>
|
|
</test-fixture>
|
|
|
|
<script>
|
|
function lightOrShadow(elem, selector) {
|
|
return elem.shadowRoot ?
|
|
elem.shadowRoot.querySelector(selector) :
|
|
elem.querySelector(selector);
|
|
}
|
|
|
|
suite('state-info', function() {
|
|
var si;
|
|
|
|
setup(function() {
|
|
si = fixture('stateInfo');
|
|
});
|
|
|
|
test('default values', function() {
|
|
assert.isUndefined(si.stateObj);
|
|
assert.isUndefined(si.inDialog);
|
|
});
|
|
|
|
test('has state-badge', function() {
|
|
assert.isOk(lightOrShadow(si, 'state-badge'));
|
|
});
|
|
|
|
test('stateObj', function(done) {
|
|
si.stateObj = {entity_id: 'light.demo', last_changed: '2017-01-01T00:00:00+00:00', state: 'off', attributes: {friendly_name: 'Name'}};
|
|
flush(function() {
|
|
var stateBadge = lightOrShadow(si, 'state-badge');
|
|
assert.isOk(stateBadge);
|
|
assert.deepEqual(stateBadge.stateObj, si.stateObj);
|
|
|
|
var name = lightOrShadow(si, '.name');
|
|
assert.isOk(name, '.name missing');
|
|
assert.equal(name.textContent, 'Name');
|
|
assert.equal(getComputedStyle(name).lineHeight, '40px');
|
|
|
|
assert.isNotOk(lightOrShadow(si, 'ha-relative-time'));
|
|
done();
|
|
});
|
|
});
|
|
|
|
test('relative time', function(done) {
|
|
si.stateObj = {entity_id: 'light.demo', last_changed: '2017-01-01T00:00:00+00:00', state: 'off', attributes: {friendly_name: 'Name'}};
|
|
si.inDialog = true;
|
|
flush(function() {
|
|
var relativeTime = lightOrShadow(si, 'ha-relative-time');
|
|
var name = lightOrShadow(si, '.name');
|
|
|
|
assert.isOk(relativeTime);
|
|
assert.notEqual(relativeTime.textContent, 'never');
|
|
assert.notEqual(relativeTime.textContent, '');
|
|
|
|
assert.isOk(name);
|
|
assert.equal(getComputedStyle(name).lineHeight, '20px');
|
|
|
|
si.stateObj = {entity_id: 'light.demo', state: 'off', attributes: {friendly_name: 'Name'}};
|
|
flush(function() {
|
|
assert.equal(relativeTime.textContent, 'never');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
|
|
test('secondary line', function(done) {
|
|
si = fixture('stateInfoSecondaryLine');
|
|
si.stateObj = {entity_id: 'light.demo', last_changed: '2017-01-01T00:00:00+00:00', state: 'off', attributes: {friendly_name: 'Name'}};
|
|
si.inDialog = false;
|
|
flush(function() {
|
|
var name = lightOrShadow(si, '.name');
|
|
assert.isOk(name);
|
|
assert.equal(getComputedStyle(name).lineHeight, '20px');
|
|
var content = si.getElementsByTagName('my-elem')[0];
|
|
assert.isOk(content);
|
|
assert.equal(content.textContent, 'text');
|
|
done();
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|