Skip to content

Remove unused filtering from getQualifiers #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/Claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,8 @@ $.extend( SELF.prototype, {
/**
* @return {wikibase.datamodel.SnakList}
*/
getQualifiers: function( propertyId ) {
if( !propertyId ) {
return this._qualifiers;
}

var filteredQualifiers = new wb.datamodel.SnakList();

this._qualifiers.each( function( i, snak ) {
if( snak.getPropertyId() === propertyId ) {
filteredQualifiers.addItem( snak );
}
} );

return filteredQualifiers;
getQualifiers: function() {
return this._qualifiers;
},

/**
Expand Down
13 changes: 6 additions & 7 deletions src/SnakList.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ wb.datamodel.SnakList = util.inherit( 'WbDataModelSnakList', PARENT, function( s
PARENT.call( this, wikibase.datamodel.Snak, snaks );
}, {
/**
* Returns a SnakList with the snaks featuring a specific property id. If the property id
* parameter is omitted, a copy of the whole SnakList object is returned.
* Returns a SnakList with the snaks featuring a specific property id.
*
* @param {string|null} [propertyId=null]
* @param {string} propertyId
* @return {wikibase.datamodel.SnakList}
*/
getFilteredSnakList: function( propertyId ) {
if( !propertyId ) {
return new wb.datamodel.SnakList( $.merge( [], this._items ) );
throw new Error( 'Can not filter with no propertyId.' );
}

var filteredQualifiers = new wb.datamodel.SnakList();
var filteredSnakList = new wb.datamodel.SnakList();

this.each( function( i, snak ) {
if( snak.getPropertyId() === propertyId ) {
filteredQualifiers.addItem( snak );
filteredSnakList.addItem( snak );
}
} );

return filteredQualifiers;
return filteredSnakList;
},

/**
Expand Down
15 changes: 4 additions & 11 deletions tests/Claim.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ QUnit.test( 'setMainSnak() & getMainSnak()', function( assert ) {
} );

QUnit.test( 'setQualifiers() & getQualifiers()', function( assert ) {
assert.expect( 2 );
assert.expect( 1 );
var claim = new wb.datamodel.Claim( new wb.datamodel.PropertyNoValueSnak( 'p1' ) ),
qualifiers = new wb.datamodel.SnakList( [
new wb.datamodel.PropertyNoValueSnak( 'p10' ),
Expand All @@ -75,18 +75,11 @@ QUnit.test( 'setQualifiers() & getQualifiers()', function( assert ) {

claim.setQualifiers( qualifiers );

assert.ok(
claim.getQualifiers().equals( qualifiers ),
assert.strictEqual(
claim.getQualifiers(),
qualifiers,
'Verified qualifiers being set.'
);

assert.ok(
claim.getQualifiers( 'p10' ).equals( new wb.datamodel.SnakList( [
new wb.datamodel.PropertyNoValueSnak( 'p10' ),
new wb.datamodel.PropertySomeValueSnak( 'p10' )
] ) ),
'Altered qualifiers.'
);
} );

QUnit.test( 'equals()', function( assert ) {
Expand Down
20 changes: 9 additions & 11 deletions tests/SnakList.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,24 @@ QUnit.test( 'Constructor', function( assert ) {
} );

QUnit.test( 'getFilteredSnakList()', function( assert ) {
assert.expect( 16 );
assert.expect( 11 );
assert.throws(
function() {
var snakList = new wb.datamodel.SnakList( [] );
snakList.getFilteredSnakList();
},
'getFilteredSnakList() throws an error when called with null.'
);

for( var i = 0; i < testSets.length; i++ ) {
var snakList = new wb.datamodel.SnakList( testSets[i] );

assert.ok(
snakList.getFilteredSnakList() instanceof wb.datamodel.SnakList,
'Returned SnakList object when issuing getFilteredSnakList() without parameter.'
);

assert.strictEqual(
snakList.getFilteredSnakList( 'P9999' ).length,
0,
'No filtered SnakList returned for an empty SnakList.'
);

assert.ok(
snakList.getFilteredSnakList().equals( new wb.datamodel.SnakList( snakList.toArray() ) ),
'Returning SnakList clone when issuing getFilteredSnakList() without parameter.'
);

var groupedSnakLists = {},
propertyId;

Expand Down