Skip to content

Commit

Permalink
[tests-only]Share file story (owncloud#7660)
Browse files Browse the repository at this point in the history
* edit txt file

* fix after review
  • Loading branch information
ScharfViktor authored Sep 27, 2022
1 parent 904be00 commit 93c81b7
Show file tree
Hide file tree
Showing 4 changed files with 224 additions and 36 deletions.
58 changes: 44 additions & 14 deletions tests/e2e/cucumber/features/integrations/share.ocis.feature
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
Feature: share

Background:
And "Admin" disables share auto accepting

Scenario: folder
Given "Admin" creates following users
| id |
| Alice |
| Brian |

Scenario: folder
When "Alice" logs in
And "Alice" opens the "files" app
And "Alice" navigates to the personal space page
And "Alice" creates the following resources
| resource | type |
| folder_to_shared | folder |
And "Alice" uploads the following resource
| resource | to |
| lorem.txt | folder_to_shared |
#Then "Alice" should see the following resource
# | folder_to_shared/lorem.txt |
When "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| folder_to_shared | Brian | user | editor |
Expand All @@ -35,26 +31,60 @@ Feature: share
| resource | to |
| simple.pdf | folder_to_shared |
When "Alice" opens the "files" app
#Then "Alice" should see the following resources
# | folder_to_shared/lorem_new.txt |
# | folder_to_shared/simple.pdf |
And "Alice" uploads the following resource
| resource | to | create_version |
| PARENT/simple.pdf | folder_to_shared | true |
#Then "Alice" should see that the resource "folder_to_shared/simple.pdf" has 1 version
And "Brian" downloads old version of the following resource
| resource | to |
| simple.pdf | folder_to_shared |
When "Brian" restores following resources
| resource | to | version |
| simple.pdf | folder_to_shared | 1 |
#Then "Brian" should see that the version of resource "simple.pdf" has been restored
When "Alice" deletes the following resources
| resource |
| folder_to_shared/lorem_new.txt |
| folder_to_shared |
And "Alice" logs out
And "Brian" opens the "files" app
#Then "Brian" should not see the following resource
# | Shares/folder_to_shared |
And "Brian" logs out


Scenario: file
When "Alice" logs in
And "Alice" opens the "files" app
And "Alice" creates the following resources
| resource | type | content |
| shareToBrian.txt | txtFile | some text |
| shareToBrian.md | mdFile | readme |
| shareToBrian.drawio | drawioFile | |
And "Alice" uploads the following resource
| resource |
| testavatar.jpeg |
| simple.pdf |
And "Alice" shares the following resource using the sidebar panel
| resource | recipient | type | role |
| shareToBrian.txt | Brian | user | editor |
| shareToBrian.md | Brian | user | editor |
| testavatar.jpeg | Brian | user | viewer |
| simple.pdf | Brian | user | viewer |
And "Alice" logs out

When "Brian" logs in
And "Brian" opens the "files" app
And "Brian" navigates to the shared with me page
And "Brian" accepts the following share
| name |
| shareToBrian.txt |
| shareToBrian.md |
| testavatar.jpeg |
| simple.pdf |
And "Brian" edits the following resources
| resource | content |
| shareToBrian.txt | new content |
| shareToBrian.md | new readme content |
And "Brian" opens the following file in mediaviewer
| resource |
| testavatar.jpeg |
And "Brian" opens the following file in pdfviewer
| resource |
| simple.pdf |
And "Brian" logs out
39 changes: 34 additions & 5 deletions tests/e2e/cucumber/steps/app-files/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ When(
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const info of stepTable.hashes()) {
if (info.type !== 'folder') {
throw new Error('resource creation is currently only supported for folders ')
}

await resourceObject.create({ name: info.resource, type: info.type })
await resourceObject.create({ name: info.resource, type: info.type, content: info.content })
}
}
)
Expand Down Expand Up @@ -309,3 +305,36 @@ export const processDownload = async (
}
}
}

