Browse Source

test(browsers): add devices CTA

pull/205/head
Nick Oliver 2 years ago
parent
commit
f0ab5ee4a8
  1. 1
      .gitattributes
  2. 4
      package.json
  3. 46
      playwright.config.ts
  4. 41
      tests/example.spec.ts

1
.gitattributes

@ -0,0 +1 @@
tests/**/*.png filter=lfs diff=lfs merge=lfs -text

4
package.json

@ -7,7 +7,9 @@
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite --host",
"build": "tsc && vite build", "build": "tsc && vite build",
"check": "biome check .", "test": "npm run test:static && npm run test:browsers",
"test:static": "biome check .",
"test:browsers": "playwright test",
"preview": "vite preview", "preview": "vite preview",
"package": "gzipper c -i html,js,css,png,ico,svg,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ $(ls ./dist/output/)" "package": "gzipper c -i html,js,css,png,ico,svg,webmanifest,txt dist dist/output && tar -cvf dist/build.tar -C ./dist/output/ $(ls ./dist/output/)"
}, },

46
playwright.config.ts

@ -1,16 +1,10 @@
import { defineConfig, devices } from '@playwright/test'; import { defineConfig, devices } from "@playwright/test";
/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();
/** /**
* See https://playwright.dev/docs/test-configuration. * See https://playwright.dev/docs/test-configuration.
*/ */
export default defineConfig({ export default defineConfig({
testDir: './tests', testDir: "./tests",
/* Run tests in files in parallel */ /* Run tests in files in parallel */
fullyParallel: true, fullyParallel: true,
/* Fail the build on CI if you accidentally left test.only in the source code. */ /* Fail the build on CI if you accidentally left test.only in the source code. */
@ -20,32 +14,32 @@ export default defineConfig({
/* Opt out of parallel tests on CI. */ /* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined, workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */ /* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html', reporter: "html",
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
use: { use: {
/* Base URL to use in actions like `await page.goto('/')`. */ /* Base URL to use in actions like `await page.goto('/')`. */
// baseURL: 'http://127.0.0.1:3000', baseURL: "http://127.0.0.1:5173",
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */ /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry', trace: "on-first-retry",
}, },
/* Configure projects for major browsers */ /* Configure projects for major browsers */
projects: [ projects: [
{ {
name: 'chromium', name: "chromium",
use: { ...devices['Desktop Chrome'] }, use: { ...devices["Desktop Chrome"] },
}, },
{ // {
name: 'firefox', // name: 'firefox',
use: { ...devices['Desktop Firefox'] }, // use: { ...devices['Desktop Firefox'] },
}, // },
{ // {
name: 'webkit', // name: 'webkit',
use: { ...devices['Desktop Safari'] }, // use: { ...devices['Desktop Safari'] },
}, // },
/* Test against mobile viewports. */ /* Test against mobile viewports. */
// { // {
@ -69,9 +63,9 @@ export default defineConfig({
], ],
/* Run your local dev server before starting the tests */ /* Run your local dev server before starting the tests */
// webServer: { webServer: {
// command: 'npm run start', command: "vite --host --port=5173",
// url: 'http://127.0.0.1:3000', url: "http://127.0.0.1:5173",
// reuseExistingServer: !process.env.CI, reuseExistingServer: !process.env.CI,
// }, },
}); });

41
tests/example.spec.ts

@ -1,18 +1,37 @@
import { test, expect } from '@playwright/test'; import { expect, test } from "@playwright/test";
test('has title', async ({ page }) => { test("Basic page load", async ({ page }) => {
await page.goto('https://playwright.dev/'); await page.goto("/");
await expect(page).toHaveTitle("Meshtastic Web");
});
test("Prompts adding a new connection as the call to action when there are no devices", async ({page}) => {
await page.goto("/");
await expect(page).toHaveScreenshot();
// Expect a title "to contain" a substring. await expect(page.getByRole("heading", { name: "No Devices" })).toBeVisible();
await expect(page).toHaveTitle(/Playwright/); await expect(page.getByRole("button", { name: "New Connection" })).toBeVisible();
}); });
test('get started link', async ({ page }) => { test("Shows the protocols as the first step of adding a device", async ({page}) => {
await page.goto('https://playwright.dev/'); await page.goto("/");
await page.getByRole("button", { name: "New Connection" }).click();
await expect(page.getByRole("heading", { name: "Connect New Device" })).toBeVisible();
await expect(page).toHaveScreenshot();
});
// Click the get started link. test("Requests the IP address or hostname as input when connecting over HTTP", async ({page}) => {
await page.getByRole('link', { name: 'Get started' }).click(); await page.goto("/");
await page.getByRole("button", { name: "New Connection" }).click();
await page.getByRole("tab", { name: "HTTP" }).click();
await expect(page.getByRole('dialog')).toHaveScreenshot('connect-over-http.png');
});
// Expects page to have a heading with the name of Installation. test("New Device button for the brower's dialog UI is presented when connecting over serial", async ({page}) => {
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible(); await page.goto("/");
await page.getByRole("button", { name: "New Connection" }).click();
await page.getByRole("tab", { name: "Serial" }).click();
await expect(page.getByRole("button", { name: "New Device" })).toBeVisible();
await expect(page.getByRole('dialog')).toHaveScreenshot('connect-over-serial.png');
}); });

Loading…
Cancel
Save