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

[full-ci][tests-only]Add internal link related e2e tests #8260

Merged
merged 4 commits into from
Feb 2, 2023
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
32 changes: 32 additions & 0 deletions tests/e2e/cucumber/features/smoke/internalLink.ocis.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Feature: internal link share

Scenario: share a link with internal role
Given "Admin" creates following users
| id |
| Alice |
| Brian |
And "Alice" creates the following folder in personal space using API
| name |
| myfolder |
And "Alice" shares the following resource using API
| resource | recipient | type | role |
| myfolder | Brian | user | editor |
And "Alice" logs in
And "Alice" opens the "files" app
And "Alice" creates a public link for the resource "myfolder" using the sidebar panel
When "Alice" edits the public link named "Link" of resource "myfolder" changing role to "internal"
And "Brian" opens the public link "Link"
And "Brian" logs in from the internal link
And "Brian" opens shared-with-me page from the internal link
And "Brian" accepts the following share
| name |
| myfolder |
And "Brian" uploads the following resource
| resource | to |
| simple.pdf | myfolder |
And "Alice" updates following sharee role
| resource | recipient | type | role |
| myfolder | Brian | user | custom_permissions:read |
And "Alice" logs out
Then "Brian" should see folder "myfolder" but should not be able to edit
And "Brian" logs out
5 changes: 3 additions & 2 deletions tests/e2e/cucumber/steps/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ Given(
await api.share.createShare({
user,
path: info.resource,
shareWith: info.recipient,
shareType: info.type,
role: info.role
shareWith: info.recipient,
role: info.role,
name: info.name
})
}
}
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/cucumber/steps/ui/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,12 @@ When(
expect(role).toBe(newPermission.toLowerCase())
}
)

When(
'{string} opens shared-with-me page from the internal link',
async function (this: World, stepUser: string): Promise<void> {
const actor = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.shares.WithMe({ page: actor.page })
await pageObject.openShareWithMeFromInternalLink(actor)
}
)
23 changes: 18 additions & 5 deletions tests/e2e/cucumber/steps/ui/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ import { DateTime } from 'luxon'
import { kebabCase } from 'lodash'
import { objects } from '../../../support'

async function LogInUser(this: World, stepUser: string): Promise<void> {
const user = this.usersEnvironment.getUser({ key: stepUser })
const { page } = await this.actorsEnvironment.createActor({
async function createNewSession(world: World, stepUser: string) {
const { page } = await world.actorsEnvironment.createActor({
key: stepUser,
namespace: kebabCase(
[this.feature.name, stepUser, DateTime.now().toFormat('yyyy-M-d-hh-mm-ss')].join('-')
[world.feature.name, stepUser, DateTime.now().toFormat('yyyy-M-d-hh-mm-ss')].join('-')
saw-jan marked this conversation as resolved.
Show resolved Hide resolved
)
})
const sessionObject = new objects.runtime.Session({ page })
return new objects.runtime.Session({ page })
}

async function LogInUser(this: World, stepUser: string): Promise<void> {
const sessionObject = await createNewSession(this, stepUser)
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const user = this.usersEnvironment.getUser({ key: stepUser })
await page.goto(config.frontendUrl)
await sessionObject.login({ user })
}
Expand All @@ -35,3 +39,12 @@ async function LogOutUser(this: World, stepUser: string): Promise<void> {
Given('{string} has logged out', LogOutUser)

When('{string} logs out', LogOutUser)

When(
'{string} logs in from the internal link',
async function (this: World, stepUser: string): Promise<void> {
const sessionObject = await createNewSession(this, stepUser)
const user = this.usersEnvironment.getUser({ key: stepUser })
await sessionObject.login({ user })
}
)
9 changes: 6 additions & 3 deletions tests/e2e/support/api/share/share.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ export const createShare = async ({
path,
shareWith,
shareType,
role
role,
name
}: {
user: User
path: string
shareWith: string
shareType: string
role: string
shareWith?: string
role?: string
name?: string
}): Promise<void> => {
const body = new URLSearchParams()
body.append('path', path)
body.append('shareWith', shareWith)
body.append('shareType', shareTypes[shareType])
body.append('role', role)
body.append('name', name)

const response = await request({
method: 'POST',
Expand Down
8 changes: 8 additions & 0 deletions tests/e2e/support/environment/actor/actor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export class ActorEnvironment extends EventEmitter implements Actor {
this.page = await this.context.newPage()
}

public async newPage(newPage: Page): Promise<Page> {
// close the old page
await this.page.close()
// set the new page
this.page = newPage
return this.page
}
Comment on lines +31 to +37
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, actor's page will be replaced with new tab and the old tab is closed
Please, suggest if it feels odd and if you have other great ideas.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can store browser context for multiple pages then it will be helpful in the future when we need to open a new page do some tasks and come back to the old page and do some task and close the old page.
Or it is not needed for now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO may be needed in the future, but not in this PR


async close(): Promise<void> {
if (this.options.context.reportTracing) {
await this.context?.tracing.stop({
Expand Down
12 changes: 12 additions & 0 deletions tests/e2e/support/objects/app-files/page/shares/withMe.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Page } from 'playwright'
import { Actor } from '../../../../../support/types'

const sharesNavSelector = '//a[@data-nav-name="files-shares-with-me"]'
const openShareWithMeButton = `//a/span[text()='Open "Shared with me"']`
const shareWithMeNavSelector = '//a/span[text()="Shared with me"]'

export class WithMe {
#page: Page
Expand All @@ -12,4 +15,13 @@ export class WithMe {
async navigate(): Promise<void> {
await this.#page.locator(sharesNavSelector).click()
}

async openShareWithMeFromInternalLink(actor: Actor): Promise<void> {
const [newTab] = await Promise.all([
this.#page.waitForEvent('popup'),
this.#page.locator(openShareWithMeButton).click()
])
await newTab.waitForSelector(shareWithMeNavSelector)
await actor.newPage(newTab)
}
}
1 change: 1 addition & 0 deletions tests/e2e/support/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Actor {
context: BrowserContext
page: Page
close(): Promise<void>
newPage(page: Page): Promise<Page>
}

export interface User {
Expand Down