Gilles has uploaded a new change for review.

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

Change subject: Respect preferences' default license when picking a license per 
file
......................................................................

Respect preferences' default license when picking a license per file

Also adds browser test coverage for the license preference

Bug: T89717
Change-Id: I6eb1b2183ce8c3626f05ffd3807dde5397f07d0a
---
M resources/mw.UploadWizardLicenseInput.js
M tests/browser/features/step_definitions/upload_wizard_steps.rb
M tests/browser/features/support/pages/describe_page.rb
M tests/browser/features/support/pages/preferences_page.rb
M tests/browser/features/support/pages/release_rights_page.rb
A tests/browser/features/upload_wizard_preferences.feature
6 files changed, 139 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/UploadWizard 
refs/changes/91/191191/1

diff --git a/resources/mw.UploadWizardLicenseInput.js 
b/resources/mw.UploadWizardLicenseInput.js
index 4d82f9e..bacf1eb 100644
--- a/resources/mw.UploadWizardLicenseInput.js
+++ b/resources/mw.UploadWizardLicenseInput.js
@@ -32,7 +32,15 @@
 
                this.type = config.type === 'or' ? 'radio' : 'checkbox';
 
-               this.defaults = ( config.licenses && config.licenses[0] ) ? [ 
config.licenses[0] ] : [];
+               this.defaults = [];
+
+               if ( config.defaults && config.defaults[0] ) {
+                       this.defaults = config.defaults;
+               } else if ( config.licenses && config.licenses[0] ) {
+                       this.defaults = [ config.licenses[0] ];
+               }
+
+               console.log( this.defaults, config.defaults, config.license );
 
                mw.UploadWizardLicenseInput.prototype.count++;
                this.name = 'license' + 
