ha-frontend-cdce8p/test/state-info-test.html
Paulus Schoutsen a4afc2e37a
Polymer 3 modulize (#1154)
* Version bump to 20180510.1

* Fix hass util

* Fix translations

* Bye paper-time-input

* Add webpack config

* Add webpack to package.json

* Fix translation import

* Disable web animations polyfill bad import

* Disable importHref import

* Update webpack config to build authorize.js

* Build translations json

* Build frontend correctly

* Run eslint --fix

* Load markdown JS on demand (#1155)

* Add HTML imports (#1160)

* Fix localize (#1161)

* Fix Roboto in build (#1162)

* Load web animations polyfill (#1163)

* P3: Fix chart js (#1164)

* P3: Fix Chart JS

* Update timeline package

* P3: panel resolver (#1165)

* WIP

* Initial importing of panels

* Fix panel resolver

* Fix automation and script editor (#1166)

* Expose Polymer and Polymer.Element on window (#1167)

* Remove unused import

* eslint --fix

* Es5 build (#1168)

* Build for ES5

* Fix build_frontend

* Remove stale comment

* Migrate to use paper-material-styles (#1170)

* Send parsed date to history/logbook (#1171)

* Fork app storage behavior (#1172)

* Add paper input with type time (#1173)

* Fix authorize

* Lint

* Sort imports

* Lint

* Remove eslint-html

* Do not lint authorize.html

* Fix polymer lint

* Try chrome 62 for wct

* P3: Add patched iconset (#1175)

* Add patched iconset

* Lint

* Test with latest Chrome again

* Use less window.hassUtil

* Teporarily use my fecha fork

* Import correct intl.messageFormat

* Update wct-browser-legacy to 1.0.0

* Include polyfill in right place

* Fix IntlMessageFormat

* Fix test not having a global scope

* Rollup <_<

* Fork app-localize-behavior

* Disable wct tests

* Lint
2018-05-15 13:31:47 -04:00

101 lines
3.1 KiB
HTML

<!doctype html>
<html>
<head>
<script src="../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
<script src="../node_modules/wct-browser-legacy/browser.js"></script>
<script type="module" src="../src/components/entity/state-info.js"></script>
</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 type="module">
import '../src/components/entity/state-info.js';
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>