Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
fix(repeat): use 0-based indexing for repeater rows
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Finding rows with protractor.By.repeater now
indexes from 0 instead of 1. This should be more familiar to most
modern programmers. You will need to edit existing tests. Closes #90.

Before:

// The fourth foo
ptor.findElement(protractor.By.repeater('foo in foos').row(4));

After:

// The fourth foo
ptor.findElement(protractor.By.repeater('foo in foos').row(3));
  • Loading branch information
juliemr committed Oct 9, 2013
1 parent e45ceaa commit 421d623
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ clientSideScripts.findBindings = function() {
}
}
}
return rows[index - 1];
return rows[index];
};

/**
Expand Down Expand Up @@ -153,7 +153,7 @@ clientSideScripts.findRepeaterElement = function() {
}
}
}
var row = rows[index - 1];
var row = rows[index];
var bindings = [];
if (row.className.indexOf('ng-binding') != -1) {
bindings.push(row);
Expand Down
32 changes: 16 additions & 16 deletions spec/findelements_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ describe('finding elements', function() {
it('should find by partial match', function() {
var fullMatch = ptor.findElement(
protractor.By.repeater('baz in days | filter:\'T\'').
row(1).column('{{baz}}'));
row(0).column('{{baz}}'));
expect(fullMatch.getText()).toEqual('Tue');

var partialMatch = ptor.findElement(
protractor.By.repeater('baz in days').row(1).column('b'));
protractor.By.repeater('baz in days').row(0).column('b'));
expect(partialMatch.getText()).toEqual('Tue');

var partialRowMatch = ptor.findElement(
protractor.By.repeater('baz in days').row(1));
protractor.By.repeater('baz in days').row(0));
expect(partialRowMatch.getText()).toEqual('Tue');
});

Expand Down Expand Up @@ -137,65 +137,65 @@ describe('finding elements', function() {

it('should return a single row', function() {
var secondRow = ptor.findElement(
protractor.By.repeater('dayColor in dayColors').row(2));
protractor.By.repeater('dayColor in dayColors').row(1));
expect(secondRow.getText()).toEqual('Tue green');
});

it('should return an individual cell', function() {
var secondColor = ptor.findElement(
protractor.By.repeater('dayColor in dayColors').
row(2).
row(1).
column('color'));

var secondColorByColumnFirst = ptor.findElement(
protractor.By.repeater('dayColor in dayColors').
column('color').
row(2));
row(1));

expect(secondColor.getText()).toEqual('green');
expect(secondColorByColumnFirst.getText()).toEqual('green');
});

it('should find a using data-ng-repeat', function() {
var byRow =
ptor.findElement(protractor.By.repeater('day in days').row(3));
ptor.findElement(protractor.By.repeater('day in days').row(2));
expect(byRow.getText()).toEqual('Wed');

var byCol =
ptor.findElement(protractor.By.repeater('day in days').row(3).
ptor.findElement(protractor.By.repeater('day in days').row(2).
column('day'));
expect(byCol.getText()).toEqual('Wed');
});

it('should find using ng:repeat', function() {
var byRow =
ptor.findElement(protractor.By.repeater('bar in days').row(3));
ptor.findElement(protractor.By.repeater('bar in days').row(2));
expect(byRow.getText()).toEqual('Wed');

var byCol =
ptor.findElement(protractor.By.repeater('bar in days').row(3).
ptor.findElement(protractor.By.repeater('bar in days').row(2).
column('bar'));
expect(byCol.getText()).toEqual('Wed');
});

it('should find using ng_repeat', function() {
var byRow =
ptor.findElement(protractor.By.repeater('foo in days').row(3));
ptor.findElement(protractor.By.repeater('foo in days').row(2));
expect(byRow.getText()).toEqual('Wed');

var byCol =
ptor.findElement(protractor.By.repeater('foo in days').row(3).
ptor.findElement(protractor.By.repeater('foo in days').row(2).
column('foo'));
expect(byCol.getText()).toEqual('Wed');
});

it('should find using x-ng-repeat', function() {
var byRow =
ptor.findElement(protractor.By.repeater('qux in days').row(3));
ptor.findElement(protractor.By.repeater('qux in days').row(2));
expect(byRow.getText()).toEqual('Wed');

var byCol =
ptor.findElement(protractor.By.repeater('qux in days').row(3).
ptor.findElement(protractor.By.repeater('qux in days').row(2).
column('qux'));
expect(byCol.getText()).toEqual('Wed');
});
Expand Down Expand Up @@ -230,12 +230,12 @@ describe('finding elements', function() {
it('should find elements using a repeater', function() {
// Returns the element for the entire row.
expect(
ptor.findElement(protractor.By.repeater('ball in planets').row(3)).
ptor.findElement(protractor.By.repeater('ball in planets').row(2)).
getText()).toEqual('Earth:3');

// Returns the element in row 2 and the column with binding {{ball.name}}
expect(
ptor.findElement(protractor.By.repeater('ball in planets').row(2).
ptor.findElement(protractor.By.repeater('ball in planets').row(1).
column('{{ball.name}}')).getText()).toEqual('Venus');

// Returns the entire column.
Expand Down
6 changes: 3 additions & 3 deletions spec/testapp_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,20 @@ describe('longer example', function() {
var addOneButton = ptor.findElement(protractor.By.id('addone'));
addOneButton.click();
var topNumber = ptor.findElement(
protractor.By.repeater('foo in foos').row(1).
protractor.By.repeater('foo in foos').row(0).
column('{{foo.b}}'));

expect(topNumber.getText()).toEqual('14930352');

addOneButton.click();

topNumber = ptor.findElement(
protractor.By.repeater('foo in foos').row(1).
protractor.By.repeater('foo in foos').row(0).
column('{{foo.b}}'));

expect(topNumber.getText()).toEqual('24157817');
});
});
});

});
});

0 comments on commit 421d623

Please sign in to comment.