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] E2e test public link #6889

Merged
merged 2 commits into from
May 17, 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
18 changes: 16 additions & 2 deletions tests/e2e/cucumber/features/integrations/link.feature
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,27 @@ Feature: link
| textfile.txt |
#Then the public should see the following files on the files-drop page
# | textfile.txt |
#When the public reloads the public link pages
#Then the public should not see the following files on the files-drop page
# | textfile.txt |
And "Anonymous" logs out
When "Alice" downloads the following resources using the batch action
| resource | from |
| lorem.txt | folderPublic |
| textfile.txt | folderPublic |
And "Alice" edits the public link named "myPublicLink" of resource "folderPublic" changing role to "editor"
And "Anonymous" refreshes the old link
And "Anonymous" downloads the following public link resources using the sidebar panel
| resource |
| lorem.txt |
| textfile.txt |
And "Anonymous" uploads the following resources in public link page
| resource |
| new-lorem.txt |
And "Anonymous" renames the following public link resources
| resource | as |
| lorem.txt | lorem_new.txt |
| textfile.txt | textfile_new.txt |
| new-lorem.txt | test.txt |
And "Alice" removes the public link named "myPublicLink" of resource "folderPublic"
And "Anonymous" should not be able to open the old link "myPublicLink"
And "Anonymous" logs out
And "Alice" logs out
9 changes: 9 additions & 0 deletions tests/e2e/cucumber/steps/app-files/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,12 @@ When(
expect(role).toBe(actualRole.toLowerCase())
}
)

When(
'{string} removes the public link named {string} of resource {string}',
async function (this: World, stepUser: string, name: string, resource: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.delete({ resourceName: resource, name })
}
)
64 changes: 62 additions & 2 deletions tests/e2e/cucumber/steps/app-files/page/public.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { DataTable, When } from '@cucumber/cucumber'
import { DataTable, Then, When } from '@cucumber/cucumber'
import { expect } from '@playwright/test'
import { kebabCase } from 'lodash'
import { DateTime } from 'luxon'
import { World } from '../../../environment'
import { objects } from '../../../../support'
import { processDownload } from '../resource'
import { linkStore } from '../../../../support/store'

When(
'{string} opens the public link {string}',
Expand Down Expand Up @@ -63,6 +66,63 @@ When(
const resources = stepTable
.hashes()
.map((f) => this.filesEnvironment.getFile({ name: f.resource }))
await pageObject.upload({ resources })
await pageObject.dropUpload({ resources })
}
)

When(
'{string} refreshes the old link',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
await pageObject.reload()
}
)

Then(
/^"([^"]*)" downloads the following public link resource(s)? using the (sidebar panel|batch action)$/,
async function (
this: World,
stepUser: string,
_: string,
actionType: string,
stepTable: DataTable
): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
await processDownload(stepTable, pageObject, actionType)
}
)

When(
'{string} renames the following public link resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
for (const { resource, as } of stepTable.hashes()) {
await pageObject.rename({ resource, newName: as })
}
}
)

When(
'{string} uploads the following resource(s) in public link page',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
for (const info of stepTable.hashes()) {
await pageObject.upload({
to: info.to,
resources: [this.filesEnvironment.getFile({ name: info.resource })],
createVersion: info.create_version === 'true'
})
}
}
)

Then(
'{string} should not be able to open the old link {string}',
function (this: World, stepUser: string, name: string): void {
expect(linkStore.has(name)).toBe(false)
}
)
110 changes: 58 additions & 52 deletions tests/e2e/cucumber/steps/app-files/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ When(
const resourceObject = new objects.applicationFiles.Resource({ page })
for (const info of stepTable.hashes()) {
await resourceObject.upload({
to: info.to,
to: info.to !== 'undefined' ? info.to : null,
resources: [this.filesEnvironment.getFile({ name: info.resource })],
createVersion: info.create_version === 'true'
})
Expand All @@ -46,56 +46,7 @@ When(
) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
let downloads
let files, parentFolder
const downloadInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { resource, from } = stepRow

if (!acc[from]) {
acc[from] = []
}

acc[from].push(resource)

return acc
}, {})

for (const folder of Object.keys(downloadInfo)) {
files = downloadInfo[folder]
parentFolder = folder
downloads = await resourceObject.download({
folder,
names: files,
via: actionType === 'batch action' ? 'BATCH_ACTION' : 'SIDEBAR_PANEL'
})
if (actionType === 'sidebar panel') {
expect(files.length).toBe(downloads.length)
downloads.forEach((download) => {
expect(files).toContain(download.suggestedFilename())
})
}
}
if (actionType === 'batch action') {
if (files.length === 1) {
expect(files.length).toBe(downloads.length)
downloads.forEach((download) => {
expect(files[0]).toBe(download.suggestedFilename())
})
} else {
expect(downloads.length).toBe(1)
downloads.forEach((download) => {
if (config.ocis) {
expect(download.suggestedFilename()).toBe('download.tar')
} else {
if (parentFolder) {
expect(download.suggestedFilename()).toBe(parentFolder + '.zip')
} else {
expect(download.suggestedFilename()).toBe('download.zip')
}
}
})
}
}
await processDownload(stepTable, resourceObject, actionType)
}
)

Expand All @@ -104,7 +55,6 @@ When(
async function (this: World, stepUser: string, stepTable: DataTable) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const { resource, as } of stepTable.hashes()) {
await resourceObject.rename({ resource, newName: as })
}
Expand Down Expand Up @@ -193,3 +143,59 @@ When(
}
}
)

