From 4a5c93d0f2ba3d4ede7626b746e6cc11e4405926 Mon Sep 17 00:00:00 2001 From: Brian Hann Date: Wed, 8 May 2013 16:36:09 -0500 Subject: [PATCH] Adding a test for editing complex properties Making sure that editing of columns bound to multilevel objects, like 'person.demographics.name' works as expected --- test/unit/directivesSpec.js | 73 ++++++++++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/test/unit/directivesSpec.js b/test/unit/directivesSpec.js index 52d69a0dc1..183598f120 100644 --- a/test/unit/directivesSpec.js +++ b/test/unit/directivesSpec.js @@ -127,9 +127,10 @@ describe('directives', function () { describe('column', function () { describe('cell editing', function () { - var elm, element, $scope; + var elm, element, $scope, $compile; - beforeEach(inject(function ($rootScope, $compile) { + beforeEach(inject(function ($rootScope, _$compile_) { + $compile = _$compile_; $scope = $rootScope; elm = angular.element( '
' @@ -183,6 +184,74 @@ describe('directives', function () { }); }); + it('should allow editing of complex properties', function() { + // Update the grid data to use complex properties + elm = angular.element( + '
' + ); + + $scope.myData = [ + { + address: '123 Main St', + person: { + name: 'Bob', + age: 20 + } + }, + { + address: '1600 Pennsylvania Ave.', + person: { + name: 'Barack', + age: 51 + } + } + ]; + $scope.gridOptions.columnDefs = [ + { field: 'person.name' }, + { field: 'person.age' }, + { field: 'address' } + ]; + + // Recompile the grid + element = $compile(elm)($scope); + $scope.$digest(); + + // Get the first editable cell + var cell = element.find('.ngRow:eq(0) .ngCell.col0 [ng-dblclick]'); + + runs(function() { + // Double-click on the first editable cell + browserTrigger(cell, 'dblclick'); + }); + waits(200); + runs(function() { + var input = cell.find('input'); + + expect(input.val()).toEqual('Bob'); + + // Change the value to 'Test' + var testName = 'Test Name'; + input.val(testName); + + expect(function(){ + // Trigger the input handler + input.triggerHandler('keyup'); + }).not.toThrow(); + + // The value of the input should stay 'Test' + expect(input.val()).toEqual(testName); + + // The change should be reflected in the data array + expect($scope.myData[0].person.name).toEqual(testName); + + // Blur so the input goes away + input.blur(); + + // 'Test' should be visible in the cell html + expect(element.find('.ngRow:eq(0) .ngCell.col0').text()).toContain(testName); + }); + }); + // TODO: add a test for enter key modifying the inputted contents });