This repository has been archived by the owner on Jul 10, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved editable aliases and prepared its DOM structure for grid layout
the AliasesEditTool doesn't initialize with an empty EditableAliases anymore. Instead we initialize an empty AliasesEditTool if no aliases are set yet, and initialize the EditableAliases instance on demand. This solves problems we had before with the button and solves some minor hackery. Also prepared DOM structure for grid layout. This requires that aliases label (part of AliasesEditTool) and the value (part of EditableAliases) are structured within one DOM node to have them together as block element which we can give some padding on the right to overlay the edit tools. - patch-set 2: added QUnit tests for AliasesEditTool and implemented destroy function - patch-set 5: rebase and fixed conflicts - patch-set 6: adjusted tests for the new aliases DOM structure Change-Id: Ie07985986450550d1efa9a27770b2d62bfc01e41
- Loading branch information
Showing
8 changed files
with
140 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* QUnit tests for aliases edit tool | ||
* @see https://www.mediawiki.org/wiki/Extension:Wikibase | ||
* | ||
* @since 0.1 | ||
* @file | ||
* @ingroup Wikibase | ||
* | ||
* @licence GNU GPL v2+ | ||
* @author Daniel Werner | ||
*/ | ||
( function( mw, wb, $, QUnit ) { | ||
'use strict'; | ||
QUnit.module( 'wikibase.ui.AliasesEditTool', QUnit.newWbEnvironment( { | ||
setup: function() { | ||
/** | ||
* Holds the original dom structure the AliasesEditTool was initialized with | ||
* @var jQuery | ||
*/ | ||
var initialStructure = wb.ui.AliasesEditTool.getEmptyStructure(); | ||
this.initialStructureMembers = initialStructure.children(); | ||
this.subject = new wb.ui.AliasesEditTool( initialStructure ); | ||
|
||
QUnit.assert.ok( | ||
this.subject instanceof wb.ui.AliasesEditTool, | ||
'instantiated AliasesEditTool' | ||
); | ||
}, | ||
teardown: function() { | ||
var self = this; | ||
var values = this.subject.getValues(); | ||
this.subject.destroy(); | ||
|
||
// basic check whether initial structure was restored | ||
var initialStructure = true; | ||
this.initialStructureMembers.each( function() { | ||
initialStructure = initialStructure && $( this ).parent().is( self.subject._subject ); | ||
} ); | ||
|
||
QUnit.assert.ok( | ||
initialStructure, | ||
'DOM nodes from initial aliases edit tool are in the right place again' | ||
); | ||
|
||
QUnit.assert.equal( | ||
this.initialStructureMembers.length + values.length, | ||
this.subject._subject.children().length, | ||
'No additional DOM nodes left (except those of inserted values)' | ||
); | ||
|
||
this.subject = null; | ||
this.initialStructureMembers = null; | ||
} | ||
|
||
} ) ); | ||
|
||
// base for following tests, creates some values | ||
var initAliasesTest = function( assert ) { | ||
var newVal = this.subject.enterNewValue( [ 'alias 1', 'two', 'three' ] ); | ||
assert.ok( | ||
newVal instanceof wb.ui.PropertyEditTool.EditableAliases, | ||
'Value entered has instance of EditableAlias' | ||
); | ||
}; | ||
|
||
// This is the same as the next test, but the next one does additional stuff, so the destroy() in teardown | ||
// might fail independently, depending on the edit tools state. | ||
QUnit.test( 'Test with creating new EditableAliases', initAliasesTest ); | ||
|
||
QUnit.test( 'Test creating and removing EditableAliases from edit tool', function( assert ) { | ||
initAliasesTest.call( this, assert ); | ||
|
||
var aliasesValue = this.subject.getValues()[0]; | ||
|
||
aliasesValue.queryApi = function( deferred, apiAction ) { // override AJAX API call | ||
deferred.resolve().promise(); | ||
}; | ||
aliasesValue.remove(); | ||
|
||
assert.ok( | ||
this.subject.getValues.length, | ||
0, | ||
'Empty after removing EditableAliases instance' | ||
); | ||
} ); | ||
|
||
}( mediaWiki, wikibase, jQuery, QUnit ) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters