From 24bd2b922c1f0a2b1a3a6f3bcc805a87ff910eba Mon Sep 17 00:00:00 2001 From: jasson99 Date: Fri, 29 Nov 2019 11:13:55 +0545 Subject: [PATCH] Add acceptance test to filter files and folders using keyword --- .../features/webUIFiles/filter.feature | 72 +++++++++++++++++++ .../acceptance/helpers/filesFoldersHelper.js | 53 ++++++++++++++ tests/acceptance/helpers/path.js | 17 ++++- .../pageObjects/FilesPageElement/filesList.js | 16 +++++ tests/acceptance/pageObjects/filesPage.js | 24 +++++++ .../stepDefinitions/filesContext.js | 49 +++++++++++++ 6 files changed, 229 insertions(+), 2 deletions(-) create mode 100644 tests/acceptance/helpers/filesFoldersHelper.js diff --git a/tests/acceptance/features/webUIFiles/filter.feature b/tests/acceptance/features/webUIFiles/filter.feature index f1a2215ed99..bb6b839ea94 100644 --- a/tests/acceptance/features/webUIFiles/filter.feature +++ b/tests/acceptance/features/webUIFiles/filter.feature @@ -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 diff --git a/tests/acceptance/helpers/filesFoldersHelper.js b/tests/acceptance/helpers/filesFoldersHelper.js new file mode 100644 index 00000000000..ab2a1ba6934 --- /dev/null +++ b/tests/acceptance/helpers/filesFoldersHelper.js @@ -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('.')) +} diff --git a/tests/acceptance/helpers/path.js b/tests/acceptance/helpers/path.js index f2ec6099e5b..0781c02d723 100644 --- a/tests/acceptance/helpers/path.js +++ b/tests/acceptance/helpers/path.js @@ -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) } diff --git a/tests/acceptance/pageObjects/FilesPageElement/filesList.js b/tests/acceptance/pageObjects/FilesPageElement/filesList.js index c5c210860db..3259d395a22 100644 --- a/tests/acceptance/pageObjects/FilesPageElement/filesList.js +++ b/tests/acceptance/pageObjects/FilesPageElement/filesList.js @@ -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') @@ -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' diff --git a/tests/acceptance/pageObjects/filesPage.js b/tests/acceptance/pageObjects/filesPage.js index a2b21e3c98b..bf9c5ee65f1 100644 --- a/tests/acceptance/pageObjects/filesPage.js +++ b/tests/acceptance/pageObjects/filesPage.js @@ -184,6 +184,7 @@ module.exports = { .click('@filterListButton') .waitForElementVisible('@hiddenFilesLabel') .click('@hiddenFilesCheckbox') + .click('@filterListButton') }, /** * @@ -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: { @@ -483,6 +504,9 @@ module.exports = { tabsInSideBar: { selector: '//div[@class="sidebar-container"]//li/a', locateStrategy: 'xpath' + }, + filterTextField: { + selector: '#oc-filter-search .oc-search-input' } } } diff --git a/tests/acceptance/stepDefinitions/filesContext.js b/tests/acceptance/stepDefinitions/filesContext.js index 92f39ff70e0..eba3f10e602 100644 --- a/tests/acceptance/stepDefinitions/filesContext.js +++ b/tests/acceptance/stepDefinitions/filesContext.js @@ -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 = [] @@ -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) }) @@ -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) +})