fix(record-range): fixes bug when disabling empty ranges.

This commit is contained in:
Rado Kirov 2014-12-03 11:59:50 -08:00
parent c59cc8631a
commit 5bdefee6c9
2 changed files with 13 additions and 2 deletions

View File

@ -188,8 +188,11 @@ export class RecordRange {
var firstEnabledChildRecord = this.findFirstEnabledRecord(); var firstEnabledChildRecord = this.findFirstEnabledRecord();
var lastEnabledChildRecord = this.findLastEnabledRecord(); var lastEnabledChildRecord = this.findLastEnabledRecord();
var nextEnabled = lastEnabledChildRecord.nextEnabled; var nextEnabled = isPresent(lastEnabledChildRecord) ?
var prevEnabled = firstEnabledChildRecord.prevEnabled; lastEnabledChildRecord.nextEnabled : null;
var prevEnabled = isPresent(firstEnabledChildRecord) ?
firstEnabledChildRecord.prevEnabled : null;
if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled; if (isPresent(nextEnabled)) nextEnabled.prevEnabled = prevEnabled;
if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled; if (isPresent(prevEnabled)) prevEnabled.nextEnabled = nextEnabled;

View File

@ -107,6 +107,14 @@ export function main() {
expect(enabledRecords(parent, recordNames)).toEqual(['record1', 'record2']); expect(enabledRecords(parent, recordNames)).toEqual(['record1', 'record2']);
}); });
it('should handle enabling/disabling an empty range', () => {
var emptyRange = new RecordRange(null, null);
emptyRange.disable();
emptyRange.enable();
expect(enabledRecords(emptyRange, recordNames)).toEqual([]);
});
it('should handle adding a range into an empty range', () => { it('should handle adding a range into an empty range', () => {
var emptyRange = new RecordRange(null, null); var emptyRange = new RecordRange(null, null);
parent.addRange(emptyRange); parent.addRange(emptyRange);