Skip to content

Commit

Permalink
[tests-only] e2e tests for url stability open file directly in the web (
Browse files Browse the repository at this point in the history
#10206)

* tests: add tests for url stability

* refactor the getFileIdFunction

Signed-off-by: Swikriti Tripathi <[email protected]>

* address reviews

---------

Signed-off-by: Swikriti Tripathi <[email protected]>
  • Loading branch information
SwikritiT authored Dec 18, 2023
1 parent 5009f77 commit 0fce6eb
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/e2e/cucumber/features/smoke/urlJourneys.feature
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Feature: web can be navigated through urls
And "Alice" creates the following folders in personal space using API
| name |
| FOLDER |
And "Alice" creates the following files into personal space using API
| pathToFile | content |
| FOLDER/file_inside_folder.txt | example text |
And "Alice" creates the following files into personal space using API
| pathToFile | content |
| lorem.txt | some content |
Expand All @@ -24,4 +27,13 @@ Feature: web can be navigated through urls
And "Alice" shares the following resource using the direct url navigation
| resource | recipient | type | role | resourceType |
| lorem.txt | Brian | user | Can view | file |
When "Alice" opens the file "lorem.txt" through the URL
Then "Alice" is in a text-editor
And "Alice" closes the file viewer
When "Alice" opens the folder "FOLDER" through the URL
And "Alice" opens the following file in texteditor
| resource |
| file_inside_folder.txt |
Then "Alice" is in a text-editor
And "Alice" closes the file viewer
And "Alice" logs out
10 changes: 10 additions & 0 deletions tests/e2e/cucumber/steps/ui/navigateByUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,13 @@ When(
await urlNavObject.navigateToDetailsPanelOfResource({ resource, detailsPanel, user })
}
)

When(
'{string} opens the file/folder {string} through the URL',
async function (this: World, stepUser: string, resource: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const user = this.usersEnvironment.getUser({ key: stepUser })
const urlNavObject = new objects.urlNavigation.URLNavigation({ page })
await urlNavObject.openResourceViaUrl({ resource, user })
}
)
16 changes: 13 additions & 3 deletions tests/e2e/support/api/davSpaces/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ export const getDataOfFileInsideSpace = async ({
})
checkResponseStatus(response, `Failed while getting information of file ${pathToFileName}`)
const fileData = JSON.parse(convert.xml2json(await response.text(), { compact: true }))
return _.get(fileData, '[d:multistatus][d:response][d:propstat]')
return _.get(fileData, '[d:multistatus][d:response]')
}

export const getIdOfFileInsideSpace = async ({
Expand All @@ -201,8 +201,18 @@ export const getIdOfFileInsideSpace = async ({
spaceType,
spaceName
})
// extract file id form the response
return _.get(fileDataResponse, '[0][d:prop][oc:fileid]')._text
// when there is a file inside the folder response comes as
// [ [Object], [Object] ], so handel this case
if (fileDataResponse.constructor.name === 'Array') {
for (const key in fileDataResponse) {
if (fileDataResponse[key]['d:propstat'][0]['d:prop']['oc:name']._text === pathToFileName) {
return _.get(fileDataResponse[key], '[d:propstat][0][d:prop][oc:fileid]')._text
}
}
} else {
// extract file id form the response
return _.get(fileDataResponse, '[d:propstat][0][d:prop][oc:fileid]')._text
}
}

export const addMembersToTheProjectSpace = async ({
Expand Down
18 changes: 18 additions & 0 deletions tests/e2e/support/objects/url-navigation/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export interface navigateToDetailsPanelOfResourceArgs {
user: User
}

export interface openResourceViaUrlArgs {
page: Page
resource: string
user: User
}

export const navigateToDetailsPanelOfResource = async (
args: navigateToDetailsPanelOfResourceArgs
): Promise<void> => {
Expand All @@ -23,3 +29,15 @@ export const navigateToDetailsPanelOfResource = async (
const fullUrl = `${config.backendUrl}/f/${fileId}?details=${detailsPanel}`
await page.goto(fullUrl)
}

export const openResourceViaUrl = async (args: openResourceViaUrlArgs) => {
const { page, resource, user } = args
const fileId = await getIdOfFileInsideSpace({
user,
pathToFileName: resource,
spaceType: 'personal',
spaceName: user.displayName
})
const fullUrl = `${config.backendUrl}/f/${fileId}`
await page.goto(fullUrl)
}
4 changes: 4 additions & 0 deletions tests/e2e/support/objects/url-navigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ export class URLNavigation {
): Promise<void> {
await po.navigateToDetailsPanelOfResource({ ...args, page: this.#page })
}

async openResourceViaUrl(args: Omit<po.openResourceViaUrlArgs, 'page'>): Promise<void> {
await po.openResourceViaUrl({ ...args, page: this.#page })
}
}

0 comments on commit 0fce6eb

Please sign in to comment.