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

[tests-only] Add e2e tests for searching #7583

Merged
merged 1 commit into from
Sep 12, 2022
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
93 changes: 93 additions & 0 deletions tests/e2e/cucumber/features/integrations/search.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Feature: Search
As a user
I want to search for resources
So that I can find them quickly

Background:
Given "Admin" sets the default folder for received shares to "Shares"
And "Admin" disables share auto accepting

Scenario: Search in personal spaces
Given "Admin" creates following users
| id |
| Alice |
| Brian |
When "Brian" logs in
And "Brian" opens the "files" app
And "Brian" creates the following resources
| resource | type |
| folder_from_brian | folder |
And "Brian" uploads the following resources
| resource |
| new-lorem-big.txt |
And "Brian" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_from_brian | Alice | user | viewer |
| new-lorem-big.txt | Alice | user | viewer |
And "Brian" logs out
When "Alice" logs in
And "Alice" navigates to the shared with me page
And "Alice" accepts the following share
| name |
| folder_from_brian |
| new-lorem-big.txt |
And "Alice" opens the "files" app
And "Alice" creates the following resources
| resource | type |
| folder | folder |
| FolDer | folder |
| PARENT/child | folder |
| PARENT/child-one | folder |
| PARENT/child-one/child-two | folder |
And "Alice" enables the option to display the hidden file
And "Alice" uploads the following resources
| resource |
| new-lorem.txt |
| .hidden-file.txt |
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 |
# enable these steps after issue https://github.com/owncloud/web/issues/7629 is fixed
# | new-lorem-big.txt |
But following resources should not be displayed in the search list for user "Alice"
| resource |
| PARENT |
| folder_from_brian |
| .hidden-file.txt |
When "Alice" searches "foldeR" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| folder |
| FolDer |
# enable these steps after issue https://github.com/owncloud/web/issues/7629 is fixed
# | folder_from_brian |
But following resources should not be displayed in the search list for user "Alice"
| resource |
| new-lorem.txt |
| new-lorem-big.txt |
| .hidden-file.txt |
When "Alice" searches "hidden" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| .hidden-file.txt |
But following resources should not be displayed in the search list for user "Alice"
| resource |
| folder |
| FolDer |
| PARENT |
| folder_from_brian |
| new-lorem.txt |
| new-lorem-big.txt |
When "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 |
When "Alice" opens folder "child-one"
And "Alice" searches "child" using the global search
Then following resources should be displayed in the search list for user "Alice"
| resource |
| child-two |
And "Alice" logs out
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Feature: share

Background:
And "admin" sets the default folder for received shares to "Shares"
Given "admin" sets the default folder for received shares to "Shares"
And "Admin" disables share auto accepting

Scenario: folder
Expand Down
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
40 changes: 34 additions & 6 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Download, Page } from 'playwright'
import { expect } from '@playwright/test'
import util from 'util'
import { resourceExists, waitForResources } from './utils'
import path from 'path'
Expand Down Expand Up @@ -29,6 +30,13 @@ 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 globalSearchOptions = '#files-global-search-options'
const loadingSpinner = '#files-global-search-bar .oc-spinner'
const filesViewOptionButton = '#files-view-options-btn'
const hiddenFilesToggleButton = '//*[@data-testid="files-switch-hidden-files"]//button'

export const clickResource = async ({
page,
Expand Down Expand Up @@ -370,12 +378,7 @@ export const emptyTrashBinResources = async (page): Promise<string> => {
return message.trim().toLowerCase()
}

export interface deleteResourceTrashbinArgs {
resource: string
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 +421,28 @@ 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)
await expect(page.locator(globalSearchOptions)).toBeVisible()
await expect(page.locator(loadingSpinner)).not.toBeVisible()
}

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', ''))
ScharfViktor marked this conversation as resolved.
Show resolved Hide resolved
}

export const showHiddenResources = async (page): Promise<void> => {
await page.locator(filesViewOptionButton).click()
await page.locator(hiddenFilesToggleButton).click()
}
26 changes: 23 additions & 3 deletions tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
deleteResource,
deleteResourceArgs,
deleteResourceTrashbin,
deleteResourceTrashbinArgs,
downloadResources,
downloadResourcesArgs,
downloadResourceVersion,
Expand All @@ -20,7 +19,12 @@ import {
uploadResource,
uploadResourceArgs,
restoreResourceTrashbinArgs,
restoreResourceTrashbin
restoreResourceTrashbin,
searchResourceGlobalSearch,
searchResourceGlobalSearchArgs,
getDisplayedResourcesFromSearch,
clickResource,
showHiddenResources
} from './actions'

export class Resource {
Expand Down Expand Up @@ -100,7 +104,7 @@ export class Resource {
return await emptyTrashBinResources(this.#page)
}

async deleteTrashBin(args: Omit<deleteResourceTrashbinArgs, 'page'>): Promise<string> {
async deleteTrashBin(args: Omit<deleteResourceArgs, 'page'>): Promise<string> {
const startUrl = this.#page.url()
const message = await deleteResourceTrashbin({ ...args, page: this.#page })
await this.#page.goto(startUrl)
Expand All @@ -113,4 +117,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)
}
}