From c955ea7143e2cd73c7628bc89efcd445f5486cff Mon Sep 17 00:00:00 2001 From: Kiran Parajuli Date: Fri, 13 Mar 2020 10:47:53 +0545 Subject: [PATCH] wip1 --- .../shareWithGroups.feature | 7 ++- .../shareWithUsers.feature | 5 +- .../FilesPageElement/expirationDatePicker.js | 21 ++++--- .../FilesPageElement/publicLinksDialog.js | 11 +--- .../FilesPageElement/sharingDialog.js | 2 - .../stepDefinitions/sharingContext.js | 61 ++++--------------- 6 files changed, 34 insertions(+), 73 deletions(-) diff --git a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature index c02fc87ce08..9b775ca2601 100644 --- a/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature +++ b/tests/acceptance/features/webUISharingInternalGroups/shareWithGroups.feature @@ -367,7 +367,7 @@ Feature: Sharing files and folders with internal groups | share_with | grp1 | | expiration | +7 | - Scenario Outline: default expiration date on group share + Scenario Outline: auto set default expiration date on group share Given the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "42" And user "user3" has logged in using the webUI @@ -386,13 +386,13 @@ Feature: Sharing files and folders with internal groups | lorem.txt | lorem (2).txt | | simple-folder | simple-folder (2) | - Scenario Outline: enforced expiration date on group share + Scenario Outline: user cannot create a group share with expiry date beyond enforced maximum expiration date Given the setting "shareapi_default_expire_date_group_share" of app "core" has been set to "yes" And the setting "shareapi_enforce_expire_date_group_share" of app "core" has been set to "yes" And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "5" And user "user3" has logged in using the webUI When the user tries to share file "" with group "grp1" which expires in "+6" days using the webUI - Then enforced maximum expiration date for group share should be set in the expiration date input field of collaborators form on the webUI + Then the expiration date input field of collaborators form should have value with "+5" days on the webUI And user "user1" should not have created any shares Examples: | shared-resource | @@ -410,6 +410,7 @@ Feature: Sharing files and folders with internal groups | expireDate | +4 | And user "user3" has logged in using the webUI When the user tries to edit the collaborator expiry date of "grp1" of file "" to "+7" days using the webUI + Then the expiration date input field of collaborators form should have value with "+4" days on the webUI Then it should not be possible to save the pending share on the webUI And user "user1" should have received a share with target "" and expiration date in 4 days And user "user2" should have received a share with target "" and expiration date in 4 days diff --git a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature index 5791c82be48..cbc80255921 100644 --- a/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature +++ b/tests/acceptance/features/webUISharingInternalUsers/shareWithUsers.feature @@ -625,7 +625,7 @@ Feature: Sharing files and folders with internal users And the setting "shareapi_expire_after_n_days_user_share" of app "core" has been set to "5" And user "user1" has logged in using the webUI When the user tries to share file "" with user "User Two" which expires in "+6" days using the webUI - Then enforced maximum expiration date for user share should be set in the expiration date input field of collaborators form on the webUI + Then the expiration date input field of collaborators form should have value with "+5" days on the webUI And user "user1" should not have created any shares Examples: | shared-resource | @@ -642,6 +642,7 @@ Feature: Sharing files and folders with internal users | expireDate | +4 | And user "user1" has logged in using the webUI When the user tries to edit the collaborator expiry date of "User Two" of resource "" to "+7" days using the webUI + Then the expiration date input field of collaborators form should have value with "+4" days on the webUI Then it should not be possible to save the pending share on the webUI Examples: | shared-resource | @@ -675,7 +676,7 @@ Feature: Sharing files and folders with internal users And the setting "shareapi_expire_after_n_days_group_share" of app "core" has been set to "5" And user "user3" has logged in using the webUI When the user tries to share file "" with user "User Two" which expires in "+6" days using the webUI - Then enforced maximum expiration date for user share should be set in the expiration date input field of collaborators form on the webUI + Then the expiration date input field of collaborators form should have value with "+5" days on the webUI Examples: | shared-resource | | lorem.txt | diff --git a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js index c38c80734b9..6a96a76a476 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js +++ b/tests/acceptance/pageObjects/FilesPageElement/expirationDatePicker.js @@ -105,7 +105,7 @@ module.exports = { const monthSelector = this.setExpiryDateMonthSelectorXpath( pastDate.toLocaleString('en-GB', { month: 'long' }) ) - const daySelector = this.setExpiryDateDaySelectorXpath(pastDate.getDay()) + const daySelector = this.setExpiryDateDaySelectorXpath(pastDate.getDate()) await this .waitForElementVisible('@dateTimePopupYear') .waitForAnimationToFinish() @@ -147,21 +147,24 @@ module.exports = { * sets expiration date on collaborators/public-link shares * * @param {string} value - provided date in format YYYY-MM-DD, or empty string to unset date + * @param {string} shareType link|collaborator * @returns {Promise} returns true if succeeds to set provided expiration date */ - setExpirationDate: async function (value) { + setExpirationDate: async function (value, shareType = 'collaborator') { if (value === '') { return this.click('@publicLinkDeleteExpirationDateButton') } value = sharingHelper.calculateDate(value) const dateToSet = new Date(Date.parse(value)) - const disabled = await this.isExpiryDateDisabled(dateToSet) - if (disabled) { - console.log('WARNING: Cannot change expiration date to disabled value!') - await this - .waitForElementVisible('@dateTimeCancelButton') - .click('@dateTimeCancelButton') - return false + if (shareType === 'collaborator') { + const disabled = await this.isExpiryDateDisabled(dateToSet) + if (disabled) { + console.log('WARNING: Cannot change expiration date to disabled value!') + await this + .waitForElementVisible('@dateTimeCancelButton') + .click('@dateTimeCancelButton') + return false + } } const year = dateToSet.getFullYear() const month = dateToSet.toLocaleString('en-GB', { month: 'long' }) diff --git a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js index bfee3d2d7ef..9fb43ae2ce2 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/publicLinksDialog.js @@ -71,7 +71,7 @@ module.exports = { * @param value values for the different fields to be set * @returns {*|Promise|exports} */ - setPublicLinkForm: async function (key, value) { + setPublicLinkForm: function (key, value) { if (key === 'role') { return this.setPublicLinkRole(value) } else if (key === 'name') { @@ -79,17 +79,12 @@ module.exports = { } else if (key === 'password') { return this.setPublicLinkPassword(value) } else if (key === 'expireDate') { - const expectToSucceed = await this.api.page + return this.api.page .FilesPageElement .sharingDialog() .openExpiryDateCalender() - .setExpirationDate(value) - if (!expectToSucceed) { - console.log('WARNING: Cannot create share with disabled expiration date!') - return - } + .setExpirationDate(value, 'link') } - return this }, /** * sets up public link share edit form diff --git a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js index fdd20712552..066af833ea8 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js +++ b/tests/acceptance/pageObjects/FilesPageElement/sharingDialog.js @@ -510,7 +510,6 @@ module.exports = { await this .waitForElementVisible('@expirationDateField') .getValue('@expirationDateField', (result) => { - console.log(result) expirationDate = result.value }) return expirationDate @@ -520,7 +519,6 @@ module.exports = { await this .waitForElementVisible('@saveShareButton') .getAttribute('@saveShareButton', 'disabled', (result) => { - console.log(result) disabled = result.value }) return disabled diff --git a/tests/acceptance/stepDefinitions/sharingContext.js b/tests/acceptance/stepDefinitions/sharingContext.js index 8169c3a638e..7c702fb0a24 100644 --- a/tests/acceptance/stepDefinitions/sharingContext.js +++ b/tests/acceptance/stepDefinitions/sharingContext.js @@ -1031,56 +1031,19 @@ Then('user {string} should have received a share with target {string} and expira return checkReceivedSharesExpirationDate(user, target, days) }) -const assertExpirationInputValueWithEnforcedDays = async function (enforcedDays) { - const expectedDateTime = new Date() - enforcedDays = parseInt(enforcedDays.ocs.data.stdOut) - expectedDateTime.setDate(expectedDateTime.getDate() + parseInt(enforcedDays)) - const expectedDate = new Date(Date.UTC( - expectedDateTime.getFullYear(), - expectedDateTime.getMonth(), - expectedDateTime.getDate() - )) - const actualExpirationDate = await client.page.FilesPageElement - .sharingDialog() - .getExpirationDateFromInputField() - const [month, day, year] = actualExpirationDate.split(' ') - const monthNames = [ - 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' - ] - const actualDate = new Date(Date.UTC( - parseInt(year), - monthNames.indexOf(month), - parseInt(day) - )) - const actualDays = Math.floor((actualDate - expectedDate) / (86400000)) - assert.strictEqual( - enforcedDays, - actualDays - ) -} - -Then('enforced maximum expiration date for group share should be set in the expiration date input field of collaborators form on the webUI', - async function () { - const enforcedDays = await runOcc( - [ - 'config:app:get', - 'core', - 'shareapi_expire_after_n_days_group_share' - ] - ) - return assertExpirationInputValueWithEnforcedDays(enforcedDays) - }) - -Then('enforced maximum expiration date for user share should be set in the expiration date input field of collaborators form on the webUI', - async function () { - const enforcedDays = await runOcc( - [ - 'config:app:get', - 'core', - 'shareapi_expire_after_n_days_user_share' - ] +Then('the expiration date input field of collaborators form should have value with {string} days on the webUI', + async function (expectedDays) { + let expectedDate = sharingHelper.calculateDate(expectedDays) + expectedDate = new Date((Date.parse(expectedDate))) + const expectedDateString = expectedDate.toLocaleString('en-GB', { month: 'short' }) + ' ' + + (expectedDate.getDate()).toString() + ', ' + expectedDate.getFullYear() + const dateStringFromInputField = await client.page.FilesPageElement + .sharingDialog() + .getExpirationDateFromInputField() + assert.strictEqual( + expectedDateString, + dateStringFromInputField ) - return assertExpirationInputValueWithEnforcedDays(enforcedDays) }) Then('it should not be possible to save the pending share on the webUI', async function () {