Add basic e2e tests

pull/37/head
Varun Patil 2022-09-14 11:18:57 -07:00
parent 8f5c4d061e
commit cc1f690e01
No known key found for this signature in database
GPG Key ID: 29719539C1CE9750
7 changed files with 321 additions and 65 deletions

3
.gitignore vendored
View File

@ -19,3 +19,6 @@ coverage/
.php_cs.cache
vendor
memories.tar.gz
/test-results/
/playwright-report/
/playwright/.cache/

View File

@ -0,0 +1,16 @@
import { test, expect } from '@playwright/test';
import { login } from './login';
test.beforeEach(login('/folders'));
test.describe('Open', () => {
test('Look for Folders', async ({ page }) => {
expect(await page.locator('.big-icon > .icon-folder').count(), 'Number of folders').toBeGreaterThan(3);
});
test('Open folder', async ({ page }) => {
await page.locator('text=Local').click();
await expect(page).toHaveURL(/http:\/\/localhost:8080\/apps\/memories\/folders\/\.*/);
await page.waitForSelector('img[src^="/core/preview"]');
});
});

16
e2e/login.ts 100644
View File

@ -0,0 +1,16 @@
import { expect, PlaywrightTestArgs } from '@playwright/test';
export function login(route: string) {
return async ({ page }: PlaywrightTestArgs) => {
await page.setViewportSize({ width: 800, height: 600 })
await page.goto('http://localhost:8080/apps/memories' + route)
await page.locator('[placeholder="Username or email"]').click();
await page.locator('[placeholder="Username or email"]').fill('admin');
await page.locator('[placeholder="Username or email"]').press('Tab');
await page.locator('[placeholder="Password"]').fill('admin');
await page.locator('input:has-text("Log in")').click();
await expect(page).toHaveURL('http://localhost:8080/apps/memories' + route);
await page.waitForSelector('img[src^="/core/preview"]');
}
}

View File

@ -0,0 +1,43 @@
import { test, expect } from '@playwright/test';
import { login } from './login';
test.beforeEach(login('/'));
test.describe('Open', () => {
test('Look for Images', async ({ page }) => {
expect(await page.locator('img[src^="/core/preview"]').count(), 'Number of previews').toBeGreaterThan(4);
await page.waitForTimeout(1000);
});
test('Open one image', async ({ page }) => {
await page.locator('div:nth-child(2) > .p-outer > .img-outer > img').first().click();
await page.waitForTimeout(1000);
await page.locator('button:has-text("Close")').first().click();
});
test('Select two images and delete', async ({ page }) => {
const i1 = "div:nth-child(3) > .photo-row > div:nth-child(2) > .p-outer";
const i2 = "div:nth-child(3) > .photo-row > div:nth-child(3) > .p-outer";
const src1 = await page.locator(`${i1} > .img-outer > img`).first().getAttribute('src');
const src2 = await page.locator(`${i2} > .img-outer > img`).first().getAttribute('src');
expect(await page.locator(`img[src="${src1}"]`).count()).toBe(1);
expect(await page.locator(`img[src="${src2}"]`).count()).toBe(1);
await page.locator(`${i1} > .icon-checkmark`).click();
await page.locator(`${i2}`).click();
await page.waitForTimeout(1000);
await page.locator('[aria-label="Delete selection"]').click();
await page.waitForTimeout(4000);
expect(await page.locator(`img[src="${src1}"]`).count()).toBe(0);
expect(await page.locator(`img[src="${src2}"]`).count()).toBe(0);
// refresh page
await page.reload();
await page.waitForSelector('img[src^="/core/preview"]');
expect(await page.locator(`img[src="${src1}"]`).count()).toBe(0);
expect(await page.locator(`img[src="${src2}"]`).count()).toBe(0);
});
});

77
package-lock.json generated
View File

