-
Notifications
You must be signed in to change notification settings - Fork 40
/
bind-data-test-attributes.js
47 lines (37 loc) · 1.4 KB
/
bind-data-test-attributes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Ember from 'ember';
const TEST_SELECTOR_PREFIX = /data-test-.*/;
export default function bindDataTestAttributes(component) {
let dataTestProperties = [];
for (let attr in component) {
if (TEST_SELECTOR_PREFIX.test(attr)) {
dataTestProperties.push(attr);
}
}
if (dataTestProperties.length === 0) {
return;
}
let tagName = component.get('tagName');
if (tagName === '') {
let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty.`;
return Ember.warn(message, false, {
id: 'ember-test-selectors.empty-tag-name',
});
}
let computedBindings = component.attributeBindings && component.attributeBindings.isDescriptor;
if (computedBindings) {
let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because attributeBindings is a computed property.`;
return Ember.warn(message, false, {
id: 'ember-test-selectors.computed-attribute-bindings',
});
}
let attributeBindings = component.getWithDefault('attributeBindings', []);
if (!Ember.isArray(attributeBindings)) {
attributeBindings = [attributeBindings];
} else {
attributeBindings = attributeBindings.slice();
}
dataTestProperties.forEach(it => attributeBindings.push(it));
component.set('attributeBindings', attributeBindings);
}