Skip to content

Commit

Permalink
Merge pull request #10468 from lazybensch/master
Browse files Browse the repository at this point in the history
[REFACTOR] dry view tests
  • Loading branch information
rwjblue committed Aug 3, 2015
2 parents a49c2eb + ec7ab94 commit 1873a12
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 172 deletions.
2 changes: 1 addition & 1 deletion packages/ember-htmlbars/tests/hooks/text_node_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { runAppend, runDestroy } from 'ember-runtime/tests/utils';

var view;

QUnit.module('ember-htmlbars: hooks/text_node_test', {
QUnit.module('ember-htmlbars: textNode hook', {
teardown() {
runDestroy(view);
}
Expand Down
66 changes: 60 additions & 6 deletions packages/ember-views/tests/views/container_view_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import viewKeyword from 'ember-htmlbars/keywords/view';
var trim = jQuery.trim;
var container, registry, view, otherContainer, originalViewKeyword;

QUnit.module('ember-views/views/container_view_test', {
QUnit.module('Ember.ContainerView', {
setup() {
originalViewKeyword = registerKeyword('view', viewKeyword);
registry = new Registry();
Expand Down Expand Up @@ -456,13 +456,35 @@ QUnit.test('if a ContainerView starts with a currentView and then a different cu
equal(trim(container.$().text()), 'This is the tertiary view.', 'should render its child');
});

QUnit.test('should be able to modify childViews many times during an run loop', function () {
container = ContainerView.create();
var child, count;
QUnit.module('Ember.ContainerView - modify childViews', {
setup() {
originalViewKeyword = registerKeyword('view', viewKeyword);
registry = new Registry();
container = ContainerView.create();

run(function() {
container.appendTo('#qunit-fixture');
});
run(function() {
container.appendTo('#qunit-fixture');
});

count = 0;
child = View.create({
template: function () {
count++;
return 'child';
}
});
},
teardown() {
run(function() {
container.destroy();
if (view) { view.destroy(); }
if (otherContainer) { otherContainer.destroy(); }
});
}
});

QUnit.test('should be able to modify childViews many times during a run loop', function () {
var one = View.create({
template: compile('one')
});
Expand Down Expand Up @@ -506,6 +528,24 @@ QUnit.test('should be able to modify childViews then rerender the ContainerView
equal(trim(container.$().text()), 'child');
});

QUnit.test('should be able to modify childViews then remove the ContainerView in same run loop', function () {
run(function() {
container.pushObject(child);
container.remove();
});

equal(count, 0, 'did not render child');
});

QUnit.test('should be able to modify childViews then destroy the ContainerView in same run loop', function () {
run(function() {
container.pushObject(child);
container.destroy();
});

equal(count, 0, 'did not render child');
});

QUnit.test('should be able to modify childViews then rerender then modify again the ContainerView in same run loop', function () {
container = ContainerView.create();

Expand Down Expand Up @@ -572,6 +612,20 @@ QUnit.test('should be able to modify childViews then rerender again the Containe
equal(trim(container.$().text()), 'onetwo');
});

QUnit.module('Ember.ContainerView', {
setup() {
originalViewKeyword = registerKeyword('view', viewKeyword);
registry = new Registry();
},
teardown() {
run(function() {
container.destroy();
if (view) { view.destroy(); }
if (otherContainer) { otherContainer.destroy(); }
});
}
});

QUnit.test('should invalidate `element` on itself and childViews when being rendered by ensureChildrenAreInDOM', function () {
expectDeprecation('Setting `childViews` on a Container is deprecated.');

Expand Down
102 changes: 14 additions & 88 deletions packages/ember-views/tests/views/text_area_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,106 +52,32 @@ QUnit.test('should become disabled if the disabled attribute is true', function(
ok(textArea.$().is(':not(:disabled)'));
});

QUnit.test('input value is updated when setting value property of view', function() {
run(function() {
set(textArea, 'value', 'foo');
textArea.append();
});

equal(textArea.$().val(), 'foo', 'renders text field with value');

run(function() { set(textArea, 'value', 'bar'); });

equal(textArea.$().val(), 'bar', 'updates text field after value changes');
});

QUnit.test('input placeholder is updated when setting placeholder property of view', function() {
run(function() {
set(textArea, 'placeholder', 'foo');
textArea.append();
});

equal(textArea.$().attr('placeholder'), 'foo', 'renders text area with placeholder');

run(function() { set(textArea, 'placeholder', 'bar'); });

equal(textArea.$().attr('placeholder'), 'bar', 'updates text area after placeholder changes');
});

QUnit.test('input name is updated when setting name property of view', function() {
run(function() {
set(textArea, 'name', 'foo');
textArea.append();
});

equal(textArea.$().attr('name'), 'foo', 'renders text area with name');

run(function() { set(textArea, 'name', 'bar'); });

equal(textArea.$().attr('name'), 'bar', 'updates text area after name changes');
});

QUnit.test('input maxlength is updated when setting maxlength property of view', function() {
run(function() {
set(textArea, 'maxlength', '300');
textArea.append();
});

equal(textArea.$().attr('maxlength'), '300', 'renders text area with maxlength');
['placeholder', 'name', 'title', 'maxlength', 'rows', 'cols', 'tabindex'].forEach(function(attributeName) {
QUnit.test(`text area ${attributeName} is updated when setting ${attributeName} property of view`, function() {
run(function() {
set(textArea, attributeName, '1');
textArea.append();
});

run(function() { set(textArea, 'maxlength', '400'); });
equal(textArea.$().attr(attributeName), '1', 'renders text area with ' + attributeName);

equal(textArea.$().attr('maxlength'), '400', 'updates text area after maxlength changes');
});
run(function() { set(textArea, attributeName, '2'); });

QUnit.test('input rows is updated when setting rows property of view', function() {
run(function() {
set(textArea, 'rows', '3');
textArea.append();
equal(textArea.$().attr(attributeName), '2', `updates text area after ${attributeName} changes`);
});

equal(textArea.$().attr('rows'), '3', 'renders text area with rows');

run(function() { set(textArea, 'rows', '4'); });

equal(textArea.$().attr('rows'), '4', 'updates text area after rows changes');
});

QUnit.test('input cols is updated when setting cols property of view', function() {
QUnit.test('text area value is updated when setting value property of view', function() {
run(function() {
set(textArea, 'cols', '30');
textArea.append();
});

equal(textArea.$().attr('cols'), '30', 'renders text area with cols');

run(function() { set(textArea, 'cols', '40'); });

equal(textArea.$().attr('cols'), '40', 'updates text area after cols changes');
});

QUnit.test('input tabindex is updated when setting tabindex property of view', function() {
run(function() {
set(textArea, 'tabindex', '4');
set(textArea, 'value', 'foo');
textArea.append();
});

equal(textArea.$().attr('tabindex'), '4', 'renders text area with the tabindex');

run(function() { set(textArea, 'tabindex', '1'); });
equal(textArea.$().val(), 'foo', 'renders text area with value');

equal(textArea.$().attr('tabindex'), '1', 'updates text area after tabindex changes');
});

QUnit.test('input title is updated when setting title property of view', function() {
run(function() {
set(textArea, 'title', 'FooTitle');
textArea.append();
});
equal(textArea.$().attr('title'), 'FooTitle', 'renders text area with the title');
run(function() { set(textArea, 'value', 'bar'); });

run(function() { set(textArea, 'title', 'BarTitle'); });
equal(textArea.$().attr('title'), 'BarTitle', 'updates text area after title changes');
equal(textArea.$().val(), 'bar', 'updates text area after value changes');
});

QUnit.test('value binding works properly for inputs that haven\'t been created', function() {
Expand Down
91 changes: 14 additions & 77 deletions packages/ember-views/tests/views/text_field_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,95 +97,32 @@ QUnit.test('should become disabled if the disabled attribute is true', function(
ok(textField.$().is(':not(:disabled)'));
});

QUnit.test('input value is updated when setting value property of view', function() {
run(function() {
set(textField, 'value', 'foo');
textField.append();
});

equal(textField.$().val(), 'foo', 'renders text field with value');

run(function() { set(textField, 'value', 'bar'); });

equal(textField.$().val(), 'bar', 'updates text field after value changes');
});

QUnit.test('input placeholder is updated when setting placeholder property of view', function() {
run(function() {
set(textField, 'placeholder', 'foo');
textField.append();
});

equal(textField.$().attr('placeholder'), 'foo', 'renders text field with placeholder');

run(function() { set(textField, 'placeholder', 'bar'); });

equal(textField.$().attr('placeholder'), 'bar', 'updates text field after placeholder changes');
});

QUnit.test('input name is updated when setting name property of view', function() {
run(function() {
set(textField, 'name', 'foo');
textField.append();
});

equal(textField.$().attr('name'), 'foo', 'renders text field with name');

run(function() { set(textField, 'name', 'bar'); });

equal(textField.$().attr('name'), 'bar', 'updates text field after name changes');
});

QUnit.test('input maxlength is updated when setting maxlength property of view', function() {
run(function() {
set(textField, 'maxlength', '30');
textField.append();
});

equal(textField.$().attr('maxlength'), '30', 'renders text field with maxlength');

run(function() { set(textField, 'maxlength', '40'); });

equal(textField.$().attr('maxlength'), '40', 'updates text field after maxlength changes');
});

QUnit.test('input size is updated when setting size property of view', function() {
run(function() {
set(textField, 'size', '30');
textField.append();
});

equal(textField.$().attr('size'), '30', 'renders text field with size');
['placeholder', 'name', 'title', 'size', 'maxlength', 'tabindex'].forEach(function(attributeName) {
QUnit.test(`text field ${attributeName} is updated when setting ${attributeName} property of view`, function() {
run(function() {
set(textField, attributeName, '1');
textField.append();
});

run(function() { set(textField, 'size', '40'); });
equal(textField.$().attr(attributeName), '1', `renders text field with ${attributeName}`);

equal(textField.$().attr('size'), '40', 'updates text field after size changes');
});
run(function() { set(textField, attributeName, '2'); });

QUnit.test('input tabindex is updated when setting tabindex property of view', function() {
run(function() {
set(textField, 'tabindex', '5');
textField.append();
equal(textField.$().attr(attributeName), '2', `updates text field after ${attributeName} changes`);
});

equal(textField.$().attr('tabindex'), '5', 'renders text field with the tabindex');

run(function() { set(textField, 'tabindex', '3'); });

equal(textField.$().attr('tabindex'), '3', 'updates text field after tabindex changes');
});

QUnit.test('input title is updated when setting title property of view', function() {
QUnit.test('input value is updated when setting value property of view', function() {
run(function() {
set(textField, 'title', 'FooTitle');
set(textField, 'value', 'foo');
textField.append();
});

equal(textField.$().attr('title'), 'FooTitle', 'renders text field with the title');
equal(textField.$().val(), 'foo', 'renders text field with value');

run(function() { set(textField, 'title', 'BarTitle'); });
run(function() { set(textField, 'value', 'bar'); });

equal(textField.$().attr('title'), 'BarTitle', 'updates text field after title changes');
equal(textField.$().val(), 'bar', 'updates text field after value changes');
});

QUnit.test('input type is configurable when creating view', function() {
Expand Down

0 comments on commit 1873a12

Please sign in to comment.