-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add acceptance test to filter files and folders using keyword
- Loading branch information
Showing
6 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('.')) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters