Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Widget / image resize tests refactoring #115

Merged
merged 64 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
52a7780
Tests: initial tests commit.
mlewand Oct 23, 2019
3b3024c
Tests: More tests for produced HTML markup.
mlewand Jan 7, 2020
8494c45
Internal: Removed unused private method.
mlewand Jan 7, 2020
fa09f04
Internal: Extracted mouse listeners used in widget resizer.
mlewand Jan 7, 2020
a9bb77f
Tests: Introduced test suite for widget resize class.
mlewand Jan 8, 2020
248f208
Tests: Dirty checkup commit.
mlewand Jan 9, 2020
c9ca31b
Tests: Adjusted breaking test.
mlewand Jan 9, 2020
f26cbe1
Tests: Attempt to add integration tests, but it doesn't look good so …
mlewand Jan 10, 2020
1a9f249
Tests: Minor adjustments.
mlewand Jan 13, 2020
fcb3d3f
Tests: Removed extra editor and reused existing one.
mlewand Jan 13, 2020
4b53b76
Tests: Further tests simplification.
mlewand Jan 13, 2020
497c1c3
Tests: Fixed unit test case.
mlewand Jan 13, 2020
5f2bc49
Tests: Simplified editor creation method.
mlewand Jan 13, 2020
4af8970
Internal: Widget resize upon its destroy should also destroy any resi…
mlewand Jan 13, 2020
b6f0e14
Tests: This test has been moved.
mlewand Jan 13, 2020
fb548de
Tests: Added unit test ensuring that if no isCenter option is passed,…
mlewand Jan 13, 2020
b675585
Tests: Added integration test for resize in percents.
mlewand Jan 14, 2020
bee7838
Internal: Fixed an issue where default resizing unit might not be pro…
mlewand Jan 14, 2020
a83a4fc
Tests: Changed default widget width for increased code coverage.
mlewand Jan 14, 2020
1529135
Tests: Removed extra suite wrapping.
mlewand Jan 14, 2020
5cc0578
Tests: Code coverage in case there's no _activeResizer set.
mlewand Jan 14, 2020
6eb73ba
Tests: Extracted common code.
mlewand Jan 14, 2020
5b93518
Tests: Extracted common onCommit stub.
mlewand Jan 14, 2020
27b158e
Tests: Extracted more common code.
mlewand Jan 14, 2020
7865154
Tests: Since editor is focused for each test move it to beforeEach.
mlewand Jan 14, 2020
9dd91ba
Tests: Forced resizer redraw is no longer required, so the code is re…
mlewand Jan 14, 2020
af63138
Tests: Removed unused utilities.
mlewand Jan 14, 2020
203feaa
Tests: Removed waiting in-between mouse operations.
mlewand Jan 14, 2020
65d803a
Tests: Bumped year in the license header.
mlewand Jan 14, 2020
80cd267
Tests: Added resizer state test suite.
mlewand Jan 15, 2020
f284a96
Tests: Inlined few variables to reduce amount of scope variables.
mlewand Jan 15, 2020
beb4c84
Tests: Added unit tests for proposed size.
mlewand Jan 15, 2020
34557c0
Tests: Ported the test for hiding resizer when its disabled.
mlewand Jan 15, 2020
65f7efb
Tests: _proposeNewSize is already tested in more relevant test suite.
mlewand Jan 15, 2020
665de49
Tests: There is no longer a need to use initMouseEvent anymore.
mlewand Jan 15, 2020
fd46bd3
Tests: Adjusted unit test name.
mlewand Feb 6, 2020
9039e01
Tests: Use plural form in unit test.
mlewand Feb 6, 2020
8cce02b
Tests: Added mouseMock.dragTo method, introduced Point class, changed…
mlewand Feb 7, 2020
aaf5d77
Tests: Simplified point handling (it's no longer immutable).
mlewand Feb 7, 2020
4c6c794
Tests: Moved assertions closer to tested code.
mlewand Feb 7, 2020
d418038
Tests: Removed the async keyword where it was not needed.
mlewand Feb 7, 2020
2be55c1
Tests: Added more cases for pixel resizing and a function generating …
mlewand Feb 7, 2020
ff71e0e
Test: Ported more old tests cases.
mlewand Feb 7, 2020
286851f
Tests: Existing tests should also reuse generateResizeTest whenever p…
mlewand Feb 7, 2020
680f561
Tests: Ported all generated tests from old suite.
mlewand Feb 7, 2020
5483424
Tests: Ported visibility test.
mlewand Feb 10, 2020
65a10d2
Tests: Ported percentage widget resize tests.
mlewand Feb 10, 2020
29817b2
Tests: getWidgetDomParts is now a shared util.
mlewand Feb 10, 2020
4cdfd89
Tests: Make getHandleCenterPoint a shared util.
mlewand Feb 10, 2020
3d940fc
Tests: Resizer mouse mock also accepts point object.
mlewand Feb 10, 2020
2e2cc7e
Tests: Improved dragTo - it now can accept explicit from and to point…
mlewand Feb 10, 2020
e825829
Tests: Expose focusEditor function.
mlewand Feb 10, 2020
67688bd
Tests: Move initialization into a single function.
mlewand Feb 10, 2020
01fdd05
Docs: Adjusted API docs.
mlewand Feb 10, 2020
52e1945
Tests: Moved test cases to proper group.
mlewand Feb 10, 2020
e2a71d8
Docs: Temporarily use generic event type in API docs.
mlewand Feb 10, 2020
7832d9b
Merge branch 'master' into i/4614
mlewand Feb 10, 2020
2354d26
Tests: Added a test case to improve CC.
mlewand Feb 10, 2020
17c4532
Tests: Renamed mouseMock to resizerMouseSimulator.
mlewand Feb 11, 2020
6ef7ac0
Tests: Turns out that behavior described in #6221 was invalid.
mlewand Feb 11, 2020
df4517f
Merge branch 'master' into i/4614
Reinmar Feb 12, 2020
706414c
Tests: Method names in suite description should feature parenthesis.
mlewand Feb 12, 2020
3835f24
Merge remote-tracking branch 'origin/master' into i/4614
mlewand Feb 18, 2020
34f4d3b
Merge branch 'master' into i/4614
Reinmar Feb 25, 2020
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
69 changes: 44 additions & 25 deletions src/widgetresize.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,33 +70,11 @@ export default class WidgetResize extends Plugin {

this._observer = Object.create( DomEmitterMixin );

this._observer.listenTo( domDocument, 'mousedown', ( event, domEventData ) => {
if ( !Resizer.isResizeHandle( domEventData.target ) ) {
return;
}
this._observer.listenTo( domDocument, 'mousedown', this._mouseDownListener.bind( this ) );

const resizeHandle = domEventData.target;
this._observer.listenTo( domDocument, 'mousemove', this._mouseMoveListener.bind( this ) );

this._activeResizer = this._getResizerByHandle( resizeHandle );

if ( this._activeResizer ) {
this._activeResizer.begin( resizeHandle );
}
} );

this._observer.listenTo( domDocument, 'mousemove', ( event, domEventData ) => {
if ( this._activeResizer ) {
this._activeResizer.updateSize( domEventData );
}
} );

this._observer.listenTo( domDocument, 'mouseup', () => {
if ( this._activeResizer ) {
this._activeResizer.commit();

this._activeResizer = null;
}
} );
this._observer.listenTo( domDocument, 'mouseup', this._mouseUpListener.bind( this ) );

const redrawFocusedResizer = () => {
if ( this._visibleResizer ) {
Expand Down Expand Up @@ -127,6 +105,10 @@ export default class WidgetResize extends Plugin {

destroy() {
this._observer.stopListening();

for ( const resizer of this._resizers.values() ) {
resizer.destroy();
}
}

/**
Expand Down Expand Up @@ -187,6 +169,43 @@ export default class WidgetResize extends Plugin {
_getResizerByViewElement( viewElement ) {
return this._resizers.get( viewElement );
}

/**
* @protected
* @param {module:utils/eventinfo~EventInfo} event
* @param {Event} domEventData Native DOM event.
*/
_mouseDownListener( event, domEventData ) {
if ( !Resizer.isResizeHandle( domEventData.target ) ) {
return;
}
const resizeHandle = domEventData.target;
this._activeResizer = this._getResizerByHandle( resizeHandle );
if ( this._activeResizer ) {
this._activeResizer.begin( resizeHandle );
}
}

/**
* @protected
* @param {module:utils/eventinfo~EventInfo} event
* @param {Event} domEventData Native DOM event.
*/
_mouseMoveListener( event, domEventData ) {
if ( this._activeResizer ) {
this._activeResizer.updateSize( domEventData );
}
}

/**
* @protected
*/
_mouseUpListener() {
if ( this._activeResizer ) {
this._activeResizer.commit();
this._activeResizer = null;
}
}
}

mix( WidgetResize, ObservableMixin );
Expand Down
25 changes: 4 additions & 21 deletions src/widgetresize/resizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class Resizer {
this.on( 'commit', event => {
// State might not be initialized yet. In this case, prevent further handling and make sure that the resizer is
// cleaned up (#5195).
if ( !this.state.proposedWidth ) {
if ( !this.state.proposedWidth && !this.state.proposedWidthPercents ) {
this._cleanup();
event.stop();
}
Expand Down Expand Up @@ -153,7 +153,7 @@ export default class Resizer {
const editingView = this._options.editor.editing.view;

editingView.change( writer => {
const unit = this._options.unit;
const unit = this._options.unit || '%';
const newWidth = ( unit === '%' ? newSize.widthPercents : newSize.width ) + unit;

writer.setStyle( 'width', newWidth, this._options.viewElement );
Expand Down Expand Up @@ -185,8 +185,8 @@ export default class Resizer {
* @fires commit
*/
commit() {
const unit = this._options.unit;
const newValue = ( unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth ) + this._options.unit;
const unit = this._options.unit || '%';
const newValue = ( unit === '%' ? this.state.proposedWidthPercents : this.state.proposedWidth ) + unit;

this._options.onCommit( newValue );

Expand Down Expand Up @@ -410,23 +410,6 @@ export default class Resizer {
domElement.appendChild( sizeUI.element );
}

/**
* Determines the position of a given resize handle.
*
* @private
* @param {HTMLElement} domHandle Handle used to calculate the reference point.
* @returns {String|undefined} Returns a string like `"top-left"` or `undefined` if not matched.
*/
_getHandlePosition( domHandle ) {
const resizerPositions = [ 'top-left', 'top-right', 'bottom-right', 'bottom-left' ];

for ( const position of resizerPositions ) {
if ( domHandle.classList.contains( getResizerClass( position ) ) ) {
return position;
}
}
}

/**
* @event begin
*/
Expand Down
Loading