Skip to content

Commit

Permalink
Added e2e tests for full text search
Browse files Browse the repository at this point in the history
  • Loading branch information
grgprarup committed Jun 21, 2023
1 parent 0e46fd9 commit 4076c00
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
89 changes: 89 additions & 0 deletions tests/e2e/cucumber/features/smoke/fullTextSearch.ocis.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Feature: Search
As a user
I want to do full text search
So that I can find the files with the content I am looking for

Background:
Given "Admin" creates following users using API
| id |
| Alice |
| Brian |
And "Admin" sets the default folder for received shares to "Shares"
And "Admin" disables share auto accepting
And "Admin" assigns following roles to the users using API
| id | role |
| Brian | Space Admin |
And "Alice" logs in
And "Alice" creates the following folder in personal space using API
| name |
| folderToShare |
And "Alice" uploads the following local file into personal space using API
| localFile | to |
| filesForUpload/textfile.txt | folderToShare/fileToShare.txt |
And "Alice" shares the following resource using API
| resource | recipient | type | role |
| folderToShare | Brian | user | Can edit |
And "Brian" logs in
And "Brian" accepts the following share using API
| name |
| folderToShare |
And "Brian" creates the following folder in personal space using API
| name |
| testFolder |
And "Brian" uploads the following local file into personal space using API
| localFile | to |
| filesForUpload/textfile.txt | textfile.txt |
| filesForUpload/textfile.txt | fileWithTag.txt |
| filesForUpload/textfile.txt | withTag.txt |
| filesForUpload/textfile.txt | testFolder/innerTextfile.txt |
And "Brian" creates the following project spaces using API
| name | id |
| FullTextSearch | fulltextsearch.1 |
And "Brian" creates the following folder in space "FullTextSearch" using API
| name |
| spaceFolder |
And "Brian" creates the following file in space "FullTextSearch" using API
| name | content |
| spaceFolder/spaceTextfile.txt | This is test file. |

And "Brian" opens the "files" app
And "Brian" adds the following tags for the following resources using the sidebar panel
| resource | tags |
| fileWithTag.txt | tag 1 |
| withTag.txt | tag 1 |


Scenario: Search for content of file
When "Brian" searches "" using the global search bar
Then "Brian" should see the message "Search for files" on the webUI

When "Brian" selects tag "tag 1" from the search result filter chip
Then following resources should be displayed in the files list for user "Brian"
| resource |
| fileWithTag.txt |
| withTag.txt |

When "Brian" searches "file" using the global search bar
Then following resources should be displayed in the files list for user "Brian"
| resource |
| fileWithTag.txt |

When "Brian" clears tag filter
Then following resources should be displayed in the files list for user "Brian"
| resource |
| textfile.txt |
| fileWithTag.txt |
| testFolder/innerTextfile.txt |
| fileToShare.txt |
| spaceFolder/spaceTextfile.txt |

When "Brian" enables the option to search in file content
And "Brian" searches "Cheers" using the global search bar
Then following resources should be displayed in the files list for user "Brian"
| resource |
| textfile.txt |
| testFolder/innerTextfile.txt |
| fileToShare.txt |
| fileWithTag.txt |
| withTag.txt |
And "Brian" logs out
47 changes: 47 additions & 0 deletions tests/e2e/cucumber/steps/ui/search.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { When, Then } from '@cucumber/cucumber'
import { World } from '../../environment'
import { objects } from '../../../support'
import { expect } from '@playwright/test'

When(
'{string} searches {string} using the global search bar',
async function (this: World, stepUser: string, keyword: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const searchObject = new objects.applicationFiles.Search({ page })
await searchObject.fullTextSearch({ keyword })
}
)

Then(
'{string} should see the message {string} on the webUI',
async function (this: World, stepUser: string, message: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const searchObject = new objects.applicationFiles.Search({ page })
const actualMessage = await searchObject.getSearchResultMessage()
expect(actualMessage).toBe(message)
}
)

When(
'{string} selects tag {string} from the search result filter chip',
async function (this: World, stepUser: string, tag: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const searchObject = new objects.applicationFiles.Search({ page })
await searchObject.selectTagFilter({ tag })
}
)

When('{string} clears tag filter', async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const searchObject = new objects.applicationFiles.Search({ page })
await searchObject.clearTagFilter()
})

When(
/^"([^"]*)" (enable|disable)s the option to search in file content?$/,
async function (this: World, stepUser: string, enableOrDisable: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const searchObject = new objects.applicationFiles.Search({ page })
await searchObject.toggleSearchInFileContent({ enableOrDisable })
}
)
1 change: 1 addition & 0 deletions tests/e2e/support/objects/app-files/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export { Resource } from './resource'
export { Share } from './share'
export { Spaces } from './spaces'
export { Trashbin } from './trashbin'
export { Search } from './search'
43 changes: 43 additions & 0 deletions tests/e2e/support/objects/app-files/search/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Page } from 'playwright'
import util from 'util'

const globalSearchInputSelector = '.oc-search-input'
const searchResultMessageSelector = '//p[@class="oc-text-muted"]'
const selectTagDropdownSelector = '.files-search-filter-tags'
const tagFilterChipSelector = '//button[contains(@data-test-value,"%s")]'
const clearTagFilterSelector =
'//div[contains(@class,"files-search-filter-tags")]//button[contains(@class,"oc-filter-chip-clear")]'
const enableSearchInFileContentSelector =
'//div[contains(@class,"files-search-filter-full-text")]//button[contains(@class,"oc-filter-chip-button")]'
const disableSearchInFileContentSelector =
'//div[contains(@class,"files-search-filter-full-text")]//button[contains(@class,"oc-filter-chip-clear")]'

export interface fullTextSearchArgs {
keyword: string
page: Page
}

export const fullTextSearch = async (args: fullTextSearchArgs): Promise<void> => {
const { page, keyword } = args
await page.locator(globalSearchInputSelector).fill(keyword)
await page.keyboard.press('Enter')
}

export const getSearchResultMessage = async ({ page }): Promise<string> => {
return await page.locator(searchResultMessageSelector).innerText()
}

export const selectTagFilter = async ({ tag, page }): Promise<void> => {
await page.locator(selectTagDropdownSelector).click()
await page.locator(util.format(tagFilterChipSelector, tag)).click()
}

export const clearTagFilter = async ({ page }): Promise<void> => {
await page.locator(clearTagFilterSelector).click()
}

export const toggleSearchInFileContent = async ({ enableOrDisable, page }): Promise<void> => {
enableOrDisable === 'enable'
? await page.locator(enableSearchInFileContentSelector).click()
: await page.locator(disableSearchInFileContentSelector).click()
}
30 changes: 30 additions & 0 deletions tests/e2e/support/objects/app-files/search/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Page } from 'playwright'
import * as po from '../search/actions'

export class Search {
#page: Page

constructor({ page }: { page: Page }) {
this.#page = page
}

async fullTextSearch(args: Omit<po.fullTextSearchArgs, 'page'>): Promise<void> {
await po.fullTextSearch({ ...args, page: this.#page })
}

async getSearchResultMessage(): Promise<string> {
return await po.getSearchResultMessage({ page: this.#page })
}

async selectTagFilter({ tag: string }): Promise<void> {
await po.selectTagFilter({ tag: string, page: this.#page })
}

async clearTagFilter(): Promise<void> {
await po.clearTagFilter({ page: this.#page })
}

async toggleSearchInFileContent({ enableOrDisable: string }): Promise<void> {
await po.toggleSearchInFileContent({ enableOrDisable: string, page: this.#page })
}
}

0 comments on commit 4076c00

Please sign in to comment.