jenkins-bot has submitted this change and it was merged.

Change subject: Preload new topic
......................................................................


Preload new topic

URL parameters can be used to preload new topic
title and content on a flow board. This was broken
when the new topic handlebar template was replaced
by a widget.

Adding browser tests to detect regression in the future.

Bug: T112037
Change-Id: I183757cc5e3ed2f1340ba3f425dbc534bdbc86f0
---
M includes/Block/TopicList.php
M modules/flow-initialize.js
M modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
A tests/browser/features/preload.feature
A tests/browser/features/step_definitions/preload_steps.rb
M tests/browser/features/support/div_extension.rb
A tests/browser/features/support/pages/preloaded_flow_page.rb
7 files changed, 118 insertions(+), 1 deletion(-)

Approvals:
  Matthias Mullie: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/Block/TopicList.php b/includes/Block/TopicList.php
index ffdcd70..cbbcebd 100644
--- a/includes/Block/TopicList.php
+++ b/includes/Block/TopicList.php
@@ -307,7 +307,7 @@
         * @throws \MWException
         */
        protected function preloadTexts( $options ) {
-               if ( isset( $options['preload'] ) ) {
+               if ( isset( $options['preload'] ) && !empty( 
$options['preload'] ) ) {
                        $title = \Title::newFromText( $options['preload'] );
                        $page = \WikiPage::factory( $title );
                        if ( $page->isRedirect() ) {
@@ -318,6 +318,7 @@
                        if ( $page->exists() ) {
                                $content = $page->getContent( \Revision::RAW );
                                $options['content'] = $content->serialize();
+                               $options['format'] = 'wikitext';
                        }
                }
 
diff --git a/modules/flow-initialize.js b/modules/flow-initialize.js
index c1b94a6..1f13d44 100644
--- a/modules/flow-initialize.js
+++ b/modules/flow-initialize.js
@@ -14,6 +14,7 @@
                        pageTitle = mw.Title.newFromText( mw.config.get( 
'wgPageName' ) ),
                        $component = $( '.flow-component' ),
                        $board = $( '.flow-board' ),
+                       preloadTopic, preloadContent, preloadFormat,
                        finishLoading = function () {
                                $component.addClass( 'flow-component-ready' );
                                $( '.flow-ui-load-overlay' ).hide();
@@ -352,6 +353,13 @@
                        mw.flow.system.populateBoardFromApi();
                }
 
+               preloadTopic = OO.getProp( dataBlob, 'blocks', 'topiclist', 
'submitted', 'topic' );
+               preloadContent = OO.getProp( dataBlob, 'blocks', 'topiclist', 
'submitted', 'content' );
+               preloadFormat = OO.getProp( dataBlob, 'blocks', 'topiclist', 
'submitted', 'format' );
+               if ( preloadTopic || preloadContent ) {
+                       newTopicWidget.preload( preloadTopic, preloadContent, 
preloadFormat );
+               }
+
                // Show the board
                finishLoading();
        } );
diff --git a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js 
b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
index dd9510a..6247307 100644
--- a/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
+++ b/modules/flow/ui/widgets/mw.flow.ui.NewTopicWidget.js
@@ -99,6 +99,13 @@
         * @private
         */
        mw.flow.ui.NewTopicWidget.prototype.onTitleFocusIn = function () {
+               this.activate();
+       };
+
+       /**
+        * Expand the widget and make it ready to create a new topic
+        */
+       mw.flow.ui.NewTopicWidget.prototype.activate = function () {
                if ( !this.isExpanded() ) {
                        // Expand the editor
                        this.toggleExpanded( true );
@@ -108,6 +115,22 @@
        };
 
        /**
+        * Preload the widget with title and content.
+        *
+        * @param {string} title
+        * @param {string} content
+        * @param {string} format
+        */
+       mw.flow.ui.NewTopicWidget.prototype.preload = function ( title, 
content, format ) {
+               this.activate();
+               this.title.setValue( title );
+
+               if ( content && format ) {
+                       this.editor.setContent( content, format ).then( 
this.updateSaveButtonState.bind( this ) );
+               }
+       };
+
+       /**
         * Respond to keydown events in title input, and cancel when escape is 
pressed.
         * @param {jQuery.Event} e Keydown event
         */
diff --git a/tests/browser/features/preload.feature 
b/tests/browser/features/preload.feature
new file mode 100644
index 0000000..7d7de47
--- /dev/null
+++ b/tests/browser/features/preload.feature
@@ -0,0 +1,22 @@
+@chrome @firefox @internet_explorer_10
+@clean
[email protected]
+Feature: preload
+
+  Background:
+    Given there is a page to preload content from
+
+  Scenario: Preloading title and content
+    When I am on Flow page with the title and content preload parameters
+    Then the title is preloaded
+    And the content is preloaded
+
+  Scenario: Preloading title only
+    When I am on Flow page with the title preload parameter
+    Then the title is preloaded
+    And the content is empty
+
+  Scenario: Preloading content only
+    When I am on Flow page with the content preload parameter
+    Then the content is preloaded
+    And the title is empty
diff --git a/tests/browser/features/step_definitions/preload_steps.rb 
b/tests/browser/features/step_definitions/preload_steps.rb
new file mode 100644
index 0000000..34f72a2
--- /dev/null
+++ b/tests/browser/features/step_definitions/preload_steps.rb
@@ -0,0 +1,54 @@
+Given(/^there is a page to preload content from$/) do
+  page_name = 'Preloaded_body_example'
+  @content_to_preload = 'this is the content of the preload page'
+  api.create_page page_name, @content_to_preload
+end
+
+When(/^I am on Flow page with the title and content preload parameters$/) do
+  @title = @data_manager.get 'new_topic_title'
+  visit(PreloadedFlowPage,
+        using_params: {
+          topiclist_preloadtitle: @title,
+          topiclist_preload: 'Preloaded_body_example'
+        })
+  step 'The Flow page is fully loaded'
+  step 'page has no ResourceLoader errors'
+end
+
+Then(/^the title is preloaded$/) do
+  on(AbstractFlowPage) do |page|
+    expect(page.new_topic_title).to eq @title
+  end
+end
+
+Then(/^the content is preloaded$/) do
+  on(AbstractFlowPage) do |page|
+    expect(page.new_topic_body_element.when_present.text).to eq 
@content_to_preload
+  end
+end
+
+When(/^I am on Flow page with the title preload parameter$/) do
+  @title = @data_manager.get 'new_topic_title'
+  visit(PreloadedFlowPage, using_params: { topiclist_preloadtitle: @title })
+  step 'The Flow page is fully loaded'
+  step 'page has no ResourceLoader errors'
+end
+
+Then(/^the content is empty$/) do
+  on(AbstractFlowPage) do |page|
+    expect(page.new_topic_body_element.when_present.text).to eq ''
+  end
+end
+
+When(/^I am on Flow page with the content preload parameter$/) do
+  @title = @data_manager.get 'new_topic_title'
+  visit(PreloadedFlowPage, using_params: { topiclist_preload: 
'Preloaded_body_example' })
+  step 'The Flow page is fully loaded'
+  step 'page has no ResourceLoader errors'
+end
+
+Then(/^the title is empty$/) do
+  on(AbstractFlowPage) do |page|
+    expect(page.new_topic_title).to eq ''
+  end
+end
diff --git a/tests/browser/features/support/div_extension.rb 
b/tests/browser/features/support/div_extension.rb
index 9d481a3..59690e8 100644
--- a/tests/browser/features/support/div_extension.rb
+++ b/tests/browser/features/support/div_extension.rb
@@ -13,5 +13,9 @@
       Watir::Wait.until { !self.disabled? }
       self
     end
+
+    def text
+      value
+    end
   end
 end
diff --git a/tests/browser/features/support/pages/preloaded_flow_page.rb 
b/tests/browser/features/support/pages/preloaded_flow_page.rb
new file mode 100644
index 0000000..7a746a6
--- /dev/null
+++ b/tests/browser/features/support/pages/preloaded_flow_page.rb
@@ -0,0 +1,5 @@
+class PreloadedFlowPage
+  include PageObject
+
+  page_url "Talk:Flow_QA?topiclist_preloadtitle=<%= 
params[:topiclist_preloadtitle] %>&topiclist_preload=<%= 
params[:topiclist_preload] %>"
+end

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I183757cc5e3ed2f1340ba3f425dbc534bdbc86f0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to