ha-frontend-cdce8p/test/state-info-test.html
Andrey 35c086a594 More tests for state-info.html (#256)
* Remove andrey-git keys. Add Android 7.0 emulator

* Use Chrome on Android 7.0

* Try a test that should fail on shadow dom.

* Change test

* try lightOrShadow

* More tests
2017-04-08 06:05:13 -07:00

78 lines
2.4 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="state-info">
<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('state-info');
window.HAWS = {};
window.HAWS.extractDomain = function (entityId) {
return entityId.substr(0, entityId.indexOf('.'));
};
});
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.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');
assert.isOk(relativeTime);
assert.notEqual(relativeTime.textContent, 'never');
assert.notEqual(relativeTime.textContent, '');
si.stateObj = {entity_id: 'light.demo', state: 'off', attributes: {friendly_name: 'Name'}};
flush(function() {
assert.equal(relativeTime.textContent, 'never');
done();
});
});
});
});
</script>
</body>
</html>