Skip to content

Commit

Permalink
fix e2e test page selectors
Browse files Browse the repository at this point in the history
skip explicit DOM date selection for public links
add nav name data property for sidebar nav records
  • Loading branch information
fschade committed Mar 1, 2022
1 parent 7ab7e3b commit 44ac9c5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 113 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:class="['oc-sidebar-nav-item-link', { active: active }]"
:to="target"
:data-nav-id="index"
:data-nav-name="navName"
>
<oc-icon :name="icon" :fill-type="fillType" />
<span class="oc-ml-m text" :class="{ 'text-invisible': collapsed }" v-text="name" />
Expand All @@ -17,6 +18,7 @@
</template>
<script>
import SidebarNavItemHighlight from './SidebarNavItemHighlight.vue'
import get from 'lodash-es/get'
export default {
components: {
Expand Down Expand Up @@ -57,6 +59,9 @@ export default {
}
},
computed: {
navName() {
return get(this.$router?.resolve(this.target), 'route.name')
},
toolTip() {
const value = this.collapsed
? this.$gettextInterpolate(this.$gettext('Navigate to %{ pageName } page'), {
Expand All @@ -69,6 +74,9 @@ export default {
arrow: false
}
}
},
mounted() {
window.foo = this
}
}
</script>
Expand Down
22 changes: 14 additions & 8 deletions tests/e2e/support/page/files/allFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ export class AllFilesPage {
async navigate(): Promise<void> {
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<void> {
Expand Down Expand Up @@ -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)
}
Expand Down
130 changes: 28 additions & 102 deletions tests/e2e/support/page/files/publicLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<void> {
await this.roleDropdownLocator.click()
await this.actor.page.locator(util.format(this.roleSelector, role)).click()
}

async selectExpiryMonth(year: string, month: string): Promise<void> {
await this.actor.page.locator(util.format(this.monthSelector, year, month)).click()
}

async selectExpiryDay(dayMonthYear: string): Promise<void> {
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<void> {
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<number> {
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<void> {
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,
Expand All @@ -170,7 +70,6 @@ export class PublicLink {
password: string
via: 'SIDEBAR_PANEL' | 'QUICK_ACTION'
}): Promise<void> {
this.dateType = this.getDateType(dateOfExpiration)
const { page } = this.actor
const resourcePaths = resource.split('/')
const resourceName = resourcePaths.pop()
Expand All @@ -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()
}
}
4 changes: 1 addition & 3 deletions tests/e2e/support/page/files/sharedWithMe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ export class SharedWithMePage {

async navigate(): Promise<void> {
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<void> {
Expand Down

0 comments on commit 44ac9c5

Please sign in to comment.