Skip to content

Commit

Permalink
[tests-only] Added more GUI tests for sharing with user (part 03) (#9389
Browse files Browse the repository at this point in the history
)

* add/update more sharing tests

* skip delete test
  • Loading branch information
saw-jan committed Feb 17, 2022
1 parent c8d4bea commit 9f3ed0c
Show file tree
Hide file tree
Showing 3 changed files with 238 additions and 80 deletions.
88 changes: 59 additions & 29 deletions test/gui/shared/scripts/pageObjects/PublicLinkDialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import names
import squish
import test
import datetime
from datetime import datetime


class PublicLinkDialog:
Expand Down Expand Up @@ -72,6 +72,20 @@ class PublicLinkDialog:
"visible": 1,
}

# to store current default public link expiry date
defaultExpiryDate = ''

@staticmethod
def setDefaultExpiryDate(defaultDate):
defaultDate = datetime.strptime(defaultDate, '%m/%d/%y')
PublicLinkDialog.defaultExpiryDate = (
f"{defaultDate.year}-{defaultDate.month}-{defaultDate.day}"
)

@staticmethod
def getDefaultExpiryDate():
return PublicLinkDialog.defaultExpiryDate

def openPublicLinkDialog(self):
squish.mouseClick(
squish.waitForObject(self.PUBLIC_LINKS_TAB),
Expand Down Expand Up @@ -144,35 +158,40 @@ def setExpirationDate(self, expireDate):
if not enabled:
self.toggleExpirationDate()

expDate = datetime.datetime.strptime(expireDate, '%Y-%m-%d')
expYear = expDate.year - 2000
squish.mouseClick(
squish.waitForObject(self.EXPIRATION_DATE_FIELD),
0,
0,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
squish.nativeType("<Delete>")
squish.nativeType("<Delete>")
squish.nativeType(expDate.month)
squish.nativeType(expDate.day)
squish.nativeType(expYear)
squish.nativeType("<Return>")

actualDate = squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
expectedDate = f"{expDate.month}/{expDate.day}/{expYear}"
if not actualDate == expectedDate:
# retry with workaround
self.setExpirationDateWithWorkaround(expYear, expDate.month, expDate.day)
if not expireDate == "default":
expDate = datetime.strptime(expireDate, '%Y-%m-%d')
expYear = expDate.year - 2000
squish.mouseClick(
squish.waitForObject(self.EXPIRATION_DATE_FIELD),
0,
0,
squish.Qt.NoModifier,
squish.Qt.LeftButton,
)
squish.nativeType("<Delete>")
squish.nativeType("<Delete>")
squish.nativeType(expDate.month)
squish.nativeType(expDate.day)
squish.nativeType(expYear)
squish.nativeType("<Return>")

squish.waitFor(
lambda: (test.vp("publicLinkExpirationProgressIndicatorInvisible"))
)
test.compare(
str(squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText),
str(expectedDate),
)
actualDate = str(
squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
)
expectedDate = f"{expDate.month}/{expDate.day}/{expYear}"
if not actualDate == expectedDate:
# retry with workaround
self.setExpirationDateWithWorkaround(
expYear, expDate.month, expDate.day
)
squish.waitFor(
lambda: (test.vp("publicLinkExpirationProgressIndicatorInvisible"))
)
else:
defaultDate = str(
squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText
)
PublicLinkDialog.setDefaultExpiryDate(defaultDate)

# This workaround is needed because the above function 'setExpirationDate'
# will not work while creating new public link
Expand Down Expand Up @@ -246,3 +265,14 @@ def verifyResource(self, resource):
str(squish.waitForObjectExists(self.ITEM_TO_SHARE).text),
resource,
)

def verifyExpirationDate(self, expectedDate):
expectedDate = datetime.strptime(expectedDate, '%Y-%m-%d')
# date format in client UI is 'mm/dd/yy' e.g. '01/15/22'
expYear = expectedDate.year - 2000
expectedDate = f"{expectedDate.month}/{expectedDate.day}/{expYear}"

test.compare(
str(squish.waitForObjectExists(self.EXPIRATION_DATE_FIELD).displayText),
str(expectedDate),
)
39 changes: 36 additions & 3 deletions test/gui/shared/steps/steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import names
import os
import sys
from os import listdir
from os import listdir, rename
from os.path import isfile, join, isdir
import re
import urllib.request
Expand Down Expand Up @@ -399,13 +399,24 @@ def createFolder(context, foldername, username=None):
os.makedirs(path)


def renameFileFolder(context, source, destination):
source = join(context.userData['currentUserSyncPath'], source)
destination = join(context.userData['currentUserSyncPath'], destination)
rename(source, destination)


@When('the user copies the folder "|any|" to "|any|"')
def step(context, sourceFolder, destinationFolder):
source_dir = join(context.userData['currentUserSyncPath'], sourceFolder)
destination_dir = join(context.userData['currentUserSyncPath'], destinationFolder)
shutil.copytree(source_dir, destination_dir)


@When(r'the user renames a (file|folder) "([^"]*)" to "([^"]*)"', regexp=True)
def step(context, type, source, destination):
renameFileFolder(context, source, destination)


@Given(r"^(.*) on the server (.*)$", regexp=True)
def step(context, stepPart1, stepPart2):
executeStepThroughMiddleware(context, "Given " + stepPart1 + " " + stepPart2)
Expand Down Expand Up @@ -689,6 +700,21 @@ def step(context, resource, password):
createPublicLinkShare(context, resource, password)


@Then('the expiration date of the last public link of file "|any|" should be "|any|"')
def step(context, resource, expiryDate):
openSharingDialog(context, resource)
publicLinkDialog = PublicLinkDialog()
publicLinkDialog.openPublicLinkDialog()

if expiryDate.strip("%") == "default":
expiryDate = PublicLinkDialog.getDefaultExpiryDate()

publicLinkDialog.verifyExpirationDate(expiryDate)

shareItem = SharingDialog()
shareItem.closeSharingDialog()


def setExpirationDateWithVerification(resource, publicLinkName, expireDate):
publicLinkDialog = PublicLinkDialog()
publicLinkDialog.verifyResource(resource)
Expand Down Expand Up @@ -725,11 +751,18 @@ def step(context):
linkSettings = {}
for row in context.table:
linkSettings[row[0]] = row[1]

if "path" not in linkSettings:
raise Exception("'path' is required but not given.")

if "expireDate" in linkSettings and linkSettings['expireDate'] == "%default%":
linkSettings['expireDate'] = linkSettings['expireDate'].strip("%")

createPublicLinkShare(
context,
resource=linkSettings['path'],
password=linkSettings['password'],
expireDate=linkSettings['expireDate'],
password=linkSettings['password'] if "password" in linkSettings else None,
expireDate=linkSettings['expireDate'] if "expireDate" in linkSettings else None,
)


Expand Down
Loading

0 comments on commit 9f3ed0c

Please sign in to comment.