From 036a0ed08f7de1a1f10b5684be43d677b10d3b3f Mon Sep 17 00:00:00 2001 From: Kiran Parajuli Date: Fri, 6 Mar 2020 15:18:43 +0545 Subject: [PATCH] Added acceptance test for changing existing expiration date of a user share --- .../shareWithGroups.feature | 19 ++++++++ .../shareWithUsers.feature | 17 +++++++ .../FilesPageElement/expirationDatePicker.js | 28 ++++++++++++ .../FilesPageElement/publicLinksDialog.js | 35 ++------------- .../FilesPageElement/sharingDialog.js | 22 ++++++++-- .../stepDefinitions/sharingContext.js | 44 ++++++++++++++++++- 6 files changed, 129 insertions(+), 36 deletions(-) diff --git a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature index 72ef06a3779..b92cbc6092d 100644 --- a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature +++ b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature @@ -349,3 +349,22 @@ Feature: Sharing files and folders with internal groups | fileName | expectedCollaborators | | simple-folder | User Two, grp1 | + Scenario: change existing expiration date of an existing share with another internal group + Given user "user3" has created a new share with following settings + | path | lorem.txt | + | shareTypeString | group | + | shareWith | grp1 | + | expireDate | 2038-10-12 | + And user "user3" has logged in using the webUI + When the user edits share with group "grp1" of file "lorem.txt" changing following + | expireDate | +7 | + Then user "user1" should have received a share with target "lorem (2).txt" and expiration date in 7 days + Then user "user2" should have received a share with target "lorem (2).txt" and expiration date in 7 days + And user "user3" should have a share with these details: + | field | value | + | path | /lorem.txt | + | share_type | group | + | uid_owner | user3 | + | share_with | grp1 | + | expiration | +7 | + diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature index 7573e846ea4..1b9f50689b5 100644 --- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature @@ -602,3 +602,20 @@ Feature: Sharing files and folders with internal users And user "user1" has logged in using the webUI When the user shares file "testimage.jpg" with user "User Two" using the webUI Then user "user2" should have received a share with target "testimage (2).jpg" and expiration date in 3 days + + Scenario: change existing expiration date of an existing share with another internal user + Given user "user1" has created a new share with following settings + | path | lorem.txt | + | shareWith | user2 | + | expireDate | 2038-10-12 | + And user "user1" has logged in using the webUI + When the user edits share with user "User Two" of file "lorem.txt" changing following + | expireDate | +7 | + Then user "user2" should have received a share with target "lorem (2).txt" and expiration date in 7 days + And user "user1" should have a share with these details: + | field | value | + | path | /lorem.txt | + | share_type | user | + | uid_owner | user1 | + | share_with | user2 | + | expiration | +7 | diff --git a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js index fe35bdf8959..2962405564a 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js +++ b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js @@ -1,4 +1,5 @@ const util = require('util') +const sharingHelper = require('../../helpers/sharingHelper') module.exports = { commands: { @@ -144,6 +145,30 @@ module.exports = { } }) return disabled + }, + /** + * sets expiration date on collaborators/public-link shares + * + * @param {string} value - provided date in format YYYY-MM-DD, or empty string to unset date + * @returns {Promise} + */ + setExpirationDate: async function (value) { + if (value === '') { + return this.click('@publicLinkDeleteExpirationDateButton') + } + value = sharingHelper.calculateDate(value) + const dateToSet = new Date(Date.parse(value)) + const year = dateToSet.getFullYear() + const month = dateToSet.toLocaleString('en-GB', { month: 'long' }) + const day = dateToSet.getDate() + await this + .initAjaxCounters() + .waitForElementVisible('@linkExpirationDateField') + .click('@linkExpirationDateField') + return this + .setExpiryDateYear(year) + .setExpiryDateMonth(month) + .setExpiryDateDay(day) } }, elements: { @@ -171,6 +196,9 @@ module.exports = { }, linkExpirationDateField: { selector: '.vdatetime-input' + }, + publicLinkDeleteExpirationDateButton: { + selector: '#oc-files-file-link-expire-date-delete' } } } diff --git a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js index 3ad1382986c..4e403122fbd 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js @@ -1,6 +1,5 @@ const util = require('util') const _ = require('lodash') -const sharingHelper = require('../../helpers/sharingHelper') module.exports = { commands: { @@ -65,32 +64,6 @@ module.exports = { .clearValue('@publicLinkPasswordField') .setValue('@publicLinkPasswordField', linkPassword) }, - /** - * sets expire date of the public link share using webUI - * - * @param {string} value - provided date in format YYYY-MM-DD, or empty string to unset date - * @returns {Promise} - */ - setPublicLinkExpiryDate: async function (value) { - const expirationDatePicker = this.api.page.FilesPageElement.expirationDatePicker() - if (value === '') { - return this.click('@publicLinkDeleteExpirationDateButton') - } - value = sharingHelper.calculateDate(value) - const dateToSet = new Date(Date.parse(value)) - const year = dateToSet.getFullYear() - const month = dateToSet.toLocaleString('en-GB', { month: 'long' }) - const day = dateToSet.getDate() - const linkExpirationDateField = expirationDatePicker.elements.linkExpirationDateField.selector - await this - .initAjaxCounters() - .waitForElementVisible(linkExpirationDateField) - .click(linkExpirationDateField) - return expirationDatePicker - .setExpiryDateYear(year) - .setExpiryDateMonth(month) - .setExpiryDateDay(day) - }, /** * function sets different fields for public link * @@ -106,7 +79,10 @@ module.exports = { } else if (key === 'password') { return this.setPublicLinkPassword(value) } else if (key === 'expireDate') { - return this.setPublicLinkExpiryDate(value) + return this.api.page + .FilesPageElement + .expirationDatePicker() + .setExpirationDate(value) } return this }, @@ -430,9 +406,6 @@ module.exports = { }, sidebarPrivateLinkIconCopied: { selector: '#files-sidebar-private-link-icon-copied' - }, - publicLinkDeleteExpirationDateButton: { - selector: '#oc-files-file-link-expire-date-delete' } } } diff --git a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js index 236f1a4b77b..246d97ea553 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js @@ -190,7 +190,7 @@ module.exports = { .waitForOutstandingAjaxCalls() .waitForElementNotPresent('@addShareSaveButton') }, - saveCollaboratorPermission: function () { + saveChanges: function () { return this.waitForElementVisible('@saveShareButton') .initAjaxCounters() .click('@saveShareButton') @@ -268,7 +268,7 @@ module.exports = { } } if (changed) { - await this.saveCollaboratorPermission() + await this.saveChanges() } else { await this.clickCancel() } @@ -298,7 +298,7 @@ module.exports = { for (const permission of enabledPermissions) { await this.toggleSinglePermission(permission) } - await this.saveCollaboratorPermission() + await this.saveChanges() }, /** * @@ -370,7 +370,7 @@ module.exports = { changeCollaboratorRole: async function (collaborator, newRole) { await collaboratorDialog.clickEditShare(collaborator) await this.changeCollaboratorRoleInDropdown(newRole) - return this.saveCollaboratorPermission() + return this.saveChanges() }, /** * @params {string} newRole @@ -485,6 +485,20 @@ module.exports = { } return this.useXpath().expect.element(collaboratorSelector).to.not.be.present + }, + /** + * @param collaborator + * @param value + * + * @return {Promise<*>} + */ + changeCollaboratorExpiryDate: async function (collaborator, value) { + await collaboratorDialog.clickEditShare(collaborator) + await this.api.page + .FilesPageElement + .expirationDatePicker() + .setExpirationDate(value) + return this.saveChanges() } }, elements: { diff --git a/tests/acceptance/stepDefinitions/sharingContext.js b/tests/acceptance/stepDefinitions/sharingContext.js index 1246d7fe588..1e6e2f206c3 100644 --- a/tests/acceptance/stepDefinitions/sharingContext.js +++ b/tests/acceptance/stepDefinitions/sharingContext.js @@ -87,7 +87,7 @@ Given('user {string} from remote server has shared {string} with user {string} f * @param {string} elementToShare path of file/folder being shared * @param {string} sharer username of the sharer * @param receiver username of the receiver - * @param shareType Type of share 0 = user, 1 = group, 3 = public (link), 6 = federated (cloud share). + * @param {number} shareType type of share user, group, public (link), federated (cloud share). * @param {string} permissionString permissions of the share for valid permissions see sharingHelper.PERMISSION_TYPES * @param {string} name name of the link (for public links), default = "New Share" * @param {object} extraParams Extra parameters allowed on the share @@ -128,6 +128,37 @@ const shareFileFolder = function ( httpHelper.checkOCSStatus(json, 'Could not create share. Message: ' + json.ocs.meta.message) }) } +/** + * create any share using dataTable + * + * @param {string} sharer + * @param {object} dataTable (attrs like: path, shareWith, expireDate, name, permissionString, + * shareTypeString, password can be passed inside dataTable) + * + * @return void + */ +Given('user {string} has created a new share with following settings', + function (sharer, dataTable) { + const settings = dataTable.rowsHash() + let expireDate = settings.expireDate + if (typeof expireDate !== 'undefined') { + expireDate = sharingHelper.calculateDate(expireDate) + } + const targetShareType = sharingHelper.humanReadableShareTypeToNumber(settings.shareTypeString) + return shareFileFolder( + settings.path, + sharer, + settings.shareWith, + targetShareType, + settings.permissionString, + settings.name, + { + expireDate: expireDate, + password: settings.password + } + ) + }) + /** * sets up data into a standard format for creating new public link share * @@ -742,6 +773,17 @@ When( } ) +When('the user edits share with user/group {string} of file/folder/resource {string} changing following', + async function (collaborator, resource, dataTable) { + const api = client.page.FilesPageElement + const settings = dataTable.rowsHash() + await api + .appSideBar() + .closeSidebar(100) + .openSharingDialog(resource) + return api.sharingDialog().changeCollaboratorExpiryDate(collaborator, settings.expireDate) + }) + Then('user {string} should be listed as {string} in the collaborators list on the webUI', function (user, role) { return assertCollaboratorslistContains('user', user, { role }) })