Skip to content

Commit

Permalink
get rid of isVisible() (owncloud#8726)
Browse files Browse the repository at this point in the history
part2

fix
  • Loading branch information
ScharfViktor authored Mar 28, 2023
1 parent d46b992 commit d4a384c
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 50 deletions.
20 changes: 8 additions & 12 deletions tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,12 @@ Then(
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
for (const info of stepTable.hashes()) {
if (actionType === 'should not') {
const isVisible = await resourceObject.isDeleteTrashBinButtonVisible({
resource: info.resource
})
expect(isVisible).toBe(false)
} else {
if (actionType === 'should') {
const message = await resourceObject.deleteTrashBin({ resource: info.resource })
const paths = info.resource.split('/')
expect(message).toBe(`"${paths[paths.length - 1]}" was deleted successfully`)
} else {
await resourceObject.expectThatDeleteTrashBinButtonIsNotVisible({ resource: info.resource })
}
}
}
Expand All @@ -198,17 +195,16 @@ Then(
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
for (const info of stepTable.hashes()) {
if (actionType === 'should not') {
const isVisible = await resourceObject.isRestoreTrashBinButtonVisible({
resource: info.resource
})
expect(isVisible).toBe(false)
} else {
if (actionType === 'should') {
const message = await resourceObject.restoreTrashBin({
resource: info.resource
})
const paths = info.resource.split('/')
expect(message).toBe(`${paths[paths.length - 1]} was restored successfully`)
} else {
await resourceObject.expectThatRestoreTrashBinButtonIsNotVisible({
resource: info.resource
})
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e/cucumber/steps/ui/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ Then(
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const spacesObject = new objects.applicationFiles.Spaces({ page })
const spaceID = spacesObject.getSpaceID({ key: space })
const isSpaceNotVisible = await spacesObject.spacesIdExist(spaceID)
expect(isSpaceNotVisible).toBe(true)
await spacesObject.expectThatSpacesIdNotExist(spaceID)
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { locatorUtils } from '../../../utils'
const spaceTrSelector = '.spaces-table tbody > tr'
const actionConfirmButton = '.oc-modal-body-actions-confirm'
const contextMenuSelector = `[data-item-id="%s"] .spaces-table-btn-action-dropdown`
const spaceCheckboxSelector = `[data-item-id="%s"]:not(.oc-table-highlighted) input[type=checkbox]`
const spaceCheckboxSelector = `[data-item-id="%s"] input[type=checkbox]`
const contextMenuActionButton = `.oc-files-actions-%s-trigger`
const inputFieldSelector =
'//div[@class="oc-modal-body-input"]//input[contains(@class,"oc-text-input")]'
Expand Down Expand Up @@ -148,7 +148,7 @@ export const deleteSpace = async (args: {
export const selectSpace = async (args: { page: Page; id: string }): Promise<void> => {
const { page, id } = args
const checkbox = await page.locator(util.format(spaceCheckboxSelector, id))
const checkBoxAlreadySelected = !(await checkbox.isVisible())
const checkBoxAlreadySelected = await checkbox.isChecked()
if (checkBoxAlreadySelected) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/support/objects/app-admin-settings/users/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const userFilterOption = '//ul[contains(@class, "item-filter-list")]//button[@da
const usersTable = '.users-table'
const quotaInput = '#quota-select-form .vs__search'
const quotaValueDropDown = `.vs__dropdown-option :text-is("%s")`
const userCheckboxSelector = `[data-item-id="%s"]:not(.oc-table-highlighted) input[type=checkbox]`
const userCheckboxSelector = `[data-item-id="%s"] input[type=checkbox]`
const editQuotaBtn = '.oc-files-actions-edit-quota-trigger'
const quotaInputBatchAction = '#quota-select-batch-action-form .vs__search'
const userInput = '#%s-input'
Expand Down Expand Up @@ -145,7 +145,7 @@ export const getDisplayedUsers = async (args: { page: Page }): Promise<string[]>
export const selectUser = async (args: { page: Page; uuid: string }): Promise<void> => {
const { page, uuid } = args
const checkbox = await page.locator(util.format(userCheckboxSelector, uuid))
const checkBoxAlreadySelected = !(await checkbox.isVisible())
const checkBoxAlreadySelected = await checkbox.isChecked()
if (checkBoxAlreadySelected) {
return
}
Expand Down
14 changes: 8 additions & 6 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,17 +639,18 @@ export const deleteResourceTrashbin = async (args: deleteResourceTrashbinArgs):
return message.trim().toLowerCase()
}

export const getDeleteResourceButtonVisibility = async (
export const expectThatDeleteButtonIsNotVisible = async (
args: deleteResourceTrashbinArgs
): Promise<boolean> => {
): Promise<void> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
util.format(checkBoxForTrashbin, `/${resource.replace(/^\/+/, '')}`)
)
if (!(await resourceCheckbox.isChecked())) {
await resourceCheckbox.check()
}
return await page.locator(permanentDeleteButton).isVisible()
const deleteButton = page.locator(permanentDeleteButton)
await expect(deleteButton).not.toBeVisible()
}

export interface restoreResourceTrashbinArgs {
Expand Down Expand Up @@ -685,17 +686,18 @@ export const restoreResourceTrashbin = async (
return message.trim().toLowerCase()
}

export const getRestoreResourceButtonVisibility = async (
export const expectThatRestoreResourceButtonVisibility = async (
args: restoreResourceTrashbinArgs
): Promise<boolean> => {
): Promise<void> => {
const { page, resource } = args
const resourceCheckbox = page.locator(
util.format(checkBoxForTrashbin, `/${resource.replace(/^\/+/, '')}`)
)
if (!(await resourceCheckbox.isChecked())) {
await resourceCheckbox.check()
}
return await page.locator(restoreResourceButton).isVisible()
const restoreButton = page.locator(restoreResourceButton)
await expect(restoreButton).not.toBeVisible()
}

export const getTagsForResourceVisibilityInFilesTable = async (
Expand Down
16 changes: 8 additions & 8 deletions tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {
editResourcesArgs,
openFileInViewer,
openFileInViewerArgs,
getDeleteResourceButtonVisibility,
getRestoreResourceButtonVisibility,
expectThatDeleteButtonIsNotVisible,
expectThatRestoreResourceButtonVisibility,
deleteResourceTrashbinArgs,
addTagsToResource,
removeTagsFromResource,
Expand Down Expand Up @@ -140,10 +140,10 @@ export class Resource {
return message
}

async isDeleteTrashBinButtonVisible(
async expectThatDeleteTrashBinButtonIsNotVisible(
args: Omit<deleteResourceTrashbinArgs, 'page'>
): Promise<boolean> {
return await getDeleteResourceButtonVisibility({ ...args, page: this.#page })
): Promise<void> {
return await expectThatDeleteButtonIsNotVisible({ ...args, page: this.#page })
}

async restoreTrashBin(args: Omit<restoreResourceTrashbinArgs, 'page'>): Promise<string> {
Expand All @@ -153,10 +153,10 @@ export class Resource {
return message
}

async isRestoreTrashBinButtonVisible(
async expectThatRestoreTrashBinButtonIsNotVisible(
args: Omit<restoreResourceTrashbinArgs, 'page'>
): Promise<boolean> {
return await getRestoreResourceButtonVisibility({ ...args, page: this.#page })
): Promise<void> {
return await expectThatRestoreResourceButtonVisibility({ ...args, page: this.#page })
}

async areTagsVisibleForResourceInFilesTable(
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/support/objects/app-files/spaces/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const editSpacesDescription = '.oc-files-actions-edit-readme-content-trigger:vis
const spacesDescriptionInputArea = '#description-input-area'
const sideBarActions =
'//ul[@id="oc-files-actions-sidebar"]//span[@class="oc-files-context-action-label"]'
const spaceDeletedFilesButton = '.oc-files-actions-delete-trigger:visible'
const spaceContextButton = '#space-context-btn'

export const openActionsPanel = async (page: Page): Promise<void> => {
await sidebar.open({ page })
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/support/objects/app-files/spaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
addExpirationDateToMember,
removeExpirationDateFromMember
} from './actions'
import { spaceWithSpaceIDExist } from './utils'
import { spaceWithSpaceIDNotExist } from './utils'
import { ICollaborator } from '../share/collaborator'

export class Spaces {
Expand Down Expand Up @@ -84,8 +84,8 @@ export class Spaces {
return id
}

async spacesIdExist(spaceID: string): Promise<boolean> {
return await spaceWithSpaceIDExist({ spaceID, page: this.#page })
async expectThatSpacesIdNotExist(spaceID: string): Promise<void> {
await spaceWithSpaceIDNotExist({ spaceID, page: this.#page })
}

async canUserEditResource(args: Omit<canUserEditSpaceResourceArgs, 'page'>): Promise<boolean> {
Expand Down
17 changes: 4 additions & 13 deletions tests/e2e/support/objects/app-files/spaces/utils.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import { expect } from '@playwright/test'
import { Page } from 'playwright'
import util from 'util'

const emptySpacesSelector = '//span[@data-msgid="%s"]'
const spaceIdSelector = `[data-item-id="%s"]`

export interface searchForSpacesIdsArgs {
spaceID: string
page: Page
}
export const spaceWithSpaceIDExist = async (args: searchForSpacesIdsArgs): Promise<boolean> => {
export const spaceWithSpaceIDNotExist = async (args: searchForSpacesIdsArgs): Promise<void> => {
const { page, spaceID } = args
const emptySpacesMessage = "You don't have access to any spaces"

// for empty case
if (await page.isVisible(util.format(emptySpacesSelector, emptySpacesMessage))) {
return true
}
// if more than one spaces exists
if (!(await page.isVisible(util.format(spaceIdSelector, spaceID)))) {
return true
}
return false
const space = page.locator(util.format(spaceIdSelector, spaceID))
await expect(space).not.toBeVisible()
}

0 comments on commit d4a384c

Please sign in to comment.