Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add acceptance test to filter files and folders using keyword in the files page #2592

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions tests/acceptance/features/webUIFiles/filter.feature
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,75 @@ Feature: Filter files/folders
| desktopapp.png |
| testimagelarge.svg |

Scenario: user filters files and folders using keyword when the files filter, folders filter, and hidden filter are enabled
When the user enables file filter using the webUI
And the user enables folder filter using the webUI
And the user enables the setting to view hidden files on the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" all files and folders containing pattern "simple" in their name should be listed in files list on the webUI

Scenario: user filters files and folders using keyword when the hidden filter is disabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user enables file filter using the webUI
And the user enables folder filter using the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" all files and folders containing pattern "simple" in their name should be listed in files list on the webUI except of hidden elements

Scenario: user filters files using keyword when the hidden filter and the folder filter are disabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user enables file filter using the webUI
And the user disables folder filter using the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" only files containing pattern "simple" in their name should be listed in files list on the webUI except hidden elements

Scenario: user filters folders using keyword when the hidden filter and the file filter are disabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user disables file filter using the webUI
And the user enables folder filter using the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" only folders containing pattern "simple" in their name should be listed in files list on the webUI except hidden elements

Scenario: user filters folders using keyword when the hidden filter and the folder filter are enabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user disables file filter using the webUI
And the user enables folder filter using the webUI
And the user enables the setting to view hidden folders on the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" only folders containing pattern "simple" in their name should be listed in files list on the webUI

Scenario: user filters files using keyword when the hidden filter and the file filter are enabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user disables folder filter using the webUI
And the user enables file filter using the webUI
And the user enables the setting to view hidden folders on the webUI
And the user filters the file list by "simple" on the webUI
Then as "user1" only files containing pattern "simple" in their name should be listed in files list on the webUI

Scenario: user filters files using keyword when the folder filter and file filter are disabled and hidden filter is enabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user disables folder filter using the webUI
And the user disables file filter using the webUI
And the user enables the setting to view hidden folders on the webUI
And the user filters the file list by "simple" on the webUI
Then there should be no files/folders listed on the webUI

Scenario: user filters files using keyword when the folder filter, file filter and hidden filter are disabled
Given the user has created file ".simpleHiddenFile"
And the user has created folder ".simpleHiddenFolder"
And the user has reloaded the current page of the webUI
When the user disables folder filter using the webUI
And the user disables file filter using the webUI
And the user filters the file list by "simple" on the webUI
Then there should be no files/folders listed on the webUI
53 changes: 53 additions & 0 deletions tests/acceptance/helpers/filesFoldersHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const { client } = require('nightwatch-api')
const { propfind } = require('./webdavHelper')
const convert = require('xml-js')
const { relativeTo, normalize, join } = require('./path')

exports.getAllFilesFolders = function (user) {
const backendURL = client.globals.backend_url
const baseURL = new URL(join(backendURL, `remote.php/dav/files/${user}/`))
const basePath = baseURL.pathname
return propfind(`/files/${user}`, user, [])
.then(str => {
const data = convert.xml2js(str, { compact: true })['d:multistatus']['d:response']
const filepaths = data.map(elements =>
normalize(
elements['d:href']._text)
)
const filenames = filepaths.map(element => relativeTo(basePath, element))
// The first element in the filenames is the username which is not actually a filename.
// The first element should therefore be removed from filenames
return filenames.splice(1)
})
}

exports.getAllFolders = async function (user) {
const filenames = await exports.getAllFilesFolders(user)
const folders = filenames.filter(elements => elements.endsWith('/'))
return folders.map(folder => folder.slice(0, -1))
}

exports.getAllFiles = async function (user) {
const filenames = await exports.getAllFilesFolders(user)
return filenames.filter(elements => !elements.endsWith('/'))
}

exports.getFilesMatchingPattern = async function (user, pattern) {
const files = await exports.getAllFiles(user)
return files.filter(elements => elements.toLowerCase().includes(pattern))
}

exports.getFoldersMatchingPattern = async function (user, pattern) {
const files = await exports.getAllFolders(user)
return files.filter(elements => elements.toLowerCase().includes(pattern))
}

exports.getFilesFoldersMatchingPattern = async function (user, pattern) {
const filesMatchingPattern = await exports.getFilesMatchingPattern(user, pattern)
const foldersMatchingPattern = await exports.getFoldersMatchingPattern(user, pattern)
return foldersMatchingPattern.concat(filesMatchingPattern)
}

exports.getAllFilesStartingWithDot = function (elements) {
return elements.filter(elem => !elem.startsWith('.'))
}
17 changes: 15 additions & 2 deletions tests/acceptance/helpers/path.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
const join = require('join-path')
const _ = require('lodash/fp')
const assert = require('assert')
const normalize = _.replace(/^\/+|$/g, '')
const parts = _.pipe(normalize, _.split('/'))
const relativeTo = function (basePath, childPath) {
basePath = normalize(basePath)
childPath = normalize(childPath)
assert.ok(childPath.startsWith(basePath), `${childPath} doesnot contain ${basePath}`)
const basePathLength = basePath.length
return childPath.slice(basePathLength)
}

