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

[tests-only] override lint rules for tests/e2e #10562

Merged
merged 3 commits into from
Mar 11, 2024
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
18 changes: 17 additions & 1 deletion docs/testing/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ To run a particular test, simply add the feature file and line number to the tes

Various options are available via ENV variables, e.g.

- `BASIC_AUTH=true` use basic authorization for api requests.
- `BASIC_AUTH=true` use basic authorization for api requests.
- `RETRY=n` to retry failures `n` times
- `SLOW_MO=n` to slow the execution time by `n` milliseconds
- `TIMEOUT=n` to set tests to timeout after `n` milliseconds
Expand All @@ -99,6 +99,22 @@ To then open e.g. the tracing from the `REPORT_DIR`, run
$ npx playwright show-trace path/to/file.zip
```

#### Lint E2E Test Code

Run the following command to find out the lint issues early in the test codes:

```shell
$ pnpm lint
```

And to fix the lint problems run the following command:

```shell
$ pnpm lint --fix
```

If the lint problems are not fixed by `--fix` option, we have to manually fix the code.

### Acceptance Tests (Nightwatch)

{{< hint info >}}
Expand Down
29 changes: 29 additions & 0 deletions tests/e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"extends": "@ownclouders",
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"project": ["./tsconfig.json"] // for TypeScript files
},
"rules": {
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off"
Comment on lines +17 to +25
Copy link
Member Author

Choose a reason for hiding this comment

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

we will eventually change them to error if possible but in separate PRs because the changes would be large

}
}
]
}
2 changes: 1 addition & 1 deletion tests/e2e/cucumber/steps/ui/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Then(
/^"([^"]*)" is in a (text-editor|pdf-viewer|image-viewer)$/,
async function (this: World, stepUser: string, fileViewerType: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const fileViewerLocator = await editor.fileViewerLocator({ page, fileViewerType })
const fileViewerLocator = editor.fileViewerLocator({ page, fileViewerType })
await expect(fileViewerLocator).toBeVisible()
}
)
Expand Down
25 changes: 17 additions & 8 deletions tests/e2e/cucumber/steps/ui/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { config } from '../../../config'
import {
createResourceTypes,
displayedResourceType,
shortcutType
shortcutType,
ActionViaType
} from '../../../support/objects/app-files/resource/actions'
import { Public } from '../../../support/objects/app-files/page/public'
import { Resource } from '../../../support/objects/app-files'
Expand Down Expand Up @@ -442,15 +443,23 @@ export const processDownload = async (
for (const folder of Object.keys(downloadInfo)) {
files = downloadInfo[folder]
parentFolder = folder !== 'undefined' ? folder : null

let via: ActionViaType = 'SINGLE_SHARE_VIEW'
switch (actionType) {
case 'batch action':
via = 'BATCH_ACTION'
break
case 'sidebar panel':
via = 'SIDEBAR_PANEL'
break
default:
break
}

downloads = await pageObject.download({
folder: parentFolder,
resources: files,
via:
actionType === 'batch action'
? 'BATCH_ACTION'
: actionType === 'sidebar panel'
? 'SIDEBAR_PANEL'
: 'SINGLE_SHARE_VIEW'
via
})

downloads.forEach((download) => {
Expand Down Expand Up @@ -757,7 +766,7 @@ Then(
async function (this: World, stepUser: string, file: string, actionType: string) {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const resourceObject = new objects.applicationFiles.Resource({ page })
const lockLocator = await resourceObject.getLockLocator({ resource: file })
const lockLocator = resourceObject.getLockLocator({ resource: file })

actionType === 'should'
? await expect(lockLocator).toBeVisible()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/cucumber/steps/ui/spaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ When(
)

When(
'{string} downloads the space {string}',
async function (this: World, stepUser: string, space: string): Promise<void> {
/^"([^"]*)" downloads the space (?:"[^"]*")$/,
async function (this: World, stepUser: string): Promise<void> {
const { page } = this.actorsEnvironment.getActor({ key: stepUser })
const spacesObject = new objects.applicationFiles.Spaces({ page })
const downloadedResource = await spacesObject.downloadSpace()
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/support/objects/app-files/link/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ 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')
? await expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'text')
: await expect(page.locator(editPublicLinkInput)).toHaveAttribute('type', 'password')
}

export const copyEnteredPassword = async (page: Page): Promise<void> => {
Expand Down
10 changes: 6 additions & 4 deletions tests/e2e/support/objects/app-files/resource/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const createSpaceFromSelection = async ({
}): Promise<Space> => {
await selectOrDeselectResources({
page,
resources: resources.map((r) => ({ name: r }) as resourceArgs),
resources: resources.map((r) => ({ name: r }) as resourceArgs), // prettier-ignore
select: true
})
await page.locator(util.format(resourceNameSelector, resources[0])).click({ button: 'right' })
Expand Down Expand Up @@ -594,11 +594,13 @@ interface resourceArgs {
type?: string
}

export type ActionViaType = 'SIDEBAR_PANEL' | 'BATCH_ACTION' | 'SINGLE_SHARE_VIEW'

export interface downloadResourcesArgs {
page: Page
resources: resourceArgs[]
folder?: string
via: 'SIDEBAR_PANEL' | 'BATCH_ACTION' | 'SINGLE_SHARE_VIEW'
via: ActionViaType
}

export const downloadResources = async (args: downloadResourcesArgs): Promise<Download[]> => {
Expand Down Expand Up @@ -1008,7 +1010,7 @@ export interface deleteResourceArgs {
page: Page
resourcesWithInfo: resourceArgs[]
folder?: string
via: 'SIDEBAR_PANEL' | 'BATCH_ACTION'
via: ActionViaType
}

export const deleteResource = async (args: deleteResourceArgs): Promise<void> => {
Expand Down Expand Up @@ -1705,7 +1707,7 @@ export interface expectFileToBeLockedArgs {
resource: string
}

export const getLockLocator = async (args: expectFileToBeLockedArgs): Promise<Locator> => {
export const getLockLocator = (args: expectFileToBeLockedArgs): Locator => {
const { page, resource } = args
return page.locator(util.format(resourceLockIcon, resource))
}
2 changes: 1 addition & 1 deletion tests/e2e/support/objects/app-files/resource/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ export class Resource {
await po.openShotcut({ page: this.#page, name: name, url: url })
}

async getLockLocator(args: Omit<po.expectFileToBeLockedArgs, 'page'>): Promise<Locator> {
getLockLocator(args: Omit<po.expectFileToBeLockedArgs, 'page'>): Locator {
return po.getLockLocator({ ...args, page: this.#page })
}
}
4 changes: 2 additions & 2 deletions tests/e2e/support/objects/app-files/utils/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export const save = async (page: Page): Promise<unknown> => {
])
}

export const fileViewerLocator = async ({
export const fileViewerLocator = ({
page,
fileViewerType
}: {
page: Page
fileViewerType: string
}): Promise<Locator> => {
}): Locator => {
switch (fileViewerType) {
case 'text-editor':
return page.locator(texEditor)
Expand Down