When(
'{string} edits the following resource(s)',
async function (this: World, stepUser: string, stepTable: DataTable): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const info of stepTable.hashes()) {
await resourceObject.editResourse({ name: info.resource, content: info.content })
}
}
)

When(
/^"([^"]*)" opens the following file(s)? in (mediaviewer|pdfviewer)$/,
async function (
this: World,
stepUser: string,
_: string,
actionType: string,
stepTable: DataTable
) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })

for (const info of stepTable.hashes()) {
await resourceObject.openFileInViewer({
name: info.resource,
actionType: actionType === 'mediaviewer' ? 'mediaviewer' : 'pdfviewer'
})
}
}
)
149 changes: 133 additions & 16 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ const fileRow = '//ancestor::tr'
const resourceNameSelector = `[data-test-resource-name="%s"]`
const addNewResourceButton = `#new-file-menu-btn`
const createNewFolderButton = '#new-folder-btn'
const folderNameInput = '.oc-modal input'
const createNewTxtFileButton = '.new-file-btn-txt'
const createNewMdFileButton = '.new-file-btn-md'
const createNewDrawioFileButton = '.new-file-btn-drawio'
const saveTextFileInEditorButton = '#text-editor-controls-save'
const closeTextEditorOrViewerButton = '#app-top-bar-close'
const textEditorInput = '#text-editor-input'
const resourceNameInput = '.oc-modal input'
const resourceUploadButton = '#upload-menu-btn'
const fileUploadInput = '#files-file-upload-input'
const uploadInfoCloseButton = '#close-upload-info-btn'
Expand All @@ -38,6 +44,7 @@ const globalSearchOptions = '#files-global-search-options'
const loadingSpinner = '#files-global-search-options .loading'
const filesViewOptionButton = '#files-view-options-btn'
const hiddenFilesToggleButton = '//*[@data-testid="files-switch-hidden-files"]//button'
const previewImage = '//main[@id="preview"]//div[contains(@class,"preview-player")]//img'

