Skip to content

Commit

Permalink
Merge pull request #3016 from swoichha/trashBinRestoreForFilesAndFolder
Browse files Browse the repository at this point in the history
[Tests-Only] Restore files and folder from trashbin with same name
  • Loading branch information
individual-it authored Feb 19, 2020
2 parents 7547172 + 2400e36 commit d8c1d4f
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 44 deletions.
36 changes: 36 additions & 0 deletions tests/acceptance/features/webUITrashbin/trashbinRestore.feature
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,39 @@ Feature: Restore deleted files/folders
And as "user1" file "simple-folder-renamed/file-to-delete-and-restore" should not exist
#And as "user1" file "simple-folder-renamed/file-to-delete-and-restore" should exist
And as "user1" file "simple-folder/file-to-delete-and-restore" should not exist

@issue-1723
Scenario: Delete and restore a file that has the same name like a deleted folder
Given the following files have been deleted by user "user1"
| name |
| lorem.txt |
And the user has created folder "lorem.txt"
And the following folders have been deleted by user "user1"
| name |
| lorem.txt |
When the user browses to the trashbin page
And the user restores file "lorem.txt" from the trashbin using the webUI
Then the success message "lorem.txt was restored successfully" should be displayed on the webUI
And file "lorem.txt" should not be listed on the webUI
And folder "lorem.txt" should be listed on the webUI
When the user browses to the files page using the webUI
Then file "lorem.txt" should be listed on the webUI
And folder "lorem.txt" should not be listed on the webUI