export const processDownload = async (
stepTable: DataTable,
pageObject: any,
actionType: string
) => {
let downloads, files, parentFolder
const downloadInfo = stepTable.hashes().reduce((acc, stepRow) => {
const { resource, from } = stepRow

if (!acc[from]) {
acc[from] = []
}

acc[from].push(resource)

return acc
}, {})

for (const folder of Object.keys(downloadInfo)) {
files = downloadInfo[folder]
parentFolder = folder !== 'undefined' ? folder : null
downloads = await pageObject.download({
folder: parentFolder,
names: files,
via: actionType === 'batch action' ? 'BATCH_ACTION' : 'SIDEBAR_PANEL'
})
if (actionType === 'sidebar panel') {
expect(files.length).toBe(downloads.length)
downloads.forEach((download) => {
expect(files).toContain(download.suggestedFilename())
})
}
}
if (actionType === 'batch action') {
if (files.length === 1) {
expect(files.length).toBe(downloads.length)
downloads.forEach((download) => {
expect(files[0]).toBe(download.suggestedFilename())
})
} else {
expect(downloads.length).toBe(1)
downloads.forEach((download) => {
if (config.ocis) {
expect(download.suggestedFilename()).toBe('download.tar')
} else {
if (parentFolder) {
expect(download.suggestedFilename()).toBe(parentFolder + '.zip')
} else {
expect(download.suggestedFilename()).toBe('download.zip')
}
}
})
}
}
}
7 changes: 7 additions & 0 deletions tests/e2e/support/environment/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,11 @@ export class LinksEnvironment {

return link
}

deleteLink({ key }: { key: string }): boolean {
if (linkStore.has(key)) {
return linkStore.delete(key)
}
throw new Error(`link with key '${key}' doesn't exist`)
}
}
29 changes: 26 additions & 3 deletions tests/e2e/support/objects/app-files/link/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export type changeRoleArgs = {
role: string
}

export type deleteLinkArgs = {
page: Page
resourceName: string
name: string
}

const publicLinkSetNameInputField = '#oc-files-file-link-name'
const publicLinkSelectRolesButton = '#files-file-link-role-button'
const publicLinkSetRoleButton = `#files-role-%s`
Expand All @@ -36,7 +42,14 @@ const savePublicLinkButton = '#oc-files-file-link-create'
const publicLink = `//ul/li/div/h4[contains(text(),'%s')]/following-sibling::div//p`
const publicLinkCurrentRole =
'//button[contains(@class,"edit-public-link-role-dropdown-toggl")]//span[contains(@class,"oc-invisible-sr")]'
const linkUpdateSuccessfulDialog = '//div[contains(@class,"oc-notification-message-title")]'
const linkUpdateDialog = '//div[contains(@class,"oc-notification-message-title")]'
const editPublicLinkButton =
`//h4[contains(@class, "oc-files-file-link-name") and text()="%s"]` +
`//ancestor::li//div[contains(@class, "details-buttons")]//button[contains(@class, "edit-drop-trigger")]`
const deleteLinkButton =
`//h4[contains(@class, "oc-files-file-link-name") and text()="%s"]` +
`//ancestor::li//div[contains(@class, "details-buttons")]//button[text()="Delete link"]`
const confirmDeleteButton = `//button[contains(@class,"oc-modal-body-actions-confirm") and text()="Delete"]`

const fillPublicLink = async (page, name, role, dateOfExpiration, password): Promise<void> => {
if (name) {
Expand All @@ -61,7 +74,6 @@ const fillPublicLink = async (page, name, role, dateOfExpiration, password): Pro
{ newExpiryDate }
)
}

if (password) {
await page.locator(publicLinkSetPasswordInputField).fill(password)
}
Expand Down Expand Up @@ -102,7 +114,18 @@ export const changeRole = async (args: changeRoleArgs): Promise<string> => {
await sidebar.openPanel({ page: page, name: 'sharing' })
await page.locator(util.format(publicLinkEditRoleButton, name)).click()
await page.locator(util.format(publicLinkSetRoleButton, role.toLowerCase())).click()
const message = await page.locator(linkUpdateSuccessfulDialog).textContent()
const message = await page.locator(linkUpdateDialog).textContent()
expect(message.trim()).toBe('Link was updated successfully')
return await page.locator(publicLinkCurrentRole).textContent()
}

export const deleteLink = async (args: deleteLinkArgs): Promise<void> => {
const { page, resourceName, name } = args
await sidebar.open({ page: page, resource: resourceName })
await sidebar.openPanel({ page: page, name: 'sharing' })
await page.locator(util.format(editPublicLinkButton, name)).click()
await page.locator(util.format(deleteLinkButton, name)).click()
await page.locator(confirmDeleteButton).click()
const message = await page.locator(linkUpdateDialog).textContent()
expect(message.trim()).toBe('Link was deleted successfully')
}
18 changes: 17 additions & 1 deletion tests/e2e/support/objects/app-files/link/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { Page } from 'playwright'
import { createLink, createLinkArgs, changeRole, changeRoleArgs } from './actions'
import {
createLink,
createLinkArgs,
changeRole,
changeRoleArgs,
deleteLinkArgs,
deleteLink
} from './actions'
import { LinksEnvironment } from '../../../environment'

export class Link {
Expand Down Expand Up @@ -29,4 +36,13 @@ export class Link {
await this.#page.goto(startUrl)
return role
}

async delete(args: Omit<deleteLinkArgs, 'page'>): Promise<void> {
const startUrl = this.#page.url()
await deleteLink({ ...args, page: this.#page })
this.#linksEnvironment.deleteLink({
key: args.name
})
await this.#page.goto(startUrl)
}
}
Loading