Gilles has uploaded a new change for review.

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

Change subject: Duplicate name test
......................................................................

Duplicate name test

Also added some code to handle posting specific content. This
ensures we don't trigger a duplicate content error before the
name error is triggered. This will also be useful for testing
duplicate content later.

Bug: T86121
Change-Id: Ie262ca6b96534c970215d83231d8921c1b2e594e
---
M tests/browser/features/step_definitions/upload_wizard_steps.rb
M tests/browser/features/support/pages/upload_page.rb
M tests/browser/features/upload_wizard.feature
3 files changed, 64 insertions(+), 32 deletions(-)


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

diff --git a/tests/browser/features/step_definitions/upload_wizard_steps.rb 
b/tests/browser/features/step_definitions/upload_wizard_steps.rb
index 68e681e..1547a34 100644
--- a/tests/browser/features/step_definitions/upload_wizard_steps.rb
+++ b/tests/browser/features/step_definitions/upload_wizard_steps.rb
@@ -12,6 +12,13 @@
 require "tempfile"
 require "chunky_png"
 
+def make_temp_image(filename, shade, width, height)
+  path = "#{Dir.tmpdir}/#{filename}"
+  image = ChunkyPNG::Image.new(shade, width, height)
+  image.save path
+  path
+end
+
 Given(/^I am logged out$/) do
   visit LogoutPage
 end
@@ -76,24 +83,34 @@
 
 When(/^there should be (\d+) uploads$/) do |countStr|
   count = countStr.to_i
-  uploads = on(UploadPage).getUploads
+  uploads = on(UploadPage).get_uploads
   uploads.length.should eql(count)
 end
 
 When(/^I click the Skip checkbox$/) do
   on(LearnPage).check_tutorial_skip
 end
-When(/^I add file (\S+)$/) do |file_name|
-  path = "#{Dir.tmpdir}/#{file_name}"
 
-  image = ChunkyPNG::Image.new(Random.new.rand(255), Random.new.rand(255), 
Random.new.rand(255))
-  image.save path
+When(/^I add file (\S+)$/) do |filename|
+  shade = Random.new.rand(255)
+  width = Random.new.rand(255)
+  height = Random.new.rand(255)
+  path = make_temp_image(filename, shade, width, height)
+  on(UploadPage).add_file(path)
+end
 
-  on(UploadPage).addFile(path)
+When(/^I add file (\S+) with (\d+)% black, (\d+)px x (\d+)px$/) do |filename, 
shadeStr, widthStr, heightStr|
+  shade = ((shadeStr.to_i / 100.0) * 255).round
+  width = widthStr.to_i
+  height = heightStr.to_i
+  path = make_temp_image(filename, shade, width, height)
+  on(UploadPage).add_file(path)
 end
-When(/^I remove file (.+)$/) do |fileName|
-  on(UploadPage).removeFile(fileName)
+
+When(/^I remove file (.+)$/) do |filename|
+  on(UploadPage).remove_file(filename)
 end
+
 Then(/^link to log in should appear$/) do
   on(UploadWizardPage).logged_in_element.should be_visible
 end
@@ -139,6 +156,11 @@
   on(UsePage)
   @browser.url.should match /Special:UploadWizard/
 end
-Then(/^there should be an upload for (\S+)$/) do |fileName|
-  on(UploadPage).hasUpload(fileName).should == true
+
+Then(/^there should be an upload for (\S+)$/) do |filename|
+  on(UploadPage).has_upload(filename).should == true
+end
+
+Then(/^a duplicate name error should appear$/) do
+  on(UploadPage).duplicate_error_element.when_present.should be_visible
 end
diff --git a/tests/browser/features/support/pages/upload_page.rb 
b/tests/browser/features/support/pages/upload_page.rb
index 6221eca..bed9601 100644
--- a/tests/browser/features/support/pages/upload_page.rb
+++ b/tests/browser/features/support/pages/upload_page.rb
@@ -19,6 +19,7 @@
   page_url url
 
   span(:continue, text: "Continue")
+  p(:duplicate_error, text: /You are already uploading/)
 
   # We need to keep track of all the uploads on the page.
   # PageObjects are bad at finding elements that are repeated and change.