Scenario: Delete and restore a folder that has the same name like a deleted file
Given the user has created file "lorem.txt"
And the following files have been deleted by user "user1"
| name |
| lorem.txt |
And the user has created folder "lorem.txt"
And the following folders have been deleted by user "user1"
| name |
| lorem.txt |
When the user browses to the trashbin page
And the user restores folder "lorem.txt" from the trashbin using the webUI
Then the success message "lorem.txt was restored successfully" should be displayed on the webUI
And folder "lorem.txt" should not be listed on the webUI
And file "lorem.txt" should be listed on the webUI
When the user browses to the files page using the webUI
Then folder "lorem.txt" should be listed on the webUI
And file "lorem.txt" should not be listed on the webUI
91 changes: 53 additions & 38 deletions tests/acceptance/pageObjects/FilesPageElement/filesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ module.exports = {
* @param fileName
* @returns {string}
*/
getFileActionBtnSelector: function (fileName) {
return this.getFileRowSelectorByFileName(fileName) +
getFileActionBtnSelector: function (fileName, elementType = 'file') {
return this.getFileRowSelectorByFileName(fileName, elementType) +
this.elements.fileActionsButtonInFileRow.selector
},
/**
Expand All @@ -48,10 +48,9 @@ module.exports = {
* @param {string} action delete|share|rename|download
* @returns {*}
*/
performFileAction: function (fileName, action) {
performFileAction: function (fileName, action, elementType = 'file') {
const { btnSelector, fileActionsBtnSelector } =
this.getFileRowButtonSelectorsByFileName(fileName, action)

this.getFileRowButtonSelectorsByFileName(fileName, action, elementType)
return this.initAjaxCounters()
.useXpath()
.waitForElementVisible(fileActionsBtnSelector)
Expand All @@ -60,7 +59,6 @@ module.exports = {
.click(btnSelector)
.useCss()
},

/**
* Checks whether a given action is disabled for a given file name.
* This method does find out itself if the file-action burger has to be clicked or not.
Expand Down Expand Up @@ -159,12 +157,15 @@ module.exports = {
/**
*
* @param {string} fileName
* @param {string} elementType
* @returns {Promise<void>}
*/
restoreFile: function (fileName) {
return this.initAjaxCounters()
.waitForFileWithPathVisible(fileName)
restoreFile: async function (fileName, elementType = 'file') {
await this
.initAjaxCounters()
.waitForFileWithPathVisible(fileName, elementType)
.useXpath()
.performFileAction(fileName, FileAction.restore)
.performFileAction(fileName, FileAction.restore, elementType)
.waitForOutstandingAjaxCalls()
.useCss()
},
Expand Down Expand Up @@ -386,9 +387,10 @@ module.exports = {
* Wait for A filerow with given filename to be visible
*
* @param {string} fileName
* @param {string} elementType
*/
waitForFileVisible: async function (fileName) {
const linkSelector = this.getFileLinkSelectorByFileName(fileName)
waitForFileVisible: async function (fileName, elementType = 'file') {
const linkSelector = this.getFileLinkSelectorByFileName(fileName, elementType)

await this.waitForElementPresent('@filesTableContainer')
await this.filesListScrollToTop()
Expand All @@ -401,7 +403,6 @@ module.exports = {
this.assert.strictEqual(result.value, fileName, 'displayed file name not as expected')
})
.useCss()

return this
},
/**
Expand All @@ -410,10 +411,11 @@ module.exports = {
* This does not works in cases where the path starts with a space (eg. " ParentFolder/file.txt")
*
* @param {string} path
* @param {string} elementType
*/
waitForFileWithPathVisible: function (path) {
const rowSelector = this.getFileRowSelectorByFileName(path)
const linkSelector = this.getFileLinkSelectorByFileName(path)
waitForFileWithPathVisible: function (path, elementType = 'file') {
const linkSelector = this.getFileLinkSelectorByFileName(path, elementType)
const rowSelector = this.getFileRowSelectorByFileName(path, elementType)
return this
.useXpath()
.waitForElementVisible(rowSelector)
Expand All @@ -422,60 +424,73 @@ module.exports = {
})
.useCss()
},
getFileRowButtonSelectorsByFileName: function (fileName, action) {
const btnSelector = this.getActionSelector(action, fileName)
const fileActionsBtnSelector = this.getFileActionBtnSelector(fileName)
/**
*
* @param {string} fileName
* @param {string} action
* @param {string} elementType
* @returns {{btnSelector: string, fileActionsBtnSelector: string}}
*/
getFileRowButtonSelectorsByFileName: function (fileName, action, elementType = 'file') {
const btnSelector = this.getActionSelector(action)
const fileActionsBtnSelector = this.getFileActionBtnSelector(fileName, elementType)

return { btnSelector, fileActionsBtnSelector }
},
/**
*
* @param {string} fileName
* @param {string} elementType
*
* @returns {string}
*/
getFileRowSelectorByFileName: function (fileName) {
const parts = path.parse(fileName)
// If our file has a extension that starts with space (for eg. "newfile. txt")
// Then the whole name comes in the filename part (i.e. The file has no extension in such case)
// Since the extension has spaces immediately after '.' we check for spaces after removing the '.' using slice().
if (parts.ext && !parts.ext.slice(1).startsWith(' ')) {
// keep path of nested folders intact, just remove the extension at the end
const filePathWithoutExt = parts.dir ? join(parts.dir, parts.name) : parts.name
const element = this.elements.fileRowByNameAndExtension
return util.format(
element.selector,
xpathHelper.buildXpathLiteral(filePathWithoutExt),
parts.ext
)
getFileRowSelectorByFileName: function (fileName, elementType = 'file') {
if (elementType === 'file') {
const parts = path.parse(fileName)
// If our file has a extension that starts with space (for eg. "newfile. txt")
// Then the whole name comes in the filename part (i.e. The file has no extension in such case)
// Since the extension has spaces immediately after '.' we check for spaces after removing the '.' using slice().
if (parts.ext && !parts.ext.slice(1).startsWith(' ')) {
// keep path of nested folders intact, just remove the extension at the end
const filePathWithoutExt = parts.dir ? join(parts.dir, parts.name) : parts.name
const element = this.elements.fileRowByNameAndExtension
return util.format(
element.selector,
xpathHelper.buildXpathLiteral(filePathWithoutExt),
parts.ext
)
}
}

const element = this.elements.fileRowByName
return util.format(element.selector, xpathHelper.buildXpathLiteral(fileName))
},
/**
*
* @param {string} fileName
* @param {string} elementType
* @returns {string}
*/
getFileLinkSelectorByFileName: function (fileName) {
return this.getFileRowSelectorByFileName(fileName) +

getFileLinkSelectorByFileName: function (fileName, elementType) {
return this.getFileRowSelectorByFileName(fileName, elementType) +
this.elements.fileLinkInFileRow.selector
},
/**
* checks whether the element is listed or not on the filesList
*
* @param {string} element Name of the file/folder/resource
* @param {string} elementType
* @returns {boolean}
*/
isElementListed: async function (element) {
isElementListed: async function (element, elementType = 'file') {
let isListed = true
await this
.waitForElementVisible('@filesTable')
.useXpath()
.waitForElementNotPresent('@loadingIndicator')
.api.elements(
'xpath',
this.getFileRowSelectorByFileName(element),
this.getFileRowSelectorByFileName(element, elementType),
(result) => {
isListed = result.value.length > 0
})
Expand Down
26 changes: 20 additions & 6 deletions tests/acceptance/stepDefinitions/filesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,18 @@ Then('there should be no files/folders/resources listed on the webUI', async fun
assert.ok(allRowsResult.value.length === 0, `No resources are listed, ${allRowsResult.length} found`)
})

Then('file/folder {string} should be listed on the webUI', function (folder) {
Then('file {string} should be listed on the webUI', function (folder) {
return client
.page
.FilesPageElement.filesList()
.waitForFileVisible(folder)
.waitForFileVisible(folder, 'file')
})

Then('folder {string} should be listed on the webUI', (folder) => {
return client
.page
.FilesPageElement.filesList()
.waitForFileVisible(folder, 'folder')
})

Then('file/folder with path {string} should be listed in the favorites page on the webUI', function (path) {
Expand All @@ -364,8 +371,15 @@ Then('the last uploaded folder should be listed on the webUI', async function ()
return client
})

Then('file/folder {string} should not be listed on the webUI', async function (folder) {
const state = await client.page.FilesPageElement.filesList().isElementListed(folder)
Then('file {string} should not be listed on the webUI', async function (folder) {
const state = await client.page.FilesPageElement.filesList().isElementListed(folder, 'file')
return client.assert.ok(
!state, `Error: Resource ${folder} is listed on the filesList`
)
})

Then('folder {string} should not be listed on the webUI', async (folder) => {
const state = await client.page.FilesPageElement.filesList().isElementListed(folder, 'folder')
return client.assert.ok(
!state, `Error: Resource ${folder} is listed on the filesList`
)
Expand Down Expand Up @@ -666,8 +680,8 @@ const assertDeletedElementsAreListed = function () {
return assertElementsAreListed(deletedElements)
}

When('the user restores file/folder {string} from the trashbin using the webUI', function (element) {
return client.page.FilesPageElement.filesList().restoreFile(element)
When(/^the user restores (file|folder) "([^"]*)" from the trashbin using the webUI$/, function (elementType, element) {
return client.page.FilesPageElement.filesList().restoreFile(element, elementType)
})

Then('the following files/folders/resources should be listed on the webUI', function (table) {
Expand Down

0 comments on commit d8c1d4f

Please sign in to comment.