From ad2d27920ce928ae577fc481a7ae9313c7585760 Mon Sep 17 00:00:00 2001 From: Florian Schade Date: Mon, 16 Aug 2021 14:42:40 +0200 Subject: [PATCH] feat(support more backends): add ocis compatibility smoke tests now can also use ocis as backend, to do so add OCIS=true env before running the tests. More info in readme --- .eslintrc.js | 7 - package.json | 2 +- tests/smoke/README.md | 30 ++-- tests/smoke/helpers/api/http.ts | 2 +- tests/smoke/helpers/api/index.ts | 1 + tests/smoke/helpers/api/user.ts | 19 +- tests/smoke/helpers/cta/files/index.ts | 3 +- tests/smoke/helpers/cta/index.ts | 1 + tests/smoke/helpers/fixtures/files.ts | 2 +- tests/smoke/helpers/fixtures/users.ts | 52 +----- tests/smoke/helpers/index.ts | 1 + tests/smoke/pages/autorize.ts | 15 -- tests/smoke/pages/files/allFiles.ts | 167 +++++++++--------- tests/smoke/pages/index.ts | 3 +- tests/smoke/pages/login/index.ts | 24 +++ tests/smoke/pages/{login.ts => login/oc10.ts} | 10 +- tests/smoke/pages/login/ocis.ts | 20 +++ tests/smoke/setup/config.ts | 2 +- tests/smoke/steps/app.files.ts | 127 +++++++------ tests/smoke/steps/login.ts | 4 +- 20 files changed, 251 insertions(+), 241 deletions(-) delete mode 100644 tests/smoke/pages/autorize.ts create mode 100644 tests/smoke/pages/login/index.ts rename tests/smoke/pages/{login.ts => login/oc10.ts} (57%) create mode 100644 tests/smoke/pages/login/ocis.ts diff --git a/.eslintrc.js b/.eslintrc.js index 62b5ca263a5..8adcbf2ea62 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -42,13 +42,6 @@ module.exports = { '@typescript-eslint/no-extra-semi': 'off', '@typescript-eslint/no-explicit-any': 'off' } - }, - { - // prettier does not support `export * as foo from 'bar'` syntax. - files: ['tests/**/*.ts'], - rules: { - 'prettier/prettier': 'off' - } } ] } diff --git a/package.json b/package.json index 4fbe27b73dc..777de36f54c 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "test:acceptance:drone": "cucumber-js --retry 1 --require-module @babel/register --require-module @babel/polyfill --require tests/acceptance/setup.js --require tests/acceptance/stepDefinitions --format @cucumber/pretty-formatter", "test:acceptance:oc10": "cucumber-js --require-module @babel/register --require-module @babel/polyfill --require tests/acceptance/setup.js --require tests/acceptance/stepDefinitions --format @cucumber/pretty-formatter -t \"${TEST_TAGS:-not @skip and not @skipOnOC10}\"", "test:acceptance:ocis": "NODE_TLS_REJECT_UNAUTHORIZED=0 RUN_ON_OCIS=true cucumber-js --require-module @babel/register --require-module @babel/polyfill --require tests/acceptance/setup.js --require tests/acceptance/stepDefinitions --format @cucumber/pretty-formatter -t \"${TEST_TAGS:-not @skip and not @skipOnOCIS and not @notToImplementOnOCIS}\"", - "test:smoke:experimental": "cucumber-js --profile=smoke", + "test:smoke:experimental": "NODE_TLS_REJECT_UNAUTHORIZED=0 cucumber-js --profile=smoke", "test:unit": "jest --coverage --config ./tests/unit/config/jest.config.js", "test:integration": "jest --config ./tests/integration/config/jest.config.js" }, diff --git a/tests/smoke/README.md b/tests/smoke/README.md index a64f5d4e302..2bc1c661db2 100644 --- a/tests/smoke/README.md +++ b/tests/smoke/README.md @@ -7,8 +7,8 @@ Use with care, the smoke-test package introduces many new concepts and is still Before we release a new web version, we always take care that nothing breaks and the core features are working as expected. Till now this was a manual process which consumed a lot of time and effort. -Manual steps are error-prone by nature, on the one hand they can bring up unknown issues, but on the other it's easy -to forget some test steps. The main problem we faced, was that it's never a good thing to manually test your own code. +Manual steps are error-prone by nature, on the one hand they can bring up unknown issues, but on the other it's easy to +forget some test steps. The main problem we faced, was that it's never a good thing to manually test your own code. To get closer to the point where we are able to release faster and more often, we started to develop the WEB-Smoke-Tests package. @@ -22,7 +22,7 @@ development. The WEB-Smoke-Tests are much smaller and are still in an early phase. Many things are still not there compared to the mature tests/acceptance package. -** The main reasons why we decided to split out the smoke tests are: ** +**The main reasons why we decided to split out the smoke tests are:** * we wanted to test on a persona // use-case level * testing should be easy, fast and reliable @@ -48,6 +48,9 @@ To run the tests with below options, you have to set them as environment variabl $ OPTION_1=foo OPTION_2=bar yarn test:smoke:experimental ... ``` +* **OCIS=boolean** + * defines if the tests should use ocis as backend + * **default**: false * **SLOW_MO=time-in-ms** * run the tests with a timeout between every interaction * **default**: 0 @@ -63,28 +66,33 @@ $ OPTION_1=foo OPTION_2=bar yarn test:smoke:experimental ... This package is still in an early stage, design could change over time. -### Features `./tests/smoke/features` +### Features -Gherkin features a placed in there, nothing special, it follows +`./tests/smoke/features` +Gherkin features are placed in there, it follows the [gherkin features spec](https://cucumber.io/docs/gherkin/reference/) -### Steps `./tests/smoke/steps` +### Steps +`./tests/smoke/steps` Cucumber [step definitions](https://cucumber.io/docs/cucumber/step-definitions/) grouped by module // app. -### Setup `./tests/smoke/setup` +### Setup -All setup related stuff like config, cucumber or playwright preparation steps. +`./tests/smoke/setup` +Setup related stuff like config, cucumber or playwright preparation steps. -### Pages `./tests/smoke/pages` +### Pages +`./tests/smoke/pages` With the option in mind that the smoke-test package could grow, we decided to already group interactions inside page objects. To get more background what page objects are, you can read the [introduction here](https://playwright.dev/docs/pom/) -### Helper `./tests/smoke/helpers` +### Helper -All else that is needed to interact with the browser, api or other things. If you not sure where to place a certain +`./tests/smoke/helpers` +All else that is needed to interact with the browser, api or other parties. If you not sure where to place a certain functionality the helpers folder is a good fallback. ## Packages we use diff --git a/tests/smoke/helpers/api/http.ts b/tests/smoke/helpers/api/http.ts index 5f5efc17da9..dcc2edcebf5 100644 --- a/tests/smoke/helpers/api/http.ts +++ b/tests/smoke/helpers/api/http.ts @@ -10,7 +10,7 @@ export const request = async ({ body, user }: { - method: 'POST' | 'DELETE' | 'PUT' + method: 'POST' | 'DELETE' | 'PUT' | 'GET' path: string body?: BodyInit user?: User diff --git a/tests/smoke/helpers/api/index.ts b/tests/smoke/helpers/api/index.ts index b74a84b53fe..9f1fd5e08d5 100644 --- a/tests/smoke/helpers/api/index.ts +++ b/tests/smoke/helpers/api/index.ts @@ -1,2 +1,3 @@ +/* eslint-disable */ export * as http from './http' export * as user from './user' diff --git a/tests/smoke/helpers/api/user.ts b/tests/smoke/helpers/api/user.ts index 12b2572435b..59c5d50fcbc 100644 --- a/tests/smoke/helpers/api/user.ts +++ b/tests/smoke/helpers/api/user.ts @@ -8,8 +8,11 @@ export const createUser = async ({ user }: { user: User }): Promise => { const promChain = [] { const body = new URLSearchParams() + body.append('username', user.id) + body.append('email', user.email) body.append('userid', user.id) body.append('password', user.password) + body.append('displayname', user.displayName) const response = await request({ method: 'POST', @@ -40,7 +43,11 @@ export const createUser = async ({ user }: { user: User }): Promise => { ) }) - await Promise.all(promChain) + // initUser is there because ocis needs to have at least 1 request to the created user to perform deleteRequests later + // twice because it works, known issue and needs to be cleaned up once the ocis users service is moved to reva + for (const prom of [initUser({ user }), ...promChain, initUser({ user })]) { + await prom + } } export const deleteUser = async ({ user }: { user: User }): Promise => { @@ -52,3 +59,13 @@ export const deleteUser = async ({ user }: { user: User }): Promise => { return user } + +export const initUser = async ({ user }: { user: User }): Promise => { + await request({ + method: 'GET', + path: join('cloud', 'users', user.id), + user: Users.get({ id: user.id }) + }) + + return user +} diff --git a/tests/smoke/helpers/cta/files/index.ts b/tests/smoke/helpers/cta/files/index.ts index ff6a4ac701e..97b66747d22 100644 --- a/tests/smoke/helpers/cta/files/index.ts +++ b/tests/smoke/helpers/cta/files/index.ts @@ -1,2 +1,3 @@ -export * from './misc' +/* eslint-disable */ export * as sidebar from './sidebar' +export * from './misc' diff --git a/tests/smoke/helpers/cta/index.ts b/tests/smoke/helpers/cta/index.ts index fa4cf8c126e..cc36b610f29 100644 --- a/tests/smoke/helpers/cta/index.ts +++ b/tests/smoke/helpers/cta/index.ts @@ -1 +1,2 @@ +/* eslint-disable */ export * as files from './files' diff --git a/tests/smoke/helpers/fixtures/files.ts b/tests/smoke/helpers/fixtures/files.ts index 490a49dbef1..c4ca892ce45 100644 --- a/tests/smoke/helpers/fixtures/files.ts +++ b/tests/smoke/helpers/fixtures/files.ts @@ -3,7 +3,7 @@ import path from 'path' import { config } from '../../setup' import { File } from '../../types' -export abstract class Files { +export class Files { static get({ name }: { name: string }): File { const relPath = path.join(config.assets, name) diff --git a/tests/smoke/helpers/fixtures/users.ts b/tests/smoke/helpers/fixtures/users.ts index 2abc51100f9..bc667655f1d 100644 --- a/tests/smoke/helpers/fixtures/users.ts +++ b/tests/smoke/helpers/fixtures/users.ts @@ -1,75 +1,35 @@ import { User } from '../../types' -const passwords = { - admin: process.env.ADMIN_PASSWORD || 'admin', - regular: process.env.REGULAR_USER_PASSWORD || '123456', - alt1: process.env.ALT1_USER_PASSWORD || '1234', - alt2: process.env.ALT2_USER_PASSWORD || 'AaBb2Cc3Dd4', - alt3: process.env.ALT3_USER_PASSWORD || 'aVeryLongPassword42TheMeaningOfLife', - alt4: process.env.ALT4_USER_PASSWORD || 'ThisIsThe4thAlternatePwd', - alt11: process.env.ALT11_USER_PASSWORD || 'E-leven' -} const users: User[] = [ { id: 'admin', displayName: process.env.ADMIN_USERNAME || 'admin', - password: passwords.admin - }, - { - id: 'regularuser', - displayName: 'Regular User', - password: passwords.regular, - email: 'regularuser@example.org' - }, - { - id: 'user0', - displayName: 'Regular User', - password: passwords.regular, - email: 'user0@example.org' + password: 'admin' }, { id: 'Alice', displayName: 'Alice Hansen', - password: passwords.alt1, + password: '1234', email: 'alice@example.org' }, { id: 'Brian', displayName: 'Brian Murphy', - password: passwords.alt2, + password: '1234', email: 'brian@example.org' }, { id: 'Carol', displayName: 'Carol King', - password: passwords.alt3, + password: '1234', email: 'carol@example.org' }, { id: 'David', displayName: 'David Lopez', - password: passwords.alt4, + password: '1234', email: 'david@example.org' }, - { - id: 'user11', - displayName: 'User Eleven', - password: passwords.alt11, - email: 'user11@example.org' - }, - { - id: 'usergrp', - displayName: 'User Grp', - password: passwords.regular, - email: 'usergrp@example.org' - }, - { - id: 'sharee1', - displayName: 'Sharee One', - password: passwords.regular, - email: 'sharee1@example.org' - }, - // These users are available by default only in ocis backend when not using ldap { id: 'Einstein', displayName: 'Albert Einstein', @@ -96,7 +56,7 @@ const users: User[] = [ } ] -export abstract class Users { +export class Users { static get({ id }: { id: string }): User { const user = users.find(user => user.id === id) diff --git a/tests/smoke/helpers/index.ts b/tests/smoke/helpers/index.ts index a4c71ef6440..33a2e42ba18 100644 --- a/tests/smoke/helpers/index.ts +++ b/tests/smoke/helpers/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable */ export * as apiHelper from './api' export * as ctaHelper from './cta' export * as fixtures from './fixtures' diff --git a/tests/smoke/pages/autorize.ts b/tests/smoke/pages/autorize.ts deleted file mode 100644 index 052e727ab6d..00000000000 --- a/tests/smoke/pages/autorize.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { World } from '../setup' -import { Page } from 'playwright' - -export class AuthorizePage { - private page: Page - - constructor(world: World) { - this.page = world.page - } - - async authorize(): Promise { - await this.page.click('button[type="submit"]') - await this.page.waitForSelector('#web') - } -} diff --git a/tests/smoke/pages/files/allFiles.ts b/tests/smoke/pages/files/allFiles.ts index 929055683c0..dc3f9fd2e07 100644 --- a/tests/smoke/pages/files/allFiles.ts +++ b/tests/smoke/pages/files/allFiles.ts @@ -1,114 +1,115 @@ -import {World} from '../../setup' -import {Page, Download} from 'playwright' -import {File, User} from '../../types' -import {ctaHelper} from '../../helpers' +import { World } from '../../setup' +import { Page, Download } from 'playwright' +import { File, User } from '../../types' +import { ctaHelper } from '../../helpers' import path from 'path' export class AllFilesPage { - page: Page + page: Page - constructor(world: World) { - this.page = world.page - } - - async navigate(): Promise { - await this.page.click('a[href="#/files/list/all"]') - } + constructor(world: World) { + this.page = world.page + } - async createFolder({name}: { name: string }): Promise { - const paths = name.split('/') - const startUrl = this.page.url() + async navigate(): Promise { + await this.page.click('a[href="#/files/list/all"]') + } - for (const folderName of paths) { - const folderExists = await ctaHelper.files.resourceExists({ - page: this.page, - name: folderName - }) + async createFolder({ name }: { name: string }): Promise { + const paths = name.split('/') + const startUrl = this.page.url() - if (!folderExists) { - await this.page.click('#new-file-menu-btn') - await this.page.click('#new-folder-btn') - await this.page.fill('.oc-modal input', folderName) - await this.page.click('.oc-modal-body-actions-confirm') - } + for (const folderName of paths) { + const folderExists = await ctaHelper.files.resourceExists({ + page: this.page, + name: folderName + }) - await ctaHelper.files.navigateToFolder({page: this.page, path: folderName}) - } + if (!folderExists) { + await this.page.click('#new-file-menu-btn') + await this.page.click('#new-folder-btn') + await this.page.fill('.oc-modal input', folderName) + await this.page.click('.oc-modal-body-actions-confirm') + } - await this.page.goto(startUrl) - await this.page.waitForSelector('#files-personal-table') + await ctaHelper.files.navigateToFolder({ page: this.page, path: folderName }) } - async uploadFiles({files, folder}: { files: File[]; folder?: string }): Promise { - const startUrl = this.page.url() - - if (folder) { - await ctaHelper.files.navigateToFolder({page: this.page, path: folder}) - } - - await this.page.click('#new-file-menu-btn') - await this.page.setInputFiles( - '#fileUploadInput', - files.map(file => file.path) - ) + await this.page.goto(startUrl) + await this.page.waitForSelector('#files-personal-table') + } - await ctaHelper.files.waitForResources({ - page: this.page, - names: files.map(file => path.basename(file.name)) - }) + async uploadFiles({ files, folder }: { files: File[]; folder?: string }): Promise { + const startUrl = this.page.url() - await this.page.goto(startUrl) + if (folder) { + await ctaHelper.files.navigateToFolder({ page: this.page, path: folder }) } - async downloadFiles({names, folder}: { names: string[], folder: string }): Promise { - const startUrl = this.page.url() - const downloads = [] + await this.page.click('#new-file-menu-btn') + await this.page.setInputFiles( + '#fileUploadInput', + files.map(file => file.path) + ) + + await ctaHelper.files.waitForResources({ + page: this.page, + names: files.map(file => path.basename(file.name)) + }) - if (folder) { - await ctaHelper.files.navigateToFolder({page: this.page, path: folder}) - } + await this.page.goto(startUrl) + await this.page.click('body') + } - for (const name of names) { - await ctaHelper.files.sidebar.open({page: this.page, resource: name}) - await ctaHelper.files.sidebar.openPanel({page: this.page, name: 'actions'}) + async downloadFiles({ names, folder }: { names: string[]; folder: string }): Promise { + const startUrl = this.page.url() + const downloads = [] - const [download] = await Promise.all([ - this.page.waitForEvent('download'), - this.page.click('.oc-files-actions-download-trigger') - ]); + if (folder) { + await ctaHelper.files.navigateToFolder({ page: this.page, path: folder }) + } - await ctaHelper.files.sidebar.close({page: this.page}) + for (const name of names) { + await ctaHelper.files.sidebar.open({ page: this.page, resource: name }) + await ctaHelper.files.sidebar.openPanel({ page: this.page, name: 'actions' }) - downloads.push(download) - } + const [download] = await Promise.all([ + this.page.waitForEvent('download'), + this.page.click('.oc-files-actions-download-trigger') + ]) - await this.page.goto(startUrl) + await ctaHelper.files.sidebar.close({ page: this.page }) - return downloads + downloads.push(download) } - async shareFolder({folder, users}: { folder: string; users: User[] }): Promise { - const startUrl = this.page.url() - const folderPaths = folder.split('/') - const folderName = folderPaths.pop() + await this.page.goto(startUrl) - if (folderPaths.length) { - await ctaHelper.files.navigateToFolder({page: this.page, path: folderPaths.join('/')}) - } + return downloads + } - await ctaHelper.files.sidebar.open({page: this.page, resource: folderName}) - await ctaHelper.files.sidebar.openPanel({page: this.page, name: 'sharing'}) - await this.page.click('.files-collaborators-open-add-share-dialog-button') + async shareFolder({ folder, users }: { folder: string; users: User[] }): Promise { + const startUrl = this.page.url() + const folderPaths = folder.split('/') + const folderName = folderPaths.pop() - for (const user of users) { - await this.page.fill('#files-share-invite-input', user.displayName) - await this.page.waitForSelector('.vs--open') - await this.page.press('#files-share-invite-input', 'Enter') - } + if (folderPaths.length) { + await ctaHelper.files.navigateToFolder({ page: this.page, path: folderPaths.join('/') }) + } - await this.page.click('#files-collaborators-collaborator-save-new-share-button') - await ctaHelper.files.sidebar.close({page: this.page}) + await ctaHelper.files.sidebar.open({ page: this.page, resource: folderName }) + await ctaHelper.files.sidebar.openPanel({ page: this.page, name: 'sharing' }) + await this.page.click('.files-collaborators-open-add-share-dialog-button') - await this.page.goto(startUrl) + for (const user of users) { + await this.page.fill('#files-share-invite-input', user.displayName) + await this.page.waitForSelector('.vs--open') + await this.page.press('#files-share-invite-input', 'Enter') } + + await this.page.click('#files-collaborators-collaborator-save-new-share-button') + await ctaHelper.files.sidebar.close({ page: this.page }) + + await this.page.goto(startUrl) + } } diff --git a/tests/smoke/pages/index.ts b/tests/smoke/pages/index.ts index d196282882c..8fa004b3dfc 100644 --- a/tests/smoke/pages/index.ts +++ b/tests/smoke/pages/index.ts @@ -1,4 +1,3 @@ export * from './files' -export * from './autorize' -export * from './login' +export { LoginPage } from './login' export * from './runtime' diff --git a/tests/smoke/pages/login/index.ts b/tests/smoke/pages/login/index.ts new file mode 100644 index 00000000000..7322e354bf2 --- /dev/null +++ b/tests/smoke/pages/login/index.ts @@ -0,0 +1,24 @@ +import { config, World } from '../../setup' +import { Page } from 'playwright' +import { User } from '../../types' +import { Oc10LoginAdapter } from './oc10' +import { OcisLoginAdapter } from './ocis' + +export interface LoginAdapter { + login({ user }: { user: User }): Promise +} + +export class LoginPage { + private page: Page + private adapter: LoginAdapter + + constructor(world: World) { + this.page = world.page + this.adapter = config.ocis ? new OcisLoginAdapter(world) : new Oc10LoginAdapter(world) + } + + async login({ user }: { user: User }): Promise { + await this.adapter.login({ user }) + await this.page.waitForSelector('#web') + } +} diff --git a/tests/smoke/pages/login.ts b/tests/smoke/pages/login/oc10.ts similarity index 57% rename from tests/smoke/pages/login.ts rename to tests/smoke/pages/login/oc10.ts index 2cce290e7d3..97872fa32f0 100644 --- a/tests/smoke/pages/login.ts +++ b/tests/smoke/pages/login/oc10.ts @@ -1,8 +1,11 @@ -import { World } from '../setup' +import { World } from '../../setup' import { Page } from 'playwright' -import { User } from '../types' +import { User } from '../../types' -export class LoginPage { +/* eslint-disable-next-line */ +import { LoginAdapter } from './index' + +export class Oc10LoginAdapter implements LoginAdapter { private page: Page constructor(world: World) { @@ -13,5 +16,6 @@ export class LoginPage { await this.page.fill('input[name="user"]', user.id) await this.page.fill('input[name="password"]', user.password) await this.page.click('#submit') + await this.page.click('button[type="submit"]') } } diff --git a/tests/smoke/pages/login/ocis.ts b/tests/smoke/pages/login/ocis.ts new file mode 100644 index 00000000000..6ba01918717 --- /dev/null +++ b/tests/smoke/pages/login/ocis.ts @@ -0,0 +1,20 @@ +import { World } from '../../setup' +import { Page } from 'playwright' +import { User } from '../../types' + +/* eslint-disable-next-line */ +import { LoginAdapter } from './index' + +export class OcisLoginAdapter implements LoginAdapter { + private page: Page + + constructor(world: World) { + this.page = world.page + } + + async login({ user }: { user: User }): Promise { + await this.page.fill('#oc-login-username', user.id) + await this.page.fill('#oc-login-password', user.password) + await this.page.click('button[type="submit"]') + } +} diff --git a/tests/smoke/setup/config.ts b/tests/smoke/setup/config.ts index 331c28b001b..bb5c3be35f4 100644 --- a/tests/smoke/setup/config.ts +++ b/tests/smoke/setup/config.ts @@ -1,7 +1,7 @@ const withHttp = url => (/^https?:\/\//i.test(url) ? url : `http://${url}`) export const config = { - ocis: !!process.env.RUN_ON_OCIS, + ocis: process.env.OCIS === 'true', assets: './tests/acceptance/filesForUpload', slowMo: parseInt(process.env.SLOW_MO) || 0, headless: process.env.HEADLESS === 'true', diff --git a/tests/smoke/steps/app.files.ts b/tests/smoke/steps/app.files.ts index 32243ae7172..c6c8d7ac5d6 100644 --- a/tests/smoke/steps/app.files.ts +++ b/tests/smoke/steps/app.files.ts @@ -1,93 +1,90 @@ -import {DataTable, Given, When} from '@cucumber/cucumber' -import {World} from '../setup' -import {FilesPage} from '../pages' -import {fixtures} from '../helpers' -import {expect} from '@playwright/test' +import { DataTable, Given, When } from '@cucumber/cucumber' +import { World } from '../setup' +import { FilesPage } from '../pages' +import { fixtures } from '../helpers' +import { expect } from '@playwright/test' -When('he/she navigates to the files page', async function (this: World): Promise { - const {allFiles: allFilesPage} = new FilesPage(this) +When('he/she navigates to the files page', async function(this: World): Promise { + const { allFiles: allFilesPage } = new FilesPage(this) - await allFilesPage.navigate() + await allFilesPage.navigate() }) -When('he/she creates following folder(s)', async function ( - this: World, - stepTable: DataTable +When('he/she creates following folder(s)', async function( + this: World, + stepTable: DataTable ): Promise { - const {allFiles: allFilesPage} = new FilesPage(this) - const folders = stepTable.raw().map(f => f[0]) + const { allFiles: allFilesPage } = new FilesPage(this) + const folders = stepTable.raw().map(f => f[0]) - for (const folder of folders) { - await allFilesPage.createFolder({name: folder}) - } + for (const folder of folders) { + await allFilesPage.createFolder({ name: folder }) + } }) -When('he/she uploads following resource(s)', async function ( - this: World, - stepTable: DataTable +When('he/she uploads following resource(s)', async function( + this: World, + stepTable: DataTable ): Promise { - const {allFiles: allFilesPage} = new FilesPage(this) - const uploadInfo = stepTable.hashes().reduce((acc, stepRow) => { - const {to, resource} = stepRow + const { allFiles: allFilesPage } = new FilesPage(this) + const uploadInfo = stepTable.hashes().reduce((acc, stepRow) => { + const { to, resource } = stepRow - if (!acc[to]) { - acc[to] = [] - } + if (!acc[to]) { + acc[to] = [] + } - acc[to].push(fixtures.Files.get({name: resource})) + acc[to].push(fixtures.Files.get({ name: resource })) - return acc - }, {}) + return acc + }, {}) - for (const folder of Object.keys(uploadInfo)) { - await allFilesPage.uploadFiles({folder, files: uploadInfo[folder]}) - } + for (const folder of Object.keys(uploadInfo)) { + await allFilesPage.uploadFiles({ folder, files: uploadInfo[folder] }) + } }) -When('he/she shares following resource(s)', async function ( - this: World, - stepTable: DataTable -) { - const {allFiles: allFilesPage} = new FilesPage(this) +When('he/she shares following resource(s)', async function(this: World, stepTable: DataTable) { + const { allFiles: allFilesPage } = new FilesPage(this) - const shareInfo = stepTable.hashes().reduce((acc, stepRow) => { - const {user, resource} = stepRow + const shareInfo = stepTable.hashes().reduce((acc, stepRow) => { + const { user, resource } = stepRow - if (!acc[resource]) { - acc[resource] = [] - } + if (!acc[resource]) { + acc[resource] = [] + } - acc[resource].push(fixtures.Users.get({id: user})) + acc[resource].push(fixtures.Users.get({ id: user })) - return acc - }, {}) + return acc + }, {}) - for (const folder of Object.keys(shareInfo)) { - await allFilesPage.shareFolder({folder, users: shareInfo[folder]}) - } + for (const folder of Object.keys(shareInfo)) { + await allFilesPage.shareFolder({ folder, users: shareInfo[folder] }) + } }) -Given('he/she downloads following files', async function (this: World, stepTable: DataTable) { - const {allFiles: allFilesPage} = new FilesPage(this) - const downloadInfo = stepTable.hashes().reduce((acc, stepRow) => { - const {resource, from} = stepRow +Given('he/she downloads following files', async function(this: World, stepTable: DataTable) { + const { allFiles: allFilesPage } = new FilesPage(this) + const downloadInfo = stepTable.hashes().reduce((acc, stepRow) => { + const { resource, from } = stepRow - if (!acc[from]) { - acc[from] = [] - } + if (!acc[from]) { + acc[from] = [] + } - acc[from].push(resource) + acc[from].push(resource) - return acc - }, {}) + return acc + }, {}) - for (const folder of Object.keys(downloadInfo)) { - const files = downloadInfo[folder] - const downloads = await allFilesPage.downloadFiles({folder, names: files}) + for (const folder of Object.keys(downloadInfo)) { + const files = downloadInfo[folder] + const downloads = await allFilesPage.downloadFiles({ folder, names: files }) - expect(files.length).toBe(downloads.length) - downloads.forEach(download => { - expect(files).toContain(download.suggestedFilename()) - }) - } + expect(files.length).toBe(downloads.length) + downloads.forEach(download => { + expect(files).toContain(download.suggestedFilename()) + }) + } }) diff --git a/tests/smoke/steps/login.ts b/tests/smoke/steps/login.ts index eaa5a627ddf..ac2e6340b66 100644 --- a/tests/smoke/steps/login.ts +++ b/tests/smoke/steps/login.ts @@ -1,15 +1,13 @@ import { Given } from '@cucumber/cucumber' import { config, World } from '../setup' import { fixtures } from '../helpers' -import { AuthorizePage, LoginPage } from '../pages' +import { LoginPage } from '../pages' Given('user {string} has logged in', async function(this: World, stepUser: string): Promise { const { page } = this const user = fixtures.Users.get({ id: stepUser }) const loginPage = new LoginPage(this) - const authorizePage = new AuthorizePage(this) await page.goto(config.frontendUrl) await loginPage.login({ user }) - await authorizePage.authorize() })