Skip to content

Commit 931c3a8

Browse files
committed
Rebase and update tests
1 parent 8137796 commit 931c3a8

File tree

2 files changed

+37
-86
lines changed

2 files changed

+37
-86
lines changed

src/Fingerprint.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ $.extend( SELF.prototype, {
147147
* @param {wikibase.datamodel.Term} description
148148
*/
149149
setDescription: function( description ) {
150-
if ( term.getText() === '' ) {
150+
if ( description.getText() === '' ) {
151151
this._descriptions.removeItemByKey( description.getLanguageCode() );
152152
} else {
153153
this._descriptions.setItem( description.getLanguageCode(), description );

tests/Fingerprint.tests.js

Lines changed: 36 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ QUnit.test( 'Constructor (positive)', function( assert ) {
5454
var expectedItem = map.getItemByKey( languageCodes[j] );
5555

5656
assert.ok(
57-
fingerprint[functionNames[term][1]]( languageCodes[j], expectedItem ),
57+
fingerprint[functionNames[term][1]]( expectedItem ),
5858
'Test set #' + i + ': Verified result of ' + functionNames[term][1]
5959
+ ' for language #' + languageCodes[j] + '.'
6060
);
@@ -126,30 +126,23 @@ QUnit.test( 'Constructor (negative)', function( assert ) {
126126
} );
127127

128128
QUnit.test( 'setLabel()', function( assert ) {
129-
assert.expect( 4 );
129+
assert.expect( 3 );
130130
var fingerprint = new wb.datamodel.Fingerprint(),
131131
label = new wb.datamodel.Term( 'de', 'de-label' );
132132

133133
assert.ok(
134-
!fingerprint.hasLabel( 'de', label ),
134+
!fingerprint.hasLabel( label ),
135135
'Verified fingerprint not featuring the label that will be added.'
136136
);
137137

138-
assert.throws(
139-
function() {
140-
fingerprint.setLabel( label );
141-
},
142-
'Throwing error when trying to set a label without specifying a language code.'
143-
);
144-
145-
fingerprint.setLabel( 'de', label );
138+
fingerprint.setLabel( label );
146139

147140
assert.ok(
148-
fingerprint.hasLabel( 'de', label ),
141+
fingerprint.hasLabel( label ),
149142
'Set label.'
150143
);
151144

152-
fingerprint.setLabel( 'de', new wb.datamodel.Term( 'de', '' ) );
145+
fingerprint.setLabel( new wb.datamodel.Term( 'de', '' ) );
153146

154147
assert.ok(
155148
!fingerprint.hasLabelFor( 'de' ),
@@ -158,26 +151,19 @@ QUnit.test( 'setLabel()', function( assert ) {
158151
} );
159152

160153
QUnit.test( 'removeLabel()', function( assert ) {
161-
assert.expect( 3 );
154+
assert.expect( 2 );
162155
var label = new wb.datamodel.Term( 'de', 'de-label' ),
163156
fingerprint = new wb.datamodel.Fingerprint( new wb.datamodel.TermMap( { de: label } ) );
164157

165158
assert.ok(
166-
fingerprint.hasLabel( 'de', label ),
159+
fingerprint.hasLabel( label ),
167160
'Verified fingerprint featuring the label to be removed.'
168161
);
169162

170-
assert.throws(
171-
function() {
172-
fingerprint.removeLabel( label );
173-
},
174-
'Throwing error when trying to remove a label without specifying a language code.'
175-
);
176-
177-
fingerprint.removeLabel( 'de', label );
163+
fingerprint.removeLabel( label );
178164

179165
assert.ok(
180-
!fingerprint.hasLabel( 'de', label ),
166+
!fingerprint.hasLabel( label ),
181167
'Removed label.'
182168
);
183169
} );
@@ -188,43 +174,36 @@ QUnit.test( 'removeLabelFor()', function( assert ) {
188174
fingerprint = new wb.datamodel.Fingerprint( new wb.datamodel.TermMap( { de: label } ) );
189175

190176
assert.ok(
191-
fingerprint.hasLabel( 'de', label ),
177+
fingerprint.hasLabel( label ),
192178
'Verified fingerprint featuring the label to be removed.'
193179
);
194180

195181
fingerprint.removeLabelFor( 'de' );
196182

197183
assert.ok(
198-
!fingerprint.hasLabel( 'de', label ),
184+
!fingerprint.hasLabel( label ),
199185
'Removed label.'
200186
);
201187
} );
202188

203189
QUnit.test( 'setDescription()', function( assert ) {
204-
assert.expect( 4 );
190+
assert.expect( 3 );
205191
var fingerprint = new wb.datamodel.Fingerprint(),
206192
description = new wb.datamodel.Term( 'de', 'de-description' );
207193

208194
assert.ok(
209-
!fingerprint.hasDescription( 'de', description ),
195+
!fingerprint.hasDescription( description ),
210196
'Verified fingerprint not featuring the description that will be added.'
211197
);
212198

213-
assert.throws(
214-
function() {
215-
fingerprint.setDescription( description );
216-
},
217-
'Throwing error when trying to set a description without specifying a language code.'
218-
);
219-
220-
fingerprint.setDescription( 'de', description );
199+
fingerprint.setDescription( description );
221200

222201
assert.ok(
223-
fingerprint.hasDescription( 'de', description ),
202+
fingerprint.hasDescription( description ),
224203
'Set description.'
225204
);
226205

227-
fingerprint.setDescription( 'de', new wb.datamodel.Term( 'de', '' ) );
206+
fingerprint.setDescription( new wb.datamodel.Term( 'de', '' ) );
228207

229208
assert.ok(
230209
!fingerprint.hasDescriptionFor( 'de' ),
@@ -233,29 +212,22 @@ QUnit.test( 'setDescription()', function( assert ) {
233212
} );
234213

235214
QUnit.test( 'removeDescription()', function( assert ) {
236-
assert.expect( 3 );
215+
assert.expect( 2 );
237216
var description = new wb.datamodel.Term( 'de', 'de-description' ),
238217
fingerprint = new wb.datamodel.Fingerprint(
239218
null,
240219
new wb.datamodel.TermMap( { de: description } )
241220
);
242221

243222
assert.ok(
244-
fingerprint.hasDescription( 'de', description ),
223+
fingerprint.hasDescription( description ),
245224
'Verified fingerprint featuring the description to be removed.'
246225
);
247226

248-
assert.throws(
249-
function() {
250-
fingerprint.removeDescription( description );
251-
},
252-
'Throwing error when trying to remove a description without specifying a language code.'
253-
);
254-
255-
fingerprint.removeDescription( 'de', description );
227+
fingerprint.removeDescription( description );
256228

257229
assert.ok(
258-
!fingerprint.hasDescription( 'de', description ),
230+
!fingerprint.hasDescription( description ),
259231
'Removed description.'
260232
);
261233
} );
@@ -269,41 +241,34 @@ QUnit.test( 'removeDescriptionFor()', function( assert ) {
269241
);
270242

271243
assert.ok(
272-
fingerprint.hasDescription( 'de', description ),
244+
fingerprint.hasDescription( description ),
273245
'Verified fingerprint featuring the description to be removed.'
274246
);
275247

276248
fingerprint.removeDescriptionFor( description.getLanguageCode() );
277249

278250
assert.ok(
279-
!fingerprint.hasDescription( 'de', description ),
251+
!fingerprint.hasDescription( description ),
280252
'Removed description.'
281253
);
282254
} );
283255

284256
QUnit.test( 'setAliases()', function( assert ) {
285-
assert.expect( 8 );
257+
assert.expect( 6 );
286258
var fingerprint = new wb.datamodel.Fingerprint(),
287259
deAliases = new wb.datamodel.MultiTerm( 'de', ['de-alias'] ),
288260
enAliases = new wb.datamodel.MultiTerm( 'en', ['en-alias'] ),
289261
aliases = new wb.datamodel.MultiTermMap( { en: enAliases } );
290262

291263
assert.ok(
292-
!fingerprint.hasAliases( 'de', deAliases ),
264+
!fingerprint.hasAliases( deAliases ),
293265
'Verified fingerprint not featuring the aliases that will be added.'
294266
);
295267

296-
assert.throws(
297-
function() {
298-
fingerprint.setAliases( deAliases );
299-
},
300-
'Throwing error when trying to set a MultiTerm without specifying a language code.'
301-
);
302-
303-
fingerprint.setAliases( 'de', deAliases );
268+
fingerprint.setAliases( deAliases );
304269

305270
assert.ok(
306-
fingerprint.hasAliases( 'de', deAliases ),
271+
fingerprint.hasAliases( deAliases ),
307272
'Set aliases passing a MultiTerm object.'
308273
);
309274

@@ -315,34 +280,27 @@ QUnit.test( 'setAliases()', function( assert ) {
315280
);
316281

317282
assert.ok(
318-
!fingerprint.hasAliases( 'en', enAliases ),
283+
!fingerprint.hasAliases( enAliases ),
319284
'Verified fingerprint not featuring the aliases that will be added.'
320285
);
321286

322287
fingerprint.setAliases( aliases );
323288

324289
assert.ok(
325-
fingerprint.hasAliases( 'en', enAliases ),
290+
fingerprint.hasAliases( enAliases ),
326291
'Set aliases passing a MultiTermMap object.'
327292
);
328293

329-
fingerprint.setAliases( 'en', new wb.datamodel.MultiTerm( 'en', [] ) );
294+
fingerprint.setAliases( new wb.datamodel.MultiTerm( 'en', [] ) );
330295

331296
assert.ok(
332297
!fingerprint.hasAliasesFor( 'en' ),
333298
'Set aliases with empty list removes aliases.'
334299
);
335-
336-
assert.throws(
337-
function() {
338-
fingerprint.setAliases( new wb.datamodel.MultiTerm( 'en', [] ) );
339-
},
340-
'Throwing error when trying to set an empty MultiTerm without specifying a language code.'
341-
);
342300
} );
343301

344302
QUnit.test( 'removeAliases()', function( assert ) {
345-
assert.expect( 3 );
303+
assert.expect( 2 );
346304
var aliases = new wb.datamodel.MultiTerm( 'de', ['de-alias'] ),
347305
fingerprint = new wb.datamodel.Fingerprint(
348306
null,
@@ -351,21 +309,14 @@ QUnit.test( 'removeAliases()', function( assert ) {
351309
);
352310

353311
assert.ok(
354-
fingerprint.hasAliases( 'de', aliases ),
312+
fingerprint.hasAliases( aliases ),
355313
'Verified fingerprint featuring the aliases to be removed.'
356314
);
357315

358-
assert.throws(
359-
function() {
360-
fingerprint.removeAliases( aliases );
361-
},
362-
'Throwing error when trying to remove aliases without specifying a language code.'
363-
);
364-
365-
fingerprint.removeAliases( 'de', aliases );
316+
fingerprint.removeAliases( aliases );
366317

367318
assert.ok(
368-
!fingerprint.hasAliases( 'de', aliases ),
319+
!fingerprint.hasAliases( aliases ),
369320
'Removed aliases.'
370321
);
371322
} );
@@ -380,14 +331,14 @@ QUnit.test( 'removeAliasesFor()', function( assert ) {
380331
);
381332

382333
assert.ok(
383-
fingerprint.hasAliases( 'de', aliases ),
334+
fingerprint.hasAliases( aliases ),
384335
'Verified fingerprint featuring the aliases to be removed.'
385336
);
386337

387338
fingerprint.removeAliasesFor( 'de' );
388339

389340
assert.ok(
390-
!fingerprint.hasAliases( 'de', aliases ),
341+
!fingerprint.hasAliases( aliases ),
391342
'Removed aliases.'
392343
);
393344
} );

0 commit comments

Comments
 (0)