Skip to content

Commit

Permalink
Add e2e tests for searching in personal
Browse files Browse the repository at this point in the history
  • Loading branch information
SwikritiT committed Sep 7, 2022
1 parent 51ea786 commit 380d78a
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 2 deletions.
76 changes: 76 additions & 0 deletions tests/e2e/cucumber/features/integrations/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
Feature: link
As a user
I want to search for resources
So that I can find them quickly


Scenario: Search in personal spaces
Given "Admin" creates following users
| id |
| Alice |
When "Alice" logs in
And "Alice" opens the "files" app
And "Alice" creates the following resources
| resource | type |
| folder | folder |
| new-folder | folder |
| FolDer | folder |
| folderPublic | folder |
| public | folder |
When "Alice" searches "fol" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| folder |
| new-folder |
| FolDer |
| folderPublic |
# Uncomment the following step after this issue is fixed https://github.com/owncloud/ocis/issues/4517
# But following resource should not be listed in the search list for user "Alice"
# | resource |
# | public |
When "Alice" creates the following resources
| resource | type |
| PARENT/child | folder |
| PARENT/child-one | folder |
| PARENT/child-two | folder |
| PARENT/test-folder | folder |
And "Alice" opens folder "PARENT"
And "Alice" searches "child" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| child |
| child-one |
| child-two |
But following resources should not be displayed in the search list for user "Alice"
| resource |
| test-folder |
And "Alice" opens the "files" app
And "Alice" searches "foldeR" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| folder |
| new-folder |
| FolDer |
| folderPublic |
And "Alice" opens the "files" app
When "Alice" uploads the following resources
| resource |
| new-lorem.txt |
| new-lorem-big.txt |
| new-data.zip |
And "Alice" searches "new" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| new-lorem.txt |
| new-lorem-big.txt |
| new-data.zip |
| new-folder |
And "Alice" opens the "files" app
When "Alice" enables the option to display the hidden file
When "Alice" uploads the following resources
| resource |
| .hidden-file.txt |
And "Alice" searches "hidden" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| .hidden-file.txt |
45 changes: 45 additions & 0 deletions tests/e2e/cucumber/steps/app-files/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,51 @@ Then(
}
}
)
When(
'{string} searches {string} using the global search',
async function (this: World, stepUser: string, keyword: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
await resourceObject.searchResource({ keyword })
}
)

Then(
/^following resources (should|should not) be displayed in the search list for user "([^"]*)"?$/,
async function (
this: World,
actionType: string,
stepUser: string,
stepTable: DataTable
): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
const actualList = await resourceObject.getDisplayedResources()
for (const info of stepTable.hashes()) {
const found = actualList.includes(info.resource)
if (actionType === 'should') expect(found).toBe(true)
else expect(found).toBe(false)
}
}
)

When(
'{string} opens folder {string}',
async function (this: World, stepUser: string, resource: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
await resourceObject.openFolder(resource)
}
)

When(
'{string} enables the option to display the hidden file',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
await resourceObject.showHiddenFiles()
}
)

export const processDownload = async (
stepTable: DataTable,
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/filesForUpload/.hidden-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a hidden file
30 changes: 29 additions & 1 deletion tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const emptyTrashBinButton = '.oc-files-actions-empty-trash-bin-trigger'
const notificationMessageDialog = '.oc-notification-message-title'
const permanentDeleteButton = '.oc-files-actions-delete-permanent-trigger'
const restoreResourceButton = '.oc-files-actions-restore-trigger'
const globalSearchInput = '.oc-search-input'
const searchList =
'//div[@id="files-global-search-options"]//li[contains(@class,"preview")]//span[@class="oc-resource-name"]'
const filesViewOptionButton = '#files-view-options-btn'
const hiddenFilesToggleButton = '//*[@data-testid="files-switch-hidden-files"]//button'

export const clickResource = async ({
page,
Expand Down Expand Up @@ -375,7 +380,7 @@ export interface deleteResourceTrashbinArgs {
page: Page
}

export const deleteResourceTrashbin = async (args: deleteResourceTrashbinArgs): Promise<string> => {
export const deleteResourceTrashbin = async (args: deleteResourceArgs): Promise<string> => {
const { page, resource } = args
const resourceCheckbox = page.locator(util.format(checkBoxForTrashbin, resource))
if (!(await resourceCheckbox.isChecked())) {
Expand Down Expand Up @@ -418,3 +423,26 @@ export const restoreResourceTrashbin = async (
const message = await page.locator(notificationMessageDialog).textContent()
return message.trim().toLowerCase()
}

export interface searchResourceGlobalSearchArgs {
keyword: string
page: Page
}

export const searchResourceGlobalSearch = async (
args: searchResourceGlobalSearchArgs
): Promise<void> => {
const { page, keyword } = args
await page.locator(globalSearchInput).fill(keyword)
}

export const getDisplayedResourcesFromSearch = async (page): Promise<string[]> => {
const result = await page.locator(searchList).allInnerTexts()
// the result has values like `test\n.txt` so remove new line
return result.map((result) => result.replace('\n', ''))
}

export const showHiddenResources = async (page): Promise<void> => {
await page.locator(filesViewOptionButton).click()
await page.locator(hiddenFilesToggleButton).click()
}
23 changes: 22 additions & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ import {
uploadResource,
uploadResourceArgs,
restoreResourceTrashbinArgs,
restoreResourceTrashbin
restoreResourceTrashbin,
searchResourceGlobalSearch,
searchResourceGlobalSearchArgs,
getDisplayedResourcesFromSearch,
clickResource,
showHiddenResources
} from './actions'

export class Resource {
Expand Down Expand Up @@ -113,4 +118,20 @@ export class Resource {
await this.#page.goto(startUrl)
return message
}

async searchResource(args: Omit<searchResourceGlobalSearchArgs, 'page'>): Promise<void> {
await searchResourceGlobalSearch({ ...args, page: this.#page })
}

getDisplayedResources(): Promise<string[]> {
return getDisplayedResourcesFromSearch(this.#page)
}

async openFolder(resource): Promise<void> {
await clickResource({ page: this.#page, path: resource })
}

async showHiddenFiles(): Promise<void> {
await showHiddenResources(this.#page)
}
}

0 comments on commit 380d78a

Please sign in to comment.