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

[test-only] extract zip test #109

Merged
merged 2 commits into from
Nov 29, 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
2 changes: 2 additions & 0 deletions .drone.star
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ APPS = [

E2E_COVERED_APPS = [
"draw-io",
"unzip",
]

OCIS_URL = "https://ocis:9200"
Expand Down Expand Up @@ -341,6 +342,7 @@ def ocisService():
"pnpm build",
"mkdir -p /apps",
"mv packages/web-app-draw-io/dist /apps/draw-io",
"mv packages/web-app-unzip/dist /apps/unzip",
],
"volumes": [
{
Expand Down
29 changes: 29 additions & 0 deletions packages/web-app-unzip/tests/e2e/extractZip.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { test, Page, expect } from '@playwright/test'
import { FilesAppBar } from '../../../../support/pages/filesAppBarActions'
import { FilesPage } from '../../../../support/pages/filesPage'
import { loginAsUser, logout } from '../../../../support/helpers/authHelper'

let adminPage: Page

test.beforeEach(async ({ browser }) => {
const admin = await loginAsUser(browser, 'admin', 'admin')
adminPage = admin.page
})

test.afterEach(async () => {
const file = new FilesPage(adminPage)
await file.deleteAllFromPersonal()
await logout(adminPage)
})

test('extract zip file', async () => {
const uploadFile = new FilesAppBar(adminPage)
await uploadFile.uploadFile('data.zip')

const file = new FilesPage(adminPage)
await file.extractZip('data.zip')

await file.openFolder('data')
await expect(adminPage.getByRole('button', { name: 'logo-wide .png' })).toBeVisible()
await expect(adminPage.getByRole('link', { name: 'lorem .txt' })).toBeVisible()
})
3 changes: 3 additions & 0 deletions packages/web-app-unzip/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@ export default defineConfig({
entryFileNames: 'unzip.js'
}
}
},
test: {
exclude: ['**/e2e/**']
}
})
30 changes: 15 additions & 15 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ export default defineConfig({
testDir: './packages/web-app-draw-io/tests/e2e',
use: { ...devices['Desktop Safari'], browserName: 'webkit', ignoreHTTPSErrors: true },
},
// {
// name: 'unzip-chromium',
// testDir: './packages/web-app-unzip/tests/e2e',
// use: { ...devices['Desktop Chrome'], browserName: 'chromium', ignoreHTTPSErrors: true },
// },
// {
// name: 'unzip-firefox',
// testDir: './packages/web-app-unzip/tests/e2e',
// use: { ...devices['Desktop Firefox'], browserName: 'firefox', ignoreHTTPSErrors: true },
// },
// {
// name: 'unzip-webkit',
// testDir: './packages/web-app-unzip/tests/e2e',
// use: { ...devices['Desktop Safari'], browserName: 'webkit', ignoreHTTPSErrors: true },
// },
{
name: 'unzip-chromium',
testDir: './packages/web-app-unzip/tests/e2e',
use: { ...devices['Desktop Chrome'], browserName: 'chromium', ignoreHTTPSErrors: true },
},
{
name: 'unzip-firefox',
testDir: './packages/web-app-unzip/tests/e2e',
use: { ...devices['Desktop Firefox'], browserName: 'firefox', ignoreHTTPSErrors: true },
},
{
name: 'unzip-webkit',
testDir: './packages/web-app-unzip/tests/e2e',
use: { ...devices['Desktop Safari'], browserName: 'webkit', ignoreHTTPSErrors: true },
},

/* Test against mobile viewports. */
// {
Expand Down
Binary file added support/filesForUpload/data.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion support/pages/appSwitcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locator, Page, expect } from '@playwright/test'
import { Locator, Page } from '@playwright/test'

export class AppSwitcher {
readonly page: Page
Expand Down
32 changes: 32 additions & 0 deletions support/pages/filesAppBarActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Locator, Page } from '@playwright/test'
import path from 'path'

export class FilesAppBar {
readonly page: Page
readonly uploadBtn: Locator
readonly uploadFileBtn: Locator

constructor(page: Page) {
this.page = page
this.uploadBtn = this.page.locator('#upload-menu-btn')
this.uploadFileBtn = this.page.locator('#files-file-upload-input')
}

async uploadFile(file: string) {
await this.uploadBtn.click()
const realPath = path.join('./support/filesForUpload', file)

let uploadAction: Promise<void> = this.uploadFileBtn.setInputFiles(path.resolve(realPath))

await Promise.all([
this.page.waitForResponse(
(resp) =>
[201, 204].includes(resp.status()) &&
['POST', 'PUT', 'PATCH'].includes(resp.request().method())
),
uploadAction
])
// close upload menu. Sometimes it hangs
await this.page.keyboard.press('Escape')
}
}
44 changes: 44 additions & 0 deletions support/pages/filesPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Locator, Page } from '@playwright/test'

export class FilesPage {
readonly page: Page
readonly uploadBtn: Locator
readonly extractHereBtnBtn: Locator
readonly selectAllCheckbox: Locator


constructor(page: Page) {
this.page = page
this.extractHereBtnBtn = this.page.locator('.context-menu .oc-files-actions-unzip-archive')
this.selectAllCheckbox = this.page.getByLabel('Select all')
}

getResourceNameSelector(resource: string): Locator {
return this.page.locator(`#files-space-table [data-test-resource-name="${resource}"]`);
}

async extractZip(file: string) {
const fileLocator = this.getResourceNameSelector(file)
await fileLocator.click({ button: 'right' })

await Promise.all([
this.page.waitForResponse(
(resp) =>
resp.status() === 201 &&
resp.request().method() === 'MKCOL'
),
this.extractHereBtnBtn.click()
])
}

async deleteAllFromPersonal() {
await this.page.getByRole('link', { name: 'Navigate to personal files' }).click();
await this.selectAllCheckbox.check();
await this.page.getByRole('button', { name: 'Delete' }).click()
}

async openFolder(folder: string) {
const folderLocator = this.getResourceNameSelector(folder)
await folderLocator.click()
}
}