1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00

Compute state display tests (#643)

* 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 e3509d7182.

* Revert "Always recalculate state display"

This reverts commit 27c24e2694.
This commit is contained in:
Adam Mills
2017-11-21 00:46:36 -05:00
committed by Paulus Schoutsen
parent 7e77a7c32c
commit 3412edb843
20 changed files with 476 additions and 141 deletions

View File

@@ -11,6 +11,8 @@
WCT.loadSuites([
'state-info-test.html?dom=shadow',
'state-info-test.html?dom=shady',
'state-card-display-test.html?dom=shadow',
'state-card-display-test.html?dom=shady',
]);
</script>
</body></html>

View File

@@ -0,0 +1,64 @@
<!doctype html>
<html>
<head>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<!--
Temporarily load core.js here so window.HAWS is available. We can remove
this once hass-util includes the helper function directly.
-->
<script src="../build/core.js"></script>
<link rel="import" href="../src/state-summary/state-card-display.html">
</head>
<body>
<test-fixture id="stateCardDisplay">
<template>
<div />
</template>
</test-fixture>
<script>
function lightOrShadow(elem, selector) {
return elem.shadowRoot ?
elem.shadowRoot.querySelector(selector) :
elem.querySelector(selector);
}
suite('state-card-display', function() {
let wrapper;
let card;
setup(function() {
wrapper = fixture('stateCardDisplay');
card = new StateCardDisplay();
card.stateObj = {
entity_id: 'binary_sensor.demo',
state: 'off',
attributes: {
device_class: 'moisture',
},
};
card.hass = {
language: 'en',
resources: {
'en': {
'state.binary_sensor.moisture.off': 'Mock Off Text',
},
},
};
wrapper.appendChild(card);
});
test('state display text', function(done) {
flush(function() {
const stateDiv = lightOrShadow(card, '.state');
assert.isOk(stateDiv);
assert.deepEqual(stateDiv.innerText, 'Mock Off Text');
done();
});
});
});
</script>
</body>
</html>

View File

@@ -29,10 +29,6 @@
setup(function() {
si = fixture('stateInfo');
window.HAWS = {};
window.HAWS.extractDomain = function (entityId) {
return entityId.substr(0, entityId.indexOf('.'));
};
});
test('default values', function() {