Skip to content

Commit

Permalink
Replaces integration tests with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xcambar authored and mathieupoteriepeopledoc committed Sep 5, 2018
1 parent 009c3c0 commit 6014bf7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 54 deletions.
2 changes: 1 addition & 1 deletion addon/utils/bind-data-test-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function bindDataTestAttributes(component) {
let message = `ember-test-selectors could not bind data-test-* properties on ${component} ` +
`automatically because tagName is empty.`;

assert(message, tagName!== '', {
assert(message, tagName !== '', {
id: 'ember-test-selectors.empty-tag-name',
});

Expand Down
34 changes: 0 additions & 34 deletions tests/integration/bind-data-test-attributes-test.js

This file was deleted.

61 changes: 42 additions & 19 deletions tests/unit/utils/bind-data-test-attributes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ module('Unit | Utility | bind data test attributes');

test('it adds missing attributeBindings array', function(assert) {
let Fixture = EmberObject.extend({
'data-test-from-factory': 'foo',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
'data-test-from-invocation': 'bar',
'data-test-from-invocation': 'bar'
});

assert.deepEqual(instance.get('attributeBindings'), undefined);

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'),
['data-test-from-invocation', 'data-test-from-factory']);
assert.deepEqual(instance.get('attributeBindings'), [
'data-test-from-invocation',
'data-test-from-factory'
]);
});

test('it adds to existing attributeBindings array', function(assert) {
Expand All @@ -28,18 +30,22 @@ test('it adds to existing attributeBindings array', function(assert) {
foo: 1,
bar: 2,

'data-test-from-factory': 'foo',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
'data-test-from-invocation': 'bar',
'data-test-from-invocation': 'bar'
});

assert.deepEqual(instance.get('attributeBindings'), ['foo', 'bar']);

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'),
['foo', 'bar', 'data-test-from-invocation', 'data-test-from-factory']);
assert.deepEqual(instance.get('attributeBindings'), [
'foo',
'bar',
'data-test-from-invocation',
'data-test-from-factory'
]);
});

test('it converts existing attributeBindings string to array', function(assert) {
Expand All @@ -48,44 +54,49 @@ test('it converts existing attributeBindings string to array', function(assert)

foo: 1,

'data-test-from-factory': 'foo',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
'data-test-from-invocation': 'bar',
'data-test-from-invocation': 'bar'
});

assert.deepEqual(instance.get('attributeBindings'), 'foo');

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'),
['foo', 'data-test-from-invocation', 'data-test-from-factory']);
assert.deepEqual(instance.get('attributeBindings'), [
'foo',
'data-test-from-invocation',
'data-test-from-factory'
]);
});

test('it only adds data-test-* properties', function(assert) {
let Fixture = EmberObject.extend({
foo: 1,
bar: 2,

'data-test-from-factory': 'foo',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
baz: 3,

'data-test-from-invocation': 'bar',
'data-test-from-invocation': 'bar'
});

assert.deepEqual(instance.get('attributeBindings'), undefined);

bindDataTestAttributes(instance);

assert.deepEqual(instance.get('attributeBindings'),
['data-test-from-invocation', 'data-test-from-factory']);
assert.deepEqual(instance.get('attributeBindings'), [
'data-test-from-invocation',
'data-test-from-factory'
]);
});

test('it does not add a data-test property', function(assert) {
let Fixture = EmberObject.extend({
'data-test': 'foo',
'data-test': 'foo'
});
let instance = Fixture.create();

Expand All @@ -104,12 +115,12 @@ test('it skips if attributeBindings is a computed property', function(assert) {

foo: 5,

'data-test-from-factory': 'foo',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
prop: 'foo',

'data-test-from-invocation': 'bar',
'data-test-from-invocation': 'bar'
});

assert.deepEqual(instance.get('attributeBindings'), ['foo']);
Expand All @@ -118,3 +129,15 @@ test('it skips if attributeBindings is a computed property', function(assert) {

assert.deepEqual(instance.get('attributeBindings'), ['foo']);
});

test('it breaks if tagName is empty', function(assert) {
let Fixture = EmberObject.extend({
tagName: '',
'data-test-from-factory': 'foo'
});
let instance = Fixture.create({
'data-test-from-invocation': 'bar'
});

assert.throws(() => bindDataTestAttributes(instance));
});

0 comments on commit 6014bf7

Please sign in to comment.