Skip to content

Commit a29b70b

Browse files
committedDec 17, 2014
Fix #2285 (tut, e2e): fixed e2e and extended tut for external sort
1 parent 54c418a commit a29b70b

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed
 

‎Gruntfile.js

+1
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ module.exports = function(grunt) {
287287
afterEach: false,
288288
before: false,
289289
beforeEach: false,
290+
console: false,
290291
dump: false,
291292
describe: false,
292293
ddescribe: false,

‎misc/tutorial/304_grid_menu.ngdoc

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ want them also internationalized in the grid menu. The translate needs to retur
1515
or a promise that will resolve to a string. In the example below we create a fake
1616
internationalization function that waits 1 second then prefixes each column with "col: ".
1717

18+
You can suppress the ability to show and hide columns by setting the gridOption `gridMenuShowHideColumns: false`,
19+
you can suppress the ability to hide individual columns by setting `enableHiding` on that columnDef to false.
20+
1821
@example
1922
<example module="app">
2023
<file name="app.js">
@@ -33,7 +36,6 @@ internationalization function that waits 1 second then prefixes each column with
3336
exporterMenuCsv: false,
3437
enableGridMenu: true,
3538
gridMenuTitleFilter: fakeI18n,
36-
gridMenuShowHideColumns: false,
3739
columnDefs: [
3840
{ name: 'name' },
3941
{ name: 'gender', enableHiding: false },
@@ -103,21 +105,21 @@ internationalization function that waits 1 second then prefixes each column with
103105
});
104106

105107
it('grid1 grid menu should have 8 items', function () {
106-
gridTestUtils.expectVisibleGridMenuItems( 'grid1', 8 );
108+
gridTestUtils.expectVisibleGridMenuItems( 'grid1', 7 );
107109
});
108110

109-
it('grid1 hide then show gender column', function () {
111+
it('grid1 hide then show company column', function () {
110112
gridTestUtils.expectHeaderColumnCount( 'grid1', 3 );
111113
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 0, 'Name' );
112114
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Gender' );
113115
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 2, 'Company' );
114116

115-
gridTestUtils.clickGridMenuItem( 'grid1', 11 ); // there are some hidden menu items, this is gender_hide
117+
gridTestUtils.clickGridMenuItem( 'grid1', 11 ); // there are some hidden menu items, this is company_hide
116118
gridTestUtils.expectHeaderColumnCount( 'grid1', 2 );
117119
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 0, 'Name' );
118-
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Company' );
120+
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Gender' );
119121

120-
gridTestUtils.clickGridMenuItem( 'grid1', 12 ); // there are some hidden menu items, this is gender_show
122+
gridTestUtils.clickGridMenuItem( 'grid1', 12 ); // there are some hidden menu items, this is company_show
121123
gridTestUtils.expectHeaderColumnCount( 'grid1', 3 );
122124
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 0, 'Name' );
123125
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Gender' );

‎misc/tutorial/307_external_sorting.ngdoc

+64-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ json files to show - one sorted ASC, one sorted DESC, and one not sorted. To fu
1616
is using external sorting, the external sort routine (consisting of me manually editing json files) got bored
1717
of sorting after the first 10 or so rows.
1818

19+
We allow sorting by the first and second columns, so that we can show a default sort and that default sort
20+
indicator being removed even when using external sorting. Our external sort routine ignores that second
21+
column however, so sorting by it has no effect.
22+
1923
<example module="app">
2024
<file name="app.js">
2125
var app = angular.module('app', ['ngTouch', 'ui.grid']);
@@ -26,13 +30,17 @@ of sorting after the first 10 or so rows.
2630
useExternalSorting: true,
2731
columnDefs: [
2832
{ name: 'name' },
29-
{ name: 'gender', enableSorting: false},
33+
{ name: 'gender', sort: {
34+
direction: uiGridConstants.DESC,
35+
priority: 1
36+
}
37+
},
3038
{ name: 'company', enableSorting: false}
3139
],
3240
onRegisterApi: function( gridApi ) {
3341
$scope.gridApi = gridApi;
3442
$scope.gridApi.core.on.sortChanged( $scope, function( grid, sortColumns ) {
35-
if( sortColumns.length === 0 ){
43+
if( sortColumns.length === 0 || sortColumns[0].name !== $scope.gridOptions.columnDefs[0].name ){
3644
$http.get('/data/100.json')
3745
.success(function(data) {
3846
$scope.gridOptions.data = data;
@@ -72,7 +80,7 @@ of sorting after the first 10 or so rows.
7280
</file>
7381
<file name="index.html">
7482
<div ng-controller="MainCtrl">
75-
<div ui-grid="gridOptions" class="grid"></div>
83+
<div id="grid1" ui-grid="gridOptions" class="grid"></div>
7684
</div>
7785
</file>
7886
<file name="main.css">
@@ -81,4 +89,57 @@ of sorting after the first 10 or so rows.
8189
height: 250px;
8290
}
8391
</file>
92+
<file name="scenario.js">
93+
var gridTestUtils = require('../../test/e2e/gridTestUtils.spec.js');
94+
95+
describe('307 tutorial', function() {
96+
it('grid should have three visible columns', function () {
97+
gridTestUtils.expectHeaderColumnCount( 'grid1', 3 );
98+
});
99+
100+
it('header values should be as expected', function () {
101+
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 0, 'Name' );
102+
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 1, 'Gender' );
103+
gridTestUtils.expectHeaderCellValueMatch( 'grid1', 2, 'Company' );
104+
});
105+
106+
it('grid should be unsorted by default', function () {
107+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
108+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
109+
});
110+
111+
it('sort by name by clicking header', function () {
112+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
113+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Beryl Rice' );
114+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Bruce Strong' );
115+
});
116+
117+
it('reverse sort by name by clicking header', function () {
118+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
119+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
120+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Wilder Gonzales' );
121+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Valarie Atkinson' );
122+
});
123+
124+
it('return to original sort by name by clicking header', function () {
125+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
126+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
127+
gridTestUtils.clickHeaderCell( 'grid1', 0 );
128+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
129+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
130+
});
131+
132+
it('sort ignored on second column', function() {
133+
gridTestUtils.clickHeaderCell( 'grid1', 1 );
134+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
135+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
136+
});
137+
138+
it('sort disabled on last column', function() {
139+
gridTestUtils.clickHeaderCell( 'grid1', 2 );
140+
gridTestUtils.expectCellValueMatch( 'grid1', 0, 0, 'Ethel Price' );
141+
gridTestUtils.expectCellValueMatch( 'grid1', 1, 0, 'Claudine Neal' );
142+
});
143+
});
144+
</file>
84145
</example>

‎test/e2e/gridTestUtils.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ module.exports = {
315315
var resizer = headerCell.all( by.css( '.ui-grid-column-resizer' )).first();
316316
var menuButton = headerCell.element( by.css( '.ui-grid-column-menu-button' ));
317317

318-
browser().actions()
318+
browser.actions()
319319
.mouseDown(resizer)
320320
.mouseMove(menuButton)
321321
.mouseUp()
@@ -344,7 +344,7 @@ module.exports = {
344344
shiftClickHeaderCell: function( gridId, colNumber ) {
345345
var headerCell = this.headerCell( gridId, colNumber);
346346

347-
browser().actions()
347+
browser.actions()
348348
.keyDown(protractor.Key.SHIFT)
349349
.click(headerCell)
350350
.keyUp(protractor.Key.SHIFT)

0 commit comments

Comments
 (0)
Failed to load comments.