mw.UploadWizardLicenseInput.prototype.count;
@@ -121,10 +129,14 @@
                 *
                 */
                createInputs: function ( $el, config, $groupToggler ) {
-                       var input = this;
-                       if ( config.licenses === undefined || typeof 
config.licenses !== 'object' ) {
+                       var defaultLicense,
+                               input = this;
+
+
+                       if ( config.licenses === undefined|| typeof 
config.licenses !== 'object' ) {
                                throw new Error( 'improper license config' );
                        }
+
                        $.each( config.licenses, function ( i, licenseName ) {
                                if ( 
mw.UploadWizard.config.licenses[licenseName] !== undefined ) {
                                        var $customDiv,
@@ -140,6 +152,12 @@
                                        // this is so we can tell if a 
particular license ought to be set in setValues()
                                        $input.data( 'licenseName', licenseName 
);
 
+                                       // If this is the default, check it
+                                       if ( licenseName === defaultLicense ) {
+                                               console.log( 'checking 
default', licenseName );
+                                               $input.prop( 'checked', true );
+                                       }
+
                                        // this is so if a single input in a 
group changes, we open the entire "toggler" that was hiding them
                                        $input.data( 'groupToggler', 
$groupToggler );
 
diff --git a/tests/browser/features/step_definitions/upload_wizard_steps.rb 
b/tests/browser/features/step_definitions/upload_wizard_steps.rb
index 7ef8814..bdc3967 100644
--- a/tests/browser/features/step_definitions/upload_wizard_steps.rb
+++ b/tests/browser/features/step_definitions/upload_wizard_steps.rb
@@ -31,6 +31,30 @@
   end
 end
 
+When(/^I set the default license to Own work - Creative Commons CC0 Waiver in 
my Preferences$/) do
+  visit(PreferencesPage) do |page|
+    page.upload_wizard_pref_tab_element.when_present.click
+    page.select_own_cc_zero_radio
+    page.preferences_save_button_element.click
+  end
+end
+
+When(/^I set the default license to Someone else's work - Original work of 
NASA in my Preferences$/) do
+  visit(PreferencesPage) do |page|
+    page.upload_wizard_pref_tab_element.when_present.click
+    page.select_thirdparty_nasa_radio
+    page.preferences_save_button_element.click
+  end
+end
+
+When(/^I set the default license to Use whatever the default is in my 
Preferences$/) do
+  visit(PreferencesPage) do |page|
+    page.upload_wizard_pref_tab_element.when_present.click
+    page.select_default_radio
+    page.preferences_save_button_element.click
+  end
+end
+
 When(/^click button Continue$/) do
   on(UploadPage).continue_element.when_present(15).click
 end
@@ -45,16 +69,23 @@
 end
 
 When(/^I click Next button at Learn page$/) do
+  sleep 1
   on(LearnPage).next_element.when_present(15).click
   on(LearnPage).wait_for_ajax
 end
 
 When(/^I click Next button at Release rights page$/) do
+  sleep 1
   on(ReleaseRightsPage).next_element.when_present(15).click
 end
 
 When(/^I click This file is my own work$/) do
   on(ReleaseRightsPage).select_my_own_work
+end
+
+When(/^I click Provide copyright information for each file$/) do
+  sleep 1 # Wait for animation to be over
+  on(ReleaseRightsPage).select_provide_copyright_information
 end
 
 When(/^I enter category$/) do
@@ -111,6 +142,10 @@
   on(UploadPage).remove_file(filename)
 end
 
+When(/^I click Use a different license for the first file$/) do
+  on(DescribePage).use_a_different_license_element.click
+end
+
 Then(/^link to log in should appear$/) do
   on(UploadWizardPage).logged_in_element.should be_visible
 end
@@ -164,3 +199,22 @@
 Then(/^a duplicate name error should appear$/) do
   on(UploadPage).duplicate_error_element.when_present.should be_visible
 end
+
+Then(/^Creative Commons CC0 Waiver should be checked for the first file$/) do
+  on(DescribePage).own_cc_zero_radio_selected?.should == true
+end
+
+Then(/^Creative Commons Attribution ShareAlike 4.0 should be checked for the 
first file$/) do
+  on(DescribePage).own_cc_by_sa_4_radio_selected?.should == true
+end
+
+Then(/^Original work of NASA should be checked for the first file$/) do
+  on(DescribePage).thirdparty_nasa_radio_selected?.should == true
+end
+
+Then(/^The Release rights radio buttons should be unchecked$/) do
+  on(DescribePage) do |page|
+    page.own_work_radio_selected?.should == false
+    page.thirdparty_radio_selected?.should == false
+  end
+end
diff --git a/tests/browser/features/support/pages/describe_page.rb 
b/tests/browser/features/support/pages/describe_page.rb
index 9297ae1..79642e6 100644
--- a/tests/browser/features/support/pages/describe_page.rb
+++ b/tests/browser/features/support/pages/describe_page.rb
@@ -26,4 +26,12 @@
     page.next_parent_element.span_element(text: "Next")
   end
   text_field(:title, id: "title0")
+
+  a(:use_a_different_license, xpath: 
"//div[@id='mwe-upwiz-stepdiv-details']//form[@id='mwe-upwiz-detailsform0']//p[@class='mwe-more-options']/a")
+
+  radio(:own_cc_zero_radio, id: "license3_4")
+  radio(:thirdparty_nasa_radio, id: "license4_13")
+  radio(:own_cc_by_sa_4_radio, id: "license3_0")
+  radio(:own_work_radio, id: "deedChooser2-ownwork")
+  radio(:thirdparty_radio, id: "deedChooser2-thirdparty")
 end
diff --git a/tests/browser/features/support/pages/preferences_page.rb 
b/tests/browser/features/support/pages/preferences_page.rb
index 48c0a12..8143e26 100644
--- a/tests/browser/features/support/pages/preferences_page.rb
+++ b/tests/browser/features/support/pages/preferences_page.rb
@@ -21,5 +21,8 @@
   a(:upload_wizard_pref_tab, id: "preftab-uploads")
   checkbox(:reset_skip_checkbox, id: "mw-input-wpupwiz_skiptutorial")
   button(:preferences_save_button, id: "prefcontrol")
-
+  checkbox(:reset_skip_checkbox, id: "mw-input-wpupwiz_skiptutorial")
+  radio(:own_cc_zero_radio, id: "mw-input-wpupwiz_deflicense-ownwork-cc-zero")
+  radio(:thirdparty_nasa_radio, id: 
"mw-input-wpupwiz_deflicense-thirdparty-pd-usgov-nasa")
+  radio(:default_radio, id: "mw-input-wpupwiz_deflicense-default")
 end
diff --git a/tests/browser/features/support/pages/release_rights_page.rb 
b/tests/browser/features/support/pages/release_rights_page.rb
index 208dbb3..58ecc22 100644
--- a/tests/browser/features/support/pages/release_rights_page.rb
+++ b/tests/browser/features/support/pages/release_rights_page.rb
@@ -19,6 +19,7 @@
   page_url url
 
   radio(:my_own_work, id: "deedChooser1-ownwork")
+  radio(:provide_copyright_information, id: "deedChooser1-custom")
   div(:next_parent, id: "mwe-upwiz-stepdiv-deeds")
   span(:next) do |page|
     page.next_parent_element.span_element(text: "Next")
diff --git a/tests/browser/features/upload_wizard_preferences.feature 
b/tests/browser/features/upload_wizard_preferences.feature
new file mode 100644
index 0000000..12bb660
--- /dev/null
+++ b/tests/browser/features/upload_wizard_preferences.feature
@@ -0,0 +1,51 @@
+#
+# This file is subject to the license terms in the COPYING file found in the
+# UploadWizard top-level directory and at
+# 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/COPYING.
 No part of
+# UploadWizard, including this file, may be copied, modified, propagated, or
+# distributed except according to the terms contained in the COPYING file.
+#
+# Copyright 2012-2014 by the Mediawiki developers. See the CREDITS file in the
+# UploadWizard top-level directory and at
+# 
https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FUploadWizard/HEAD/CREDITS
+#
+@chrome @commons.wikimedia.beta.wmflabs.org @firefox @login 
@test2.wikipedia.org
+Feature: UploadWizard preferences
+
+  Background:
+    Given I am logged in
+      And my Preferences Skip tutorial box is unchecked
+
+  Scenario: Set license preference to Own work - Creative Commons CC0 Waiver
+    When I set the default license to Own work - Creative Commons CC0 Waiver 
in my Preferences
+      And I navigate to Upload Wizard
+      And I click Next button at Learn page
+      And I add file image.png
+      And I add file image2.png
+      And click button Continue
+      And I click Provide copyright information for each file
+      And I click Next button at Release rights page
+      And I click Use a different license for the first file
+    Then Creative Commons CC0 Waiver should be checked for the first file
+
+  Scenario: Set license preference to Someone else's work - Original work of 
NASA
+    When I set the default license to Someone else's work - Original work of 
NASA in my Preferences
+      And I navigate to Upload Wizard
+      And I click Next button at Learn page
+      And I add file image.png
+      And I add file image2.png
+      And click button Continue
+      And I click Provide copyright information for each file
+      And I click Next button at Release rights page
+    Then Original work of NASA should be checked for the first file
+
+  Scenario: Set license preference to Use whatever the default is
+    When I set the default license to Use whatever the default is in my 
Preferences
+      And I navigate to Upload Wizard
+      And I click Next button at Learn page
+      And I add file image.png
+      And I add file image2.png
+      And click button Continue
+      And I click Provide copyright information for each file
+      And I click Next button at Release rights page
+    Then The Release rights radio buttons should be unchecked
\ No newline at end of file

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6eb1b2183ce8c3626f05ffd3807dde5397f07d0a
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>

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

Reply via email to