Skip to content

Commit

Permalink
added e2e test for show password, copy password and generate password…
Browse files Browse the repository at this point in the history
… buttons (owncloud#9820)
  • Loading branch information
PrajwolAmatya authored and LukasHirt committed Oct 25, 2023
1 parent 80952b0 commit 8e1a52b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 1 deletion.
8 changes: 8 additions & 0 deletions tests/e2e/cucumber/features/smoke/spaces/publicLink.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,17 @@ Feature: spaces public link
"""
Unfortunately, your password is commonly used. please pick a harder-to-guess password for your safety
"""
And "Alice" closes the public link password dialog box
When "Alice" tries to sets the password of the public link named "myPublicLink" of resource "lorem.txt" to "12345678"
Then "Alice" should see an error message
"""
Unfortunately, your password is commonly used. please pick a harder-to-guess password for your safety
"""
And "Alice" reveals the password of the public link
And "Alice" hides the password of the public link
And "Alice" generates the password for the public link
And "Alice" copies the password of the public link
And "Alice" sets the password of the public link
And "Anonymous" opens the public link "myPublicLink"
And "Anonymous" unlocks the public link with password "%copied_password%"
And "Alice" logs out
46 changes: 45 additions & 1 deletion tests/e2e/cucumber/steps/ui/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,51 @@ When(
}
)

When(
/^"([^"]*)" (reveals|hides) the password of the public link$/,
async function (this: World, stepUser: string, showOrHide: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.showOrHidePassword({ showOrHide })
}
)

When(
'{string} closes the public link password dialog box',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.clickOnCancelButton()
}
)

When(
'{string} copies the password of the public link',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.copyEnteredPassword()
}
)

When(
'{string} generates the password for the public link',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.generatePassword()
}
)

When(
'{string} sets the password of the public link',
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const linkObject = new objects.applicationFiles.Link({ page })
await linkObject.setPassword()
}
)

When(
'{string} edits the public link named {string} of resource {string} changing role to {string}',
async function (
Expand Down Expand Up @@ -158,7 +203,6 @@ Then(
const linkObject = new objects.applicationFiles.Link({ page })
const actualErrorMessage = await linkObject.checkErrorMessage()
expect(actualErrorMessage).toBe(errorMessage)
await linkObject.clickOnCancelButton()
}
)

Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/cucumber/steps/ui/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ When(
async function (this: World, stepUser: string, password: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const pageObject = new objects.applicationFiles.page.Public({ page })
if (password === '%copied_password%') {
password = await page.evaluate('navigator.clipboard.readText()')
}
await pageObject.authenticate({ password })
}
)
Expand Down
37 changes: 37 additions & 0 deletions tests/e2e/support/objects/app-files/link/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ const confirmDeleteButton = `//button[contains(@class,"oc-modal-body-actions-con
const notificationContainer = 'div.oc-notification'
const publicLinkPasswordErrorMessage = `//div[contains(@class, "oc-text-input-message oc-text-input-danger")]/span`
const cancelButton = '.oc-modal-body-actions-cancel'
const showOrHidePasswordButton = '.oc-text-input-show-password-toggle'
const copyPasswordButton = '.oc-text-input-copy-password-button'
const generatePasswordButton = '.oc-text-input-generate-password-button'
const expectedRegexForGeneratedPassword = /^[A-Za-z0-9\s\S]{12}$/

const getRecentLinkUrl = async (page: Page): Promise<string> => {
return page.locator(publicLinkUrlList).first().textContent()
Expand Down Expand Up @@ -204,6 +208,39 @@ export const addPassword = async (args: addPasswordArgs): Promise<void> => {
expect(message.trim()).toBe('Link was updated successfully')
}

export const showOrHidePassword = async (args): Promise<void> => {
const { page, showOrHide } = args
await page.locator(showOrHidePasswordButton).click()
showOrHide === 'reveals'
? expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'text')
: expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'password')
}

export const copyEnteredPassword = async (page: Page): Promise<void> => {
const enteredPassword = await page.locator(editPublicLinkInput).inputValue()
await page.locator(copyPasswordButton).click()
const copiedPassword = await page.evaluate('navigator.clipboard.readText()')
expect(enteredPassword).toBe(copiedPassword)
}

export const generatePassword = async (page: Page): Promise<void> => {
await page.locator(generatePasswordButton).click()
const generatedPassword = await page.locator(editPublicLinkInput).inputValue()
expect(generatedPassword).toMatch(expectedRegexForGeneratedPassword)
}

export const setPassword = async (page: Page): Promise<void> => {
await Promise.all([
page.waitForResponse(
(res) =>
res.url().includes('api/v1/shares/') &&
res.request().method() === 'PUT' &&
res.status() === 200
),
page.locator(editPublicLinkRenameConfirm).click()
])
}

export const addExpiration = async (args: addExpirationArgs): Promise<void> => {
const { page, resource, linkName, expireDate } = args
const resourcePaths = resource.split('/')
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/support/objects/app-files/link/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ export class Link {
await po.fillPassword({ page: this.#page, ...args })
}

async showOrHidePassword(args): Promise<void> {
return po.showOrHidePassword({ page: this.#page, ...args })
}

async copyEnteredPassword(): Promise<void> {
return po.copyEnteredPassword(this.#page)
}

async generatePassword(): Promise<void> {
return po.generatePassword(this.#page)
}

async setPassword(): Promise<void> {
return po.setPassword(this.#page)
}

async changeRole(args: Omit<po.changeRoleArgs, 'page'>): Promise<string> {
const startUrl = this.#page.url()
const role = await po.changeRole({ page: this.#page, ...args })
Expand Down

0 comments on commit 8e1a52b

Please sign in to comment.