From 44ac9c5a8dbe147bb894c4dea38a5286bf3dcc1d Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Tue, 1 Mar 2022 06:13:34 +0100 Subject: [PATCH] fix e2e test page selectors skip explicit DOM date selection for public links add nav name data property for sidebar nav records --- .../components/SidebarNav/SidebarNavItem.vue | 8 ++ tests/e2e/support/page/files/allFiles.ts | 22 +-- tests/e2e/support/page/files/publicLink.ts | 130 ++++-------------- tests/e2e/support/page/files/sharedWithMe.ts | 4 +- 4 files changed, 51 insertions(+), 113 deletions(-) diff --git a/packages/web-runtime/src/components/SidebarNav/SidebarNavItem.vue b/packages/web-runtime/src/components/SidebarNav/SidebarNavItem.vue index eef0d330253..7b413f3dacc 100644 --- a/packages/web-runtime/src/components/SidebarNav/SidebarNavItem.vue +++ b/packages/web-runtime/src/components/SidebarNav/SidebarNavItem.vue @@ -8,6 +8,7 @@ :class="['oc-sidebar-nav-item-link', { active: active }]" :to="target" :data-nav-id="index" + :data-nav-name="navName" > @@ -17,6 +18,7 @@ diff --git a/tests/e2e/support/page/files/allFiles.ts b/tests/e2e/support/page/files/allFiles.ts index d2d2b2ae54a..e66f4eea6ec 100644 --- a/tests/e2e/support/page/files/allFiles.ts +++ b/tests/e2e/support/page/files/allFiles.ts @@ -13,10 +13,7 @@ export class AllFilesPage { async navigate(): Promise { const { page } = this.actor - const allFilesBtn = page.locator( - '//li[contains(@class, "oc-sidebar-nav-item")]//span[text()="All files"]' - ) - await allFilesBtn.click() + await page.locator('//a[@data-nav-name="files-spaces-personal-home"]').click() } async createFolder({ name }: { name: string }): Promise { @@ -318,10 +315,19 @@ export class AllFilesPage { for (const user of users) { const userColumn = `//*[@data-testid="collaborator-user-item-${user.id}"]` - await page.click(`${userColumn}//button[contains(@class,"files-recipient-role-select-btn")]`) - await page.click( - `${userColumn}//ul[contains(@class,"files-recipient-role-drop-list")]//button[@id="files-recipient-role-drop-btn-${role}"]` - ) + + await Promise.all([ + page.click(`${userColumn}//button[contains(@class,"files-recipient-role-select-btn")]`), + page.click( + `${userColumn}//ul[contains(@class,"files-recipient-role-drop-list")]//button[@id="files-recipient-role-drop-btn-${role}"]` + ), + page.waitForResponse( + (resp) => + resp.url().includes('shares') && + resp.status() === 200 && + resp.request().method() === 'PUT' + ) + ]) } await page.goto(startUrl) } diff --git a/tests/e2e/support/page/files/publicLink.ts b/tests/e2e/support/page/files/publicLink.ts index b3ae1564d03..193c466115e 100644 --- a/tests/e2e/support/page/files/publicLink.ts +++ b/tests/e2e/support/page/files/publicLink.ts @@ -22,7 +22,6 @@ export class PublicLink { private readonly publicLinkListSelector: string private readonly roleSelector: string private readonly folderSelector: string - private dateType: string constructor({ actor }: { actor: Actor }) { this.actor = actor @@ -51,110 +50,11 @@ export class PublicLink { this.folderSelector = `//*[@data-test-resource-name="%s"]/ancestor::tr//button[contains(@class, "files-quick-action-collaborators")]` } - async selectRole(role: string): Promise { - await this.roleDropdownLocator.click() - await this.actor.page.locator(util.format(this.roleSelector, role)).click() - } - - async selectExpiryMonth(year: string, month: string): Promise { - await this.actor.page.locator(util.format(this.monthSelector, year, month)).click() - } - - async selectExpiryDay(dayMonthYear: string): Promise { - await this.actor.page.locator(util.format(this.daySelector, dayMonthYear)).click() - } - - getDateType = (expiryDate: string): string => { - if (expiryDate.charAt(0).includes('-')) { - throw new Error('The provided date is negative and has already expired !!') - } else if (expiryDate.charAt(0).includes('+')) { - return expiryDate.toLowerCase().match(/[dayrmonthwek]+/)[0] - } - } - - async selectDate(dateOfExpiration: string): Promise { - const newExpiryDate = getActualExpiryDate(this.dateType, dateOfExpiration) - const expiryDay = newExpiryDate.getDate() - const expiryMonth = ('0' + (newExpiryDate.getMonth() + 1)).slice(-2) - const expiryYear = newExpiryDate.getFullYear().toString() - await this.expirationDateDropdownLocator.click() - const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] - const months = [ - 'January', - 'February', - 'March', - 'April', - 'May', - 'June', - 'July', - 'August', - 'September', - 'October', - 'November', - 'December' - ] - const dayMonthYear = - days[newExpiryDate.getDay()] + - ', ' + - months[newExpiryDate.getMonth()] + - ' ' + - expiryDay + - ', ' + - expiryYear - await this.monthAndYearDropdownLocator.click() - if ((await this.yearButtonLocator.innerText()) !== expiryYear) { - await this.yearButtonLocator.click() - while (true) { - const nextYearSpanValue = await this.yearButtonLocator.innerText() - const splitNextSpanYear = nextYearSpanValue.split('-') - if ( - newExpiryDate.getFullYear() >= parseInt(splitNextSpanYear[0]) && - newExpiryDate.getFullYear() <= parseInt(splitNextSpanYear[1]) - ) { - const yearLocator = await this.actor.page.locator( - util.format(this.yearSelector, expiryYear) - ) - await yearLocator.click() - break - } - await this.nextSpanYearLocator.click() - } - } - - await this.selectExpiryMonth(expiryYear, expiryMonth) - await this.selectExpiryDay(dayMonthYear) - } - async getLinksCount(): Promise { await this.actor.page.waitForSelector(this.publicLinkListSelector) return await this.actor.page.locator(this.publicLinkListSelector).count() } - async fillThePublicLinkForm({ - name, - password, - role, - dateOfExpiration - }: { - name: string - password: string - role: string - dateOfExpiration: string - }): Promise { - if (name) { - await this.publicLinkNameLocator.fill(name) - } - if (role) { - await this.selectRole(role) - } - if (dateOfExpiration) { - await this.selectDate(dateOfExpiration) - } - if (password) { - await this.publicLinkPasswordLocator.fill(password) - } - } - async createPublicLinkForResource({ resource, name, @@ -170,7 +70,6 @@ export class PublicLink { password: string via: 'SIDEBAR_PANEL' | 'QUICK_ACTION' }): Promise { - this.dateType = this.getDateType(dateOfExpiration) const { page } = this.actor const resourcePaths = resource.split('/') const resourceName = resourcePaths.pop() @@ -189,7 +88,34 @@ export class PublicLink { break } await this.publicLinkButtonLocator.click() - await this.fillThePublicLinkForm({ name, password, role, dateOfExpiration }) + + if (name) { + await this.publicLinkNameLocator.fill(name) + } + + if (role) { + await this.roleDropdownLocator.click() + await this.actor.page.locator(util.format(this.roleSelector, role)).click() + } + + if (dateOfExpiration) { + const newExpiryDate = getActualExpiryDate( + dateOfExpiration.toLowerCase().match(/[dayrmonthwek]+/)[0], + dateOfExpiration + ) + + await page.locator('#oc-files-file-link-expire-date').evaluate( + (datePicker: any, { newExpiryDate }): any => { + datePicker.__vue__.updateValue(newExpiryDate) + }, + { newExpiryDate } + ) + } + + if (password) { + await this.publicLinkPasswordLocator.fill(password) + } + await this.createLinkButtonLocator.click() } } diff --git a/tests/e2e/support/page/files/sharedWithMe.ts b/tests/e2e/support/page/files/sharedWithMe.ts index 9264d6c160a..78ba623c12c 100644 --- a/tests/e2e/support/page/files/sharedWithMe.ts +++ b/tests/e2e/support/page/files/sharedWithMe.ts @@ -11,9 +11,7 @@ export class SharedWithMePage { async navigate(): Promise { const { page } = this.actor - await page - .locator('//li[contains(@class, "oc-sidebar-nav-item")]//span[text()="Shared with me"]') - .click() + await page.locator('//a[@data-nav-name="files-shares-with-me"]').click() } async acceptShare({ name }: { name: string }): Promise {