export const clickResource = async ({
page,
Expand All @@ -50,7 +57,6 @@ export const clickResource = async ({
for (const name of paths) {
const resource = await page.locator(util.format(resourceNameSelector, name))
const itemId = await resource.locator(fileRow).getAttribute('data-item-id')

await Promise.all([
resource.click(),
page.waitForResponse(
Expand All @@ -69,35 +75,100 @@ export const clickResource = async ({
export interface createResourceArgs {
page: Page
name: string
type: 'folder'
type: 'folder' | 'txtFile' | 'mdFile' | 'drawioFile'
content?: string
}

export const createResource = async (args: createResourceArgs): Promise<void> => {
const { page, name } = args
const { page, name, type, content } = args
const paths = name.split('/')

for (const resource of paths) {
const folderExists = await resourceExists({
const resourcesExists = await resourceExists({
page: page,
name: resource
})

if (!folderExists) {
if (!resourcesExists) {
await page.locator(addNewResourceButton).click()
await page.locator(createNewFolderButton).click()
await page.locator(folderNameInput).fill(resource)
await Promise.all([
page.waitForResponse(
(resp) => resp.status() === 207 && resp.request().method() === 'PROPFIND'
),
page.locator(actionConfirmationButton).click()
])
}

await clickResource({ page, path: resource })
switch (type) {
case 'folder': {
await page.locator(createNewFolderButton).click()
await page.locator(resourceNameInput).fill(resource)
await Promise.all([
page.waitForResponse(
(resp) => resp.status() === 207 && resp.request().method() === 'PROPFIND'
),
page.locator(actionConfirmationButton).click()
])
break
}
case 'txtFile': {
await page.locator(createNewTxtFileButton).click()
await page.locator(resourceNameInput).fill(resource)
await Promise.all([
page.waitForResponse(
(resp) => resp.status() === 201 && resp.request().method() === 'PUT'
),
page.locator(actionConfirmationButton).click()
])
await editTextDocument({ page, content: content })
break
}
case 'mdFile': {
await page.locator(createNewMdFileButton).click()
await page.locator(resourceNameInput).fill(resource)
await Promise.all([
page.waitForResponse(
(resp) => resp.status() === 201 && resp.request().method() === 'PUT'
),
page.locator(actionConfirmationButton).click()
])
await editTextDocument({ page, content: content })
break
}
case 'drawioFile': {
await page.locator(createNewDrawioFileButton).click()
await page.locator(resourceNameInput).fill(resource)

const [drawioTab] = await Promise.all([
page.waitForEvent('popup'),
page.waitForResponse(
(resp) => resp.status() === 201 && resp.request().method() === 'PUT'
),
page.locator(actionConfirmationButton).click()
])
await drawioTab.waitForLoadState()
await drawioTab.locator('.geBigButton', { hasText: 'Save' }).isVisible()
await drawioTab.waitForURL('**/draw-io/spaces/**')
await drawioTab.close()
break
}
}
}
if (type === 'folder') {
await clickResource({ page, path: resource })
}
}
}

export const editTextDocument = async ({
page,
content
}: {
page: Page
content: string
}): Promise<void> => {
await Promise.all([
page.waitForResponse((resp) => resp.status() === 204 && resp.request().method() === 'PUT'),
page.locator(textEditorInput).fill(content),
page.locator(saveTextFileInEditorButton).click()
])

await Promise.all([page.waitForNavigation(), page.locator(closeTextEditorOrViewerButton).click()])
}

/**/

export interface uploadResourceArgs {
Expand Down Expand Up @@ -447,3 +518,49 @@ export const showHiddenResources = async (page): Promise<void> => {
await page.locator(filesViewOptionButton).click()
await page.locator(hiddenFilesToggleButton).click()
}

export interface editResourcesArgs {
page: Page
name: string
content: string
}

export const editResources = async (args: editResourcesArgs): Promise<void> => {
const { page, name, content } = args
await page.locator(util.format(resourceNameSelector, name)).click()
await editTextDocument({ page, content: content })
}

export interface openFileInViewerArgs {
page: Page
name: string
actionType: 'mediaviewer' | 'pdfviewer'
}

export const openFileInViewer = async (args: openFileInViewerArgs): Promise<void> => {
const { page, name, actionType } = args

if (actionType === 'mediaviewer') {
await Promise.all([
page.waitForResponse(
(resp) =>
resp.url().includes('preview') &&
resp.status() === 200 &&
resp.request().method() === 'GET'
),
page.locator(util.format(resourceNameSelector, name)).click()
])

// in case of error <img> doesn't contain src="blob:https://url"
expect(await page.locator(previewImage).getAttribute('src')).toContain('blob')
} else {
await Promise.all([
page.waitForResponse(
(resp) => resp.status() === 207 && resp.request().method() === 'PROPFIND'
),
page.locator(util.format(resourceNameSelector, name)).click()
])
}

await Promise.all([page.waitForNavigation(), page.locator(closeTextEditorOrViewerButton).click()])
}
14 changes: 13 additions & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import {
searchResourceGlobalSearchArgs,
getDisplayedResourcesFromSearch,
clickResource,
showHiddenResources
showHiddenResources,
editResources,
editResourcesArgs,
openFileInViewer,
openFileInViewerArgs
} from './actions'

export class Resource {
Expand Down Expand Up @@ -133,4 +137,12 @@ export class Resource {
async showHiddenFiles(): Promise<void> {
await showHiddenResources(this.#page)
}

async editResourse(args: Omit<editResourcesArgs, 'page'>): Promise<void> {
await editResources({ ...args, page: this.#page })
}

async openFileInViewer(args: Omit<openFileInViewerArgs, 'page'>): Promise<void> {
await openFileInViewer({ ...args, page: this.#page })
}
}

0 comments on commit 93c81b7

Please sign in to comment.