@@ -30,13 +31,10 @@
   # the page which is ready to accept new files. It is usually
   # invisible and its file input is styled to cover the button which
   # adds more files.
-  def getUploadInterfaceDivs(isFilled)
-    basicConstraint = "contains(@class,'mwe-upwiz-file')"
-    filledConstraint = "contains(@class,'filled')"
-    if !isFilled
-      filledConstraint = 'not(' + filledConstraint + ')'
-    end
-    constraints = [basicConstraint, filledConstraint].join(' and ')
+  def get_upload_interface_divs(is_filled)
+    basic_constraint = "contains(@class,'mwe-upwiz-file')"
+    filled_constraint = is_filled ? "contains(@class,'filled')" : 
"not(contains(@class,'filled'))"
+    constraints = [basic_constraint, filled_constraint].join(' and ')
     @browser.divs(
       xpath: "//div[@id='mwe-upwiz-filelist']/div[#{constraints}]"
     )
@@ -44,8 +42,8 @@
 
   # break the upload divs into objects with easy to access 'properties'
   # n.b. in xpath, .// will search relative to current node
-  def getUploadObjects(isFilled)
-    getUploadInterfaceDivs(isFilled).map do |uploadDiv|
+  def get_upload_objects(is_filled)
+    get_upload_interface_divs(is_filled).map do |uploadDiv|
       {
         fileInput: uploadDiv.file_field(xpath: './/input[@type="file"]'),
         indicator: uploadDiv.div(
@@ -63,42 +61,48 @@
 
   # return the filled uploads on the page (the visible stuff
   # with thumbnails and whatnot)
-  def getUploads
-    getUploadObjects(true)
+  def get_uploads
+    get_upload_objects(true)
   end
 
   # The last upload on the page is 'empty', waiting to be filled.
   # It's either the one represented by the initial big button, or
   # it's the one represented by the "add more files" button.
-  def getUploadToAdd
-    getUploadObjects(false)[0]
+  def get_upload_to_add
+    get_upload_objects(false)[0]
   end
 
   # Gets upload by name. Filenames *should* be unique to be uploaded, but can 
be
   # non-unique (they should be in an error state if so), so this always 
returns an array
-  def getUploadsByName(fileName)
-    getUploads.select{ |upload|
-      upload[:fileName].eql?(fileName)
+  def get_uploads_by_name(filename)
+    get_uploads.select{ |upload|
+      upload[:fileName].eql?(filename)
     }
   end
+
+  # for convenience in tests, when we know the filename is unique
+  def get_upload_by_name(filename)
+    get_uploads_by_name(filename)[0]
+  end
+
 
   # In PageObject, file fields are magic, you can assign a path to
   # upload a file. However, this file field is a Watir::FileField,
   # so we use .set()
-  def addFile(path)
-    getUploadToAdd[:fileInput].set(path)
+  def add_file(path)
+    get_upload_to_add[:fileInput].set(path)
   end
 
   # Remove file(s) with a filename. Note, this is basename, not the full path
-  def removeFile(fileName)
-    getUploadsByName(fileName).each do |upload|
+  def remove_file(filename)
+    get_uploads_by_name(filename).each do |upload|
       upload[:removeCtrl].click
     end
   end
 
   # Check if an upload exists, by name. Return boolean
-  def hasUpload(fileName)
-    getUploadsByName(fileName).length > 0
+  def has_upload(filename)
+    get_uploads_by_name(filename).length > 0
   end
 
 end
diff --git a/tests/browser/features/upload_wizard.feature 
b/tests/browser/features/upload_wizard.feature
index 5d342a9..c464331 100644
--- a/tests/browser/features/upload_wizard.feature
+++ b/tests/browser/features/upload_wizard.feature
@@ -64,6 +64,12 @@
      And there should be an upload for image.png
      And there should be an upload for image3.png
 
+  Scenario: Same name, different content
+    When I click Next button at Learn page
+      And I add file image.png with 50% black, 50px x 50px
+      And I add file image.png with 100% black, 100px x 70px
+    Then a duplicate name error should appear
+
   Scenario: Navigate to Describe page
     When I click Next button at Learn page
       And I add file image.png

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie262ca6b96534c970215d83231d8921c1b2e594e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/UploadWizard
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>
Gerrit-Reviewer: Neilk <ne...@neilk.net>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to