Jdlrobson has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/156739

Change subject: Update classes of topic during close/reopen actions.
......................................................................

Update classes of topic during close/reopen actions.

Add tests.
Bug: 68328

Change-Id: I15a09c5b057de8e7d24e5c1b953bd36dfe72a40c
---
M modules/new/components/flow-board.js
M tests/qunit/new/components/test_flow-board.js
2 files changed, 97 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/39/156739/1

diff --git a/modules/new/components/flow-board.js 
b/modules/new/components/flow-board.js
index bea39a2..f264487 100644
--- a/modules/new/components/flow-board.js
+++ b/modules/new/components/flow-board.js
@@ -582,6 +582,7 @@
                        var revision,
                                $target = info.$target, $topicTitleBar,
                                topicId, revisionId,
+                               $topic = $target.parents( '.flow-topic' ),
                                self = this,
                                flowBoard = 
FlowBoardComponent.prototype.getInstanceByElement( $( this ) ),
                                flowId = $( self ).closest( 
'.flow-topic-titlebar' ).parent().data( 'flow-id' );
@@ -616,11 +617,13 @@
                                revisionId = result.posts[topicId];
                                revision = result.revisions[revisionId];
 
-                               // FIXME: Api should be returning moderation 
state. Why not?
-                               revision.isModerated = revision.moderateState 
=== 'close';
-
-                               // FIXME: Hackily remove the moderated class 
(avoids re-rendering entire post)
-                               $target.parents( '.flow-topic' ).removeClass( 
'flow-topic-moderated' );
+                               if ( !revision.isModerated ) {
+                                       $topic.removeClass( 
'flow-topic-moderated' ).
+                                               removeClass( 
'flow-topic-moderatestate-close' );
+                               } else {
+                                       $topic.addClass( 'flow-topic-moderated' 
).
+                                               addClass( 
'flow-topic-moderatestate-close' );
+                               }
 
                                // Update view of the title bar
                                $topicTitleBar = $(
diff --git a/tests/qunit/new/components/test_flow-board.js 
b/tests/qunit/new/components/test_flow-board.js
index 3b71c69..055f89d 100644
--- a/tests/qunit/new/components/test_flow-board.js
+++ b/tests/qunit/new/components/test_flow-board.js
@@ -7,12 +7,101 @@
 
 QUnit.module( 'ext.flow: FlowBoardComponent', {
        setup: function() {
+               var stub;
                this.$el = $( '<div class="flow-component" 
data-flow-component="board">' );
                this.component = mw.flow.initComponent( this.$el );
+               stub = this.sandbox.stub( this.component.API, 'apiCall' );
+               stub.withArgs( {
+                       action: 'flow',
+                       submodule: 'view-topic',
+                       workflow: 's18cjkj1bs3rkt13',
+                       page: 'Topic:S18cjkj1bs3rkt13'
+               } ).returns(
+                       new $.Deferred().resolve( {
+                               flow: {
+                                       'view-topic': {
+                                               result: {
+                                                       topic: {
+                                                               roots: [ 
's18cjkj1bs3rkt13' ],
+                                                               posts: {
+                                                                       
s18cjkj1bs3rkt13: '4'
+                                                               },
+                                                               revisions: {
+                                                                       '4': {
+                                                                               
content: {
+                                                                               
        format: 'html',
+                                                                               
        content: 'Hi'
+                                                                               
},
+                                                                               
changeType: "close-topic",
+                                                                               
isModerated: false
+                                                                       }
+                                                               }
+                                                       },
+                                               }
+                                       }
+                               }
+                       } )
+               );
+               stub.withArgs( {
+                       action: 'flow',
+                       submodule: 'view-topic',
+                       workflow: 't18cjkj1bs3rkt13',
+                       page: 'Topic:T18cjkj1bs3rkt13'
+               } ).returns(
+                       new $.Deferred().resolve( {
+                               flow: {
+                                       'view-topic': {
+                                               result: {
+                                                       topic: {
+                                                               roots: [ 
't18cjkj1bs3rkt13' ],
+                                                               posts: {
+                                                                       
t18cjkj1bs3rkt13: '4'
+                                                               },
+                                                               revisions: {
+                                                                       '4': {
+                                                                               
changeType: "restore-topic",
+                                                                               
content: {
+                                                                               
        format: 'html',
+                                                                               
        content: 'Hi'
+                                                                               
},
+                                                                               
isModerated: true
+                                                                       }
+                                                               }
+                                                       },
+                                               }
+                                       }
+                               }
+                       } )
+               );
                this.UI = this.component.constructor.UI;
        }
 } );
 
+QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 2, function( 
assert ) {
+       var
+               $topic = $( '<div class="flow-topic" 
data-flow-id="s18cjkj1bs3rkt13">' ).
+                       addClass( 'flow-topic-moderatestate-close 
flow-topic-moderated' ).
+                       appendTo( this.$el ),
+               $titleBar = $( '<div class="flow-topic-titlebar">' ).appendTo( 
$topic ),
+               info = { status: 'done', $target: $titleBar };
+
+       this.UI.events.apiHandlers.closeOpenTopic.call( $titleBar, info );
+       assert.strictEqual( $topic.hasClass( 'flow-topic-moderated' ), false, 
'No longer has the moderated state.' );
+       assert.strictEqual( $topic.hasClass( 'flow-topic-moderatestate-close' 
), false, 'No longer has the moderated close state.' );
+} );
+
+QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 2, function( 
assert ) {
+       var
+               $topic = $( '<div class="flow-topic" 
data-flow-id="t18cjkj1bs3rkt13">' ).
+                       appendTo( this.$el ),
+               $titleBar = $( '<div class="flow-topic-titlebar">' ).appendTo( 
$topic ),
+               info = { status: 'done', $target: $titleBar };
+
+       this.UI.events.apiHandlers.closeOpenTopic.call( $titleBar, info );
+       assert.strictEqual( $topic.hasClass( 'flow-topic-moderated' ), true, 
'Has the moderated state.' );
+       assert.strictEqual( $topic.hasClass( 'flow-topic-moderatestate-close' 
), true, 'Has the moderated close state.' );
+} );
+
 QUnit.test( 'FlowBoardComponent.UI.events.apiHandlers.preview', 6, function( 
assert ) {
        var $container = this.$el,
                $form = $( '<form>' ).appendTo( $container ),

-- 
To view, visit https://gerrit.wikimedia.org/r/156739
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I15a09c5b057de8e7d24e5c1b953bd36dfe72a40c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to