@ -26,7 +26,9 @@
"@nextcloud/eslint-config": "^8.1.2",
"@nextcloud/stylelint-config": "^2.2.0",
"@nextcloud/webpack-vue-config": "^5.3.0",
"@playwright/test": "^1.25.2",
"@types/url-parse": "^1.4.8",
"playwright": "^1.25.2",
"ts-loader": "^9.3.1",
"typescript": "^4.8.3"
},
@ -2372,6 +2374,22 @@
"node": ">= 8"
}
},
"node_modules/@playwright/test": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.25.2.tgz",
"integrity": "sha512-6qPznIR4Fw02OMbqXUPMG6bFFg1hDVNEdihKy0t9K0dmRbus1DyP5Q5XFQhGwEHQkLG5hrSfBuu9CW/foqhQHQ==",
"dev": true,
"dependencies": {
"@types/node": "*",
"playwright-core": "1.25.2"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
@ -2515,8 +2533,7 @@
"version": "18.7.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.3.tgz",
"integrity": "sha512-LJgzOEwWuMTBxHzgBR/fhhBOWrvBjvO+zPteUgbbuQi80rYIZHrk1mNbRUqPZqSLP2H7Rwt1EFLL/tNLD1Xx/w==",
"dev": true,
"peer": true
"dev": true
},
"node_modules/@types/normalize-package-data": {
"version": "2.4.1",
@ -8507,6 +8524,34 @@
"node": ">=8"
}
},
"node_modules/playwright": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.25.2.tgz",
"integrity": "sha512-RwMB5SFRV/8wSfK+tK8ycpqdzORvoqUNz9DUeRfSgZFrZej5uuBl9wFjWcc+OkXFEtaPmx1acAVGG7hA4IJ1kg==",
"dev": true,
"hasInstallScript": true,
"dependencies": {
"playwright-core": "1.25.2"
},
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/playwright-core": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.25.2.tgz",
"integrity": "sha512-0yTbUE9lIddkEpLHL3u8PoCL+pWiZtj5A/j3U7YoNjcmKKDGBnCrgHJMzwd2J5vy6l28q4ki3JIuz7McLHhl1A==",
"dev": true,
"bin": {
"playwright": "cli.js"
},
"engines": {
"node": ">=14"
}
},
"node_modules/postcss": {
"version": "8.4.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz",
@ -13669,6 +13714,16 @@
"fastq": "^1.6.0"
}
},
"@playwright/test": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.25.2.tgz",
"integrity": "sha512-6qPznIR4Fw02OMbqXUPMG6bFFg1hDVNEdihKy0t9K0dmRbus1DyP5Q5XFQhGwEHQkLG5hrSfBuu9CW/foqhQHQ==",
"dev": true,
"requires": {
"@types/node": "*",
"playwright-core": "1.25.2"
}
},
"@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
@ -13812,8 +13867,7 @@
"version": "18.7.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.3.tgz",
"integrity": "sha512-LJgzOEwWuMTBxHzgBR/fhhBOWrvBjvO+zPteUgbbuQi80rYIZHrk1mNbRUqPZqSLP2H7Rwt1EFLL/tNLD1Xx/w==",
"dev": true,
"peer": true
"dev": true
},
"@types/normalize-package-data": {
"version": "2.4.1",
@ -18490,6 +18544,21 @@
}
}
},
"playwright": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.25.2.tgz",
"integrity": "sha512-RwMB5SFRV/8wSfK+tK8ycpqdzORvoqUNz9DUeRfSgZFrZej5uuBl9wFjWcc+OkXFEtaPmx1acAVGG7hA4IJ1kg==",
"dev": true,
"requires": {
"playwright-core": "1.25.2"
}
},
"playwright-core": {
"version": "1.25.2",
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.25.2.tgz",
"integrity": "sha512-0yTbUE9lIddkEpLHL3u8PoCL+pWiZtj5A/j3U7YoNjcmKKDGBnCrgHJMzwd2J5vy6l28q4ki3JIuz7McLHhl1A==",
"dev": true
},
"postcss": {
"version": "8.4.16",
"resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.16.tgz",

View File

@ -56,7 +56,9 @@
"@nextcloud/eslint-config": "^8.1.2",
"@nextcloud/stylelint-config": "^2.2.0",
"@nextcloud/webpack-vue-config": "^5.3.0",
"@playwright/test": "^1.25.2",
"@types/url-parse": "^1.4.8",
"playwright": "^1.25.2",
"ts-loader": "^9.3.1",
"typescript": "^4.8.3"
}

View File

@ -0,0 +1,107 @@
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/**
* See https://playwright.dev/docs/test-configuration.
*/
const config: PlaywrightTestConfig = {
testDir: './e2e',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
expect: {
/**
* Maximum time expect() should wait for the condition to be met.
* For example in `await expect(locator).toHaveText();`
*/
timeout: 5000
},
/* Run tests in files in parallel */
fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */
forbidOnly: !!process.env.CI,
/* Retry on CI only */
retries: process.env.CI ? 2 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: {
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
actionTimeout: 0,
/* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://localhost:3000',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Configure projects for major browsers */
projects: [
{
name: 'chromium',
use: {
...devices['Desktop Chrome'],
},
},
// {
// name: 'firefox',
// use: {
// ...devices['Desktop Firefox'],
// },
// },
// {
// name: 'webkit',
// use: {
// ...devices['Desktop Safari'],
// },
// },
/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: {
// ...devices['Pixel 5'],
// },
// },
// {
// name: 'Mobile Safari',
// use: {
// ...devices['iPhone 12'],
// },
// },
/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: {
// channel: 'msedge',
// },
// },
// {
// name: 'Google Chrome',
// use: {
// channel: 'chrome',
// },
// },
],
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
// outputDir: 'test-results/',
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// port: 3000,
// },
};
export default config;