module.exports = {
normalize: _.replace(/^\/+|\/+$/g, ''),
normalize,
resolve: _.partial(join, ['/']),
join
join,
parts,
relativeTo,
filename: _.pipe(parts, _.remove(n => n === ''), _.last)
}
16 changes: 16 additions & 0 deletions tests/acceptance/pageObjects/FilesPageElement/filesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,19 @@ module.exports = {
})
})
},
getListedFilesFolders: function () {
this
.waitForElementNotPresent('@filesListProgressBar')
.waitForElementVisible({
selector: '@allFiles',
abortOnFailure: false
})
return new Promise((resolve, reject) => {
this.api.elements('@allFiles', function (result) {
resolve(result)
})
})
},
copyPrivateLink: function () {
return this
.waitForElementVisible('@sidebar')
Expand Down Expand Up @@ -611,6 +624,9 @@ module.exports = {
fileRows: {
selector: 'tr.file-row'
},
allFiles: {
selector: 'span.oc-file.file-row-name'
},
loadingIndicator: {
selector: '//*[contains(@class, "oc-loader")]',
locateStrategy: 'xpath'
Expand Down
24 changes: 24 additions & 0 deletions tests/acceptance/pageObjects/filesPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ module.exports = {
.click('@filterListButton')
.waitForElementVisible('@hiddenFilesLabel')
.click('@hiddenFilesCheckbox')
.click('@filterListButton')
},
/**
*
Expand Down Expand Up @@ -335,6 +336,26 @@ module.exports = {
return this
.waitForElementVisible('@restorePreviousVersion')
.click('@restorePreviousVersion')
},
filterElementsList: function (input) {
return this.initAjaxCounters()
.click('@filterListButton')
.waitForElementVisible('@filterTextField')
.clearValue('@filterTextField')
.setValue('@filterTextField', input)
.waitForOutstandingAjaxCalls()
// This click is for closing the filter list
.click('@filterListButton')
},
getAllListedResources: async function () {
const allFileRows = await this.api.page.FilesPageElement.filesList().getListedFilesFolders()
const allFilesListed = []
for (const elemId of allFileRows.value) {
await this.api.elementIdText(elemId.ELEMENT, function (result) {
allFilesListed.push(result.value)
})
}
return allFilesListed
}
},
elements: {
Expand Down Expand Up @@ -483,6 +504,9 @@ module.exports = {
tabsInSideBar: {
selector: '//div[@class="sidebar-container"]//li/a',
locateStrategy: 'xpath'
},
filterTextField: {
selector: '#oc-filter-search .oc-search-input'
}
}
}
49 changes: 49 additions & 0 deletions tests/acceptance/stepDefinitions/filesContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ let deletedElements
let timeOfLastDeleteOperation = Date.now()
let timeOfLastUploadOperation = Date.now()
const { download } = require('../helpers/webdavHelper')
const { getFilesFoldersMatchingPattern, getFoldersMatchingPattern, getFilesMatchingPattern, getAllFilesStartingWithDot } = require('../helpers/filesFoldersHelper')

const assertDesiredResourcesListed = async function (resourcesMatchingPattern, listedResources) {
const diff = _.difference(resourcesMatchingPattern, listedResources)
return assert.strictEqual(diff.length, 0, `Expected : ${resourcesMatchingPattern} but got ${listedResources}`)
}

Before(() => {
deletedElements = []
Expand Down Expand Up @@ -159,6 +165,10 @@ When('the user enables the setting to view hidden files/folders on the webUI', f
When('the user browses to folder {string} using the breadcrumb on the webUI', (resource) =>
client.page.filesPage().navigateToBreadcrumb(resource))

When('the user filters the file list by {string} on the webUI', function (input) {
return client.page.filesPage().filterElementsList(input)
})

When('the user deletes file/folder {string} using the webUI', function (element) {
return client.page.FilesPageElement.filesList().deleteFile(element)
})
Expand Down Expand Up @@ -854,3 +864,42 @@ Then('the page should be empty', async function () {
When('the user downloads file/folder {string} using the webUI', function (file) {
return client.page.FilesPageElement.filesList().downloadFile(file)
})

Then('as {string} all files and folders containing pattern {string} in their name should be listed in files list on the webUI', async function (user, pattern) {
const filesFoldersMatchingPattern = await getFilesFoldersMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
return assertDesiredResourcesListed(filesFoldersMatchingPattern, allListedFilesFolders)
})

Then('as {string} all files and folders containing pattern {string} in their name should be listed in files list on the webUI except of hidden elements', async function (user, pattern) {
const filesFoldersMatchingPattern = await getFilesFoldersMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
const nonHiddenElements = await getAllFilesStartingWithDot(filesFoldersMatchingPattern)
return assertDesiredResourcesListed(nonHiddenElements, allListedFilesFolders)
})

Then('as {string} only files containing pattern {string} in their name should be listed in files list on the webUI except hidden elements', async function (user, pattern) {
const filesMatchingPattern = await getFilesMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
const nonHiddenFiles = await getAllFilesStartingWithDot(filesMatchingPattern)
return assertDesiredResourcesListed(nonHiddenFiles, allListedFilesFolders)
})

Then('as {string} only folders containing pattern {string} in their name should be listed in files list on the webUI except hidden elements', async function (user, pattern) {
const foldersMatchingPattern = await getFoldersMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
const nonHiddenFolders = await getAllFilesStartingWithDot(foldersMatchingPattern)
return assertDesiredResourcesListed(nonHiddenFolders, allListedFilesFolders)
})

Then('as {string} only folders containing pattern {string} in their name should be listed in files list on the webUI', async function (user, pattern) {
const foldersMatchingPattern = await getFoldersMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
return assertDesiredResourcesListed(foldersMatchingPattern, allListedFilesFolders)
})

Then('as {string} only files containing pattern {string} in their name should be listed in files list on the webUI', async function (user, pattern) {
const filesMatchingPattern = await getFilesMatchingPattern(user, pattern)
const allListedFilesFolders = await client.page.filesPage().getAllListedResources()
return assertDesiredResourcesListed(filesMatchingPattern, allListedFilesFolders)
})