From b5d75e99e0263aacfbbbf845022c3ebc86a029c5 Mon Sep 17 00:00:00 2001 From: Swikriti Tripathi <41103328+SwikritiT@users.noreply.github.com> Date: Mon, 15 May 2023 14:48:39 +0545 Subject: [PATCH] [tests-only]Add tests for pagination in personal space (#9008) * Add tests for pagination presonal space * set skeleton to emply for tests * remove the reduntant config * add logout step * address reviews * address reviews --- dev/docker/oc10.entrypoint.sh | 1 + tests/drone/setup-server-and-app.sh | 3 +- .../smoke/personalSpacePagination.feature | 24 +++++++++ .../smoke/spaces/project.ocis.feature | 2 +- tests/e2e/cucumber/steps/api.ts | 24 +++++++++ tests/e2e/cucumber/steps/ui/resources.ts | 49 ++++++++++++++++++- .../objects/app-files/resource/actions.ts | 44 +++++++++++++++++ .../objects/app-files/resource/index.ts | 29 ++++++++++- 8 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 tests/e2e/cucumber/features/smoke/personalSpacePagination.feature diff --git a/dev/docker/oc10.entrypoint.sh b/dev/docker/oc10.entrypoint.sh index f2a10c49681..d5ea69fa5a9 100755 --- a/dev/docker/oc10.entrypoint.sh +++ b/dev/docker/oc10.entrypoint.sh @@ -45,6 +45,7 @@ then true occ config:system:set trusted_domains 0 --value="localhost" occ config:system:set cors.allowed-domains 0 --value="http://localhost:9100" + occ config:system:set skeletondirectory --value='' fi if [ -d /var/www/owncloud/apps/web/ ] diff --git a/tests/drone/setup-server-and-app.sh b/tests/drone/setup-server-and-app.sh index 63a52690ad0..34216d462ca 100755 --- a/tests/drone/setup-server-and-app.sh +++ b/tests/drone/setup-server-and-app.sh @@ -22,12 +22,11 @@ else then php occ config:system:set web.baseUrl --value="http://owncloud/index.php/apps/web" php occ config:system:set enable_previews --type=boolean --value=false + php occ config:system:set skeletondirectory --value='' else php occ config:system:set web.baseUrl --value="http://web" php occ config:system:set cors.allowed-domains 0 --value=http://web fi php occ config:system:set sharing.federation.allowHttpFallback --value=true --type=bool php occ config:system:set web.rewriteLinks --value=true - # Remove when https://github.com/owncloud/core/pull/40024 is merged and released - php occ config:system:set cors.allowed-headers --type json --value '["cache-control"]' fi diff --git a/tests/e2e/cucumber/features/smoke/personalSpacePagination.feature b/tests/e2e/cucumber/features/smoke/personalSpacePagination.feature new file mode 100644 index 00000000000..0d3293913af --- /dev/null +++ b/tests/e2e/cucumber/features/smoke/personalSpacePagination.feature @@ -0,0 +1,24 @@ +Feature: check files pagination in personal space + As a user + I want to navigate a large number of files using pagination + So that I do not have to scroll deep down + + Scenario: pagination + Given "Admin" creates following user using API + | id | + | Alice | + And "Alice" creates 55 folders in personal space using API + And "Alice" creates 55 files in personal space using API + And "Alice" creates the following files into personal space using API + | pathToFile | content | + | .hidden-testFile.txt | This is a hidden file. | + And "Alice" logs in + And "Alice" opens the "files" app + When "Alice" navigates to page "2" of the personal space files view + Then "Alice" should see the text "111 items with 1 kB in total (56 files, 55 folders)" at the footer of the page + And "Alice" should see 10 resources in the personal space files view + When "Alice" enables the option to display the hidden file + Then "Alice" should see 11 resources in the personal space files view + When "Alice" changes the items per page to "500" + Then "Alice" should not see the pagination in the personal space files view + And "Alice" logs out diff --git a/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature b/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature index 0766703923c..b5209d1c774 100644 --- a/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature +++ b/tests/e2e/cucumber/features/smoke/spaces/project.ocis.feature @@ -107,7 +107,7 @@ Feature: spaces.personal And "Alice" uploads the following resource | resource | to | option | | PARENT/simple.pdf | folder_to_shared | replace | - When "Brian" should not see the version of the file + And "Brian" should not see the version of the file | resource | to | | simple.pdf | folder_to_shared | When "Alice" deletes the following resources using the sidebar panel diff --git a/tests/e2e/cucumber/steps/api.ts b/tests/e2e/cucumber/steps/api.ts index a3ed5a2eaec..a8799c7e242 100644 --- a/tests/e2e/cucumber/steps/api.ts +++ b/tests/e2e/cucumber/steps/api.ts @@ -102,6 +102,16 @@ Given( } ) +Given( + '{string} creates {int} folder(s) in personal space using API', + async function (this: World, stepUser: string, numberOfFolders: number): Promise { + const user = this.usersEnvironment.getUser({ key: stepUser }) + for (let i = 1; i <= numberOfFolders; i++) { + await api.dav.createFolderInsidePersonalSpace({ user, folder: `testFolder${i}` }) + } + } +) + Given( '{string} shares the following resource using API', async function (this: World, stepUser: string, stepTable: DataTable): Promise { @@ -146,6 +156,20 @@ Given( } ) +Given( + '{string} creates {int} file(s) in personal space using API', + async function (this: World, stepUser: string, numberOfFiles: number): Promise { + const user = this.usersEnvironment.getUser({ key: stepUser }) + for (let i = 1; i <= numberOfFiles; i++) { + await api.dav.uploadFileInPersonalSpace({ + user, + pathToFile: `testfile${i}.txt`, + content: `This is a test file${i}` + }) + } + } +) + Given( '{string} uploads the following local file(s) into personal space using API', async function (this: World, stepUser: string, stepTable: DataTable): Promise { diff --git a/tests/e2e/cucumber/steps/ui/resources.ts b/tests/e2e/cucumber/steps/ui/resources.ts index ae3aede5868..cac45390ffe 100644 --- a/tests/e2e/cucumber/steps/ui/resources.ts +++ b/tests/e2e/cucumber/steps/ui/resources.ts @@ -520,7 +520,7 @@ When( } ) -When( +Then( '{string} should not see the version of the file(s)', async function (this: World, stepUser: string, stepTable: DataTable): Promise { const { page } = this.actorsEnvironment.getActor({ key: stepUser }) @@ -542,3 +542,50 @@ When( } } ) + +When( + '{string} navigates to page {string} of the personal space files view', + async function (this: World, stepUser: string, pageNumber: string) { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + await resourceObject.changePagePersonalSpace({ pageNumber }) + } +) + +When( + '{string} changes the items per page to {string}', + async function (this: World, stepUser: string, itemsPerPage: string): Promise { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + await resourceObject.changeItemsPerPage({ itemsPerPage }) + } +) + +Then( + '{string} should see the text {string} at the footer of the page', + async function (this: World, stepUser: string, expectedText: string) { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + const actualText = await resourceObject.getFileListFooterText() + await expect(actualText).toBe(expectedText) + } +) + +Then( + '{string} should see {int} resources in the personal space files view', + async function (this: World, stepUser: string, expectedNumberOfResources: number) { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + const actualNumberOfResources = await resourceObject.getNumberOfResourcesInThePage() + await expect(actualNumberOfResources).toBe(expectedNumberOfResources) + } +) + +Then( + '{string} should not see the pagination in the personal space files view', + async function (this: World, stepUser: string) { + const { page } = this.actorsEnvironment.getActor({ key: stepUser }) + const resourceObject = new objects.applicationFiles.Resource({ page }) + await resourceObject.expectPageNumberNotToBeVisible() + } +) diff --git a/tests/e2e/support/objects/app-files/resource/actions.ts b/tests/e2e/support/objects/app-files/resource/actions.ts index 84ca0b48b51..152405d944f 100644 --- a/tests/e2e/support/objects/app-files/resource/actions.ts +++ b/tests/e2e/support/objects/app-files/resource/actions.ts @@ -69,6 +69,14 @@ const tagFormInput = '#tags-form input' const compareDialogConfirmBtn = '.compare-save-dialog-confirm-btn' const resourcesAsTiles = '#files-view .oc-tiles' const fileVersionSidebar = '#oc-file-versions-sidebar' +const listItemPageSelector = '//*[contains(@class,"oc-pagination-list-item-page") and text()="%s"]' +const itemsPerPageDropDownOptionSelector = + '//li[contains(@class,"vs__dropdown-option") and text()="%s"]' +const footerTextSelector = '//*[@data-testid="files-list-footer-info"]' +const filesTableResourcesDetailsSelector = + '//td[contains(@class,"oc-table-data-cell-name")]//div//div[contains(@class,"oc-resource-details")]' +const itemsPerPageDropDownSelector = '.vs__actions' +const filesPaginationNavSelector = '.files-pagination' export const clickResource = async ({ page, @@ -934,6 +942,8 @@ export const expectThatResourcesAreTiles = async (args): Promise => { export const showHiddenResources = async (page): Promise => { await page.locator(filesViewOptionButton).click() await page.locator(hiddenFilesToggleButton).click() + // close the files view option + await page.locator(filesViewOptionButton).click() } export interface editResourcesArgs { @@ -1058,3 +1068,37 @@ export const checkThatFileVersionIsNotAvailable = async ( await sidebar.openPanel({ page, name: 'versions' }) await expect(page.locator(fileVersionSidebar)).toHaveText('No Versions available for this file') } + +export interface changePageArgs { + page: Page + pageNumber: string +} +export const changePagePersonalSpace = async (args: changePageArgs): Promise => { + const { page, pageNumber } = args + await page.locator(util.format(listItemPageSelector, pageNumber)).click() +} + +export interface changeItemsPerPageArgs { + page: Page + itemsPerPage: string +} +export const changeItemsPerPage = async (args: changeItemsPerPageArgs): Promise => { + const { page, itemsPerPage } = args + await page.locator(filesViewOptionButton).click() + await page.locator(itemsPerPageDropDownSelector).click() + await page.locator(util.format(itemsPerPageDropDownOptionSelector, itemsPerPage)).click() + // close the files view option + await page.locator(filesViewOptionButton).click() +} + +export const getFileListFooterText = ({ page }): Promise => { + return page.locator(footerTextSelector).textContent() +} + +export const getNumberOfResourcesInThePage = ({ page }): Promise => { + return page.locator(filesTableResourcesDetailsSelector).count() +} + +export const expectPageNumberNotToBeVisible = async ({ page }): Promise => { + await expect(page.locator(filesPaginationNavSelector)).not.toBeVisible() +} diff --git a/tests/e2e/support/objects/app-files/resource/index.ts b/tests/e2e/support/objects/app-files/resource/index.ts index ff3d8e20e19..cdf685a0e98 100644 --- a/tests/e2e/support/objects/app-files/resource/index.ts +++ b/tests/e2e/support/objects/app-files/resource/index.ts @@ -48,7 +48,14 @@ import { createSpaceFromFolderArgs, createSpaceFromSelection, createSpaceFromSelectionArgs, - checkThatFileVersionIsNotAvailable + checkThatFileVersionIsNotAvailable, + changePageArgs, + changePagePersonalSpace, + getFileListFooterText, + getNumberOfResourcesInThePage, + changeItemsPerPage, + changeItemsPerPageArgs, + expectPageNumberNotToBeVisible } from './actions' import { Space } from '../../../types' @@ -245,4 +252,24 @@ export class Resource { await checkThatFileVersionIsNotAvailable({ ...args, page: this.#page }) await this.#page.goto(startUrl) } + + async changePagePersonalSpace(args: Omit): Promise { + await changePagePersonalSpace({ ...args, page: this.#page }) + } + + async changeItemsPerPage(args: Omit): Promise { + await changeItemsPerPage({ ...args, page: this.#page }) + } + + getFileListFooterText(): Promise { + return getFileListFooterText({ page: this.#page }) + } + + getNumberOfResourcesInThePage(): Promise { + return getNumberOfResourcesInThePage({ page: this.#page }) + } + + async expectPageNumberNotToBeVisible(): Promise { + await expectPageNumberNotToBeVisible({ page: this.#page }) + } }