Skip to content

Commit

Permalink
Merge pull request #2372 from kiranparajuli589/test-public-links
Browse files Browse the repository at this point in the history
Add acceptance test for public link sharing
  • Loading branch information
skshetry authored Nov 21, 2019
2 parents 587aa6e + 37e4bd2 commit 6ce4651
Show file tree
Hide file tree
Showing 8 changed files with 823 additions and 217 deletions.
16 changes: 12 additions & 4 deletions apps/files/src/components/FileLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
<a :href="link.url" :uk-tooltip="$_tooltipTextLink" class="uk-text-small uk-link">{{ link.token }}</a> <span class="uk-text-meta">| {{ link.description }}<template v-if="link.expiration"> | <span v-translate>Expires</span> {{ formDateFromNow(link.expiration) }}</template></span>
</div>
<div class="uk-width-auto uk-button-group">
<button class="uk-button uk-button-default uk-position-relative" @click.stop="$_copyToClipboard(link, $event)">
<button class="uk-button uk-button-default uk-position-relative" :aria-label="$_copyButtonLabel" @click.stop="$_copyToClipboard(link, $event)">
<oc-icon name="copy_to_clipboard" class="uk-position-center" />
</button>
<oc-button :disabled="!!(formOpen || linkId)" icon="edit" @click="$_editLink(link)"/>
<oc-button :disabled="!!(formOpen || linkId)" icon="delete" @click="$_removeLink(link)" />
<oc-button :disabled="!!(formOpen || linkId)" :aria-label="$_editButtonLabel" icon="edit" @click="$_editLink(link)"/>
<oc-button :disabled="!!(formOpen || linkId)" :aria-label="$_deleteButtonLabel" icon="delete" @click="$_removeLink(link)" />
</div>
</oc-grid>
<FileLinkForm v-if="linkId === link.id" class="uk-margin-top" :params="params" :context="'edit'" :linkId="linkId"/>
Expand Down Expand Up @@ -107,9 +107,17 @@ export default {
enforced: expireDate.enforced === '1'
}
},
$_tooltipTextLink () {
return `title: ${this.$gettext('Click to open the link')}; pos: bottom`
},
$_deleteButtonLabel () {
return this.$gettext('Delete public link')
},
$_editButtonLabel () {
return this.$gettext('Edit public link')
},
$_copyButtonLabel () {
return this.$gettext('Copy link url')
}
},
methods: {
Expand Down
252 changes: 131 additions & 121 deletions tests/acceptance/features/webUISharingPublic/shareByPublicLink.feature

Large diffs are not rendered by default.

120 changes: 79 additions & 41 deletions tests/acceptance/helpers/sharingHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,73 +67,84 @@ module.exports = {
return fetch(apiURL, { method: 'GET', headers: headers })
.then(res => res.json())
.then(function (sharesResult) {
if (sharesResult.ocs.meta.statuscode === 200) {
const shares = sharesResult.ocs.data
let found
for (var shareI = 0; shareI < shares.length; shareI++) {
const share = shares[shareI]
found = true
for (var expectedDetailsI = 0; expectedDetailsI < expectedDetailsTable.hashes().length; expectedDetailsI++) {
const expectedDetail = expectedDetailsTable.hashes()[expectedDetailsI]
if (expectedDetail.field === 'permissions') {
expectedDetail.value = sharingHelper.humanReadablePermissionsToBitmask(expectedDetail.value).toString()
} else if (expectedDetail.field === 'share_type') {
expectedDetail.value = sharingHelper.humanReadableShareTypeToNumber(expectedDetail.value).toString()
}
if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) {
found = false
break
}
httpHelper.checkOCSStatus(sharesResult, 'Could not get shares. Message: ' + sharesResult.ocs.meta.message)
const shares = sharesResult.ocs.data
let found
for (const share of shares) {
found = true
for (const expectedDetail of expectedDetailsTable.hashes()) {
if (expectedDetail.field === 'permissions') {
expectedDetail.value = sharingHelper.humanReadablePermissionsToBitmask(expectedDetail.value).toString()
} else if (expectedDetail.field === 'share_type') {
expectedDetail.value = sharingHelper.humanReadableShareTypeToNumber(expectedDetail.value).toString()
}
if (found === true) {
if (!(expectedDetail.field in share) || share[expectedDetail.field].toString() !== expectedDetail.value) {
found = false
break
}
}
assert.strictEqual(
found, true, 'could not find expected share in "' + JSON.stringify(sharesResult, null, 2) + '"'
)
return this
} else {
throw Error('Could not get shares. Message: ' + sharesResult.ocs.meta.message)
if (found) {
break
}
}
assert.strictEqual(
found, true, 'could not find expected share in "' + JSON.stringify(sharesResult, null, 2) + '"'
)
return this
})
},

/**
* Asynchronously fetches the last public link created by the given link creator
*
* @async
* @param {string[]} linkCreator link creator
* @param {string} linkCreator link creator
* @return {Promise<Object>} last share token
*/
fetchLastPublicLinkShare: async function (linkCreator) {
const self = this
const headers = httpHelper.createAuthHeader(linkCreator)
const apiURL = client.globals.backend_url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?format=json'
let lastShareToken
let lastShare
await fetch(apiURL, { method: 'GET', headers: headers })
.then(res => res.json())
.then(function (sharesResult) {
if (sharesResult.ocs.meta.statuscode === 200) {
const shares = sharesResult.ocs.data
let lastFoundShareId = 0
for (var shareI = 0; shareI < shares.length; shareI++) {
const share = shares[shareI]
if (share.share_type === self.SHARE_TYPES.public_link && share.id >= lastFoundShareId) {
lastFoundShareId = share.id
lastShare = share
}
httpHelper.checkOCSStatus(sharesResult, 'Could not get shares. Message: ' + sharesResult.ocs.meta.message)
const shares = sharesResult.ocs.data
let lastFoundShareId = 0
for (const share of shares) {
if (share.share_type === self.SHARE_TYPES.public_link && share.id >= lastFoundShareId) {
lastFoundShareId = share.id
lastShareToken = share.token
lastShare = share
}
if (lastShare === null) {
throw Error('Could not find public shares. All shares: ' + JSON.stringify(shares, null, 2))
}
} else {
throw Error('Could not get shares. Message: ' + sharesResult.ocs.meta.message)
}
if (lastShareToken === null) {
throw Error('Could not find public shares. All shares: ' + JSON.stringify(shares, null, 2))
}
})

return lastShare
},
/**
* get a list of all public link shares shared by provided sharer
*
* @param sharer user whose all public links are to be fetched
* @returns {Object<[]>}
*/
getAllPublicLinkShares: async function (sharer) {
const headers = httpHelper.createAuthHeader(sharer)
const data = []
const apiURL = client.globals.backend_url + '/ocs/v2.php/apps/files_sharing/api/v1/shares?&format=json'
const response = await fetch(apiURL, { method: 'GET', headers: headers })
const jsonResponse = await response.json()
httpHelper.checkOCSStatus(jsonResponse, 'Could not get shares. Message: ' + jsonResponse.ocs.meta.message)
for (const share of jsonResponse.ocs.data) {
if (share.share_type === this.SHARE_TYPES.public_link) {
data.push(share)
}
}
return data
},
/**
*
* @param {string} user
Expand Down Expand Up @@ -185,5 +196,32 @@ module.exports = {
})
}
}
},
/**
* asserts expectedDetails with the last public link share of a user
*
* @param {string} linkCreator - owner of public link share
* @param {Object} expectedDetails - provided expected details of last public link share for assertion
* @param {string} expectedDetails.token - token of the public link share
* @param {string} expectedDetails.expireDate - expire date for public link share in format 'YYYY-MM-DD'
* @returns {Promise<void>}
*/
assertUserLastPublicShareDetails: async function (linkCreator, expectedDetails) {
const lastShare = await this.fetchLastPublicLinkShare(linkCreator)
if (lastShare.share_type === this.SHARE_TYPES.public_link) {
const regDate = lastShare.expiration.split(' ')[0]
if (expectedDetails.token) {
assert.strictEqual(
lastShare.token, expectedDetails.token, 'Token Missmatch' + lastShare
)
}
if (expectedDetails.expireDate) {
assert.strictEqual(
regDate, expectedDetails.expireDate, 'Expiry Date Missmatch: ' + lastShare
)
}
} else {
throw new Error('Invalid Share Type' + lastShare)
}
}
}
5 changes: 2 additions & 3 deletions tests/acceptance/pageObjects/FilesPageElement/filesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ module.exports = {
*
* @param {string} fileName
*/
openPublicLinkDialog: function (fileName) {
this.waitForFileVisible(fileName)
openPublicLinkDialog: async function (fileName) {
await this.waitForFileVisible(fileName)
.useXpath()
.performFileAction(fileName, 'share')
.waitForElementVisible('@linkToPublicLinksTag')
Expand Down Expand Up @@ -514,7 +514,6 @@ module.exports = {
})
})
},

copyPrivateLink: function () {
return this
.waitForElementVisible('@sidebar')
Expand Down
Loading

0 comments on commit 6ce4651

Please sign in to comment.