1
0
mirror of https://github.com/home-assistant/frontend.git synced 2025-12-20 02:38:53 +00:00
Files
frontend/test-mocha/common/util/attribute_class_names_test.js
Adam Mills 70c082716f MVP tests for hass-util.html (#629)
* MVP tests for hass-util.html

* MVP util.js to allow individual JS function export

* Use mocha to unit test js logic

* Isolate mocha test directory

* Move mocha opts to separate file

* Default export of util function

* Use reify for mocha tests instead of babel
2017-11-15 21:42:54 -08:00

54 lines
1.2 KiB
JavaScript

import attributeClassNames from '../../../js/common/util/attribute_class_names';
const assert = require('assert');
describe('attributeClassNames', function() {
const attrs = ['mock_attr1', 'mock_attr2'];
it('null state', function() {
const stateObj = null;
assert.strictEqual(
attributeClassNames(stateObj, attrs),
'');
});
it('matches no attrbutes', function() {
const stateObj = {
attributes: {
other_attr_1: 1,
other_attr_2: 2,
},
};
assert.strictEqual(
attributeClassNames(stateObj, attrs),
'');
});
it('matches one attrbute', function() {
const stateObj = {
attributes: {
other_attr_1: 1,
other_attr_2: 2,
mock_attr1: 3,
},
};
assert.strictEqual(
attributeClassNames(stateObj, attrs),
'has-mock_attr1');
});
it('matches two attrbutes', function() {
const stateObj = {
attributes: {
other_attr_1: 1,
other_attr_2: 2,
mock_attr1: 3,
mock_attr2: null,
},
};
assert.strictEqual(
attributeClassNames(stateObj, attrs),
'has-mock_attr1 has-mock_attr2');
});
});