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(ui): ensure title and connect wallet button render #57

Merged
merged 4 commits into from
Jan 25, 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 .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ jobs:
run: yarn build
- name: yarn test
run: yarn test
- name: yarn test:e2e
run: yarn test:e2e
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"resolutions-note": "work-around for https://github.com/Agoric/agoric-sdk/issues/8621",
"resolutions": {
"ses": "0.18.5",
"ses": "0.18.8",
"@endo/bundle-source": "2.5.2-upstream-rollup",
"@endo/captp": "3.1.1",
"@endo/compartment-mapper": "0.8.4",
Expand Down Expand Up @@ -46,6 +46,7 @@
"start:ui": "cd ui && yarn dev",
"lint": "yarn workspaces run lint",
"test": "yarn workspaces run test",
"test:e2e": "yarn workspace offer-up-ui test:e2e",
"build": "yarn workspaces run build"
}
}
9 changes: 7 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "exit 0",
"test": "vitest spec",
"test:e2e": "vitest e2e",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint:fix": "yarn lint --fix",
"preview": "vite preview"
Expand All @@ -18,10 +19,11 @@
"devDependencies": {
"@agoric/eventual-send": "^0.14.1",
"@agoric/notifier": "^0.6.2",
"@agoric/rpc": "^0.6.0",
"@agoric/rpc": "0.9.1-dev-f471a83.0",
"@agoric/store": "^0.9.2",
"@agoric/ui-components": "^0.9.0",
"@agoric/web-components": "0.12.0",
"@testing-library/react": "^14.1.2",
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand All @@ -32,10 +34,13 @@
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"happy-dom": "^13.3.1",
"prettier": "^3.2.4",
"puppeteer": "^21.9.0",
Copy link
Member

Choose a reason for hiding this comment

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

hm. Let's not forget that dapp-offer-up is supposed to be simple. I'm a little afraid that readers are going to get overwhelmed by some of this stuff. On the other hand, it's the only sane way to be sure we're not breaking things.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good points. In d3b726c I moved the test to /test so it's less prominent. Also have it only running on yarn test:e2e, instead of yarn test.

Maybe this sort of test is best for a react-scripts-esque library that this eventually depends on.

"ses": "^0.18.8",
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vitest": "^1.2.1",
"zustand": "^4.4.1"
},
"resolutions": {
Expand Down
22 changes: 22 additions & 0 deletions ui/src/App.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import './installSesLockdown';
import { render, screen } from '@testing-library/react';
import App from './App';

describe('App.tsx', () => {
it('renders app title', async () => {
render(<App />);

const titleElement = await screen.findByText('Items Listed on Offer Up', {
selector: 'h1',
});
expect(titleElement).toBeTruthy();
});

it('renders the wallet connection button', async () => {
render(<App />);
const buttonEl = await screen.findByRole('button', {
name: 'Connect Wallet',
});
expect(buttonEl).toBeTruthy();
});
});
28 changes: 28 additions & 0 deletions ui/test/App.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import puppeteer from 'puppeteer';
import { execSync, spawn } from 'node:child_process';

describe('Puppeteer E2E test', () => {
it('should load the webpage', async () => {
execSync('yarn build');
const previewServer = spawn('yarn', ['preview'], {
detached: true,
stdio: 'ignore',
});
// delay for preview server to start
await new Promise(resolve => setTimeout(resolve, 2000));

try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:4173');

const buttonText = await page.$eval('button', el => el.textContent);
expect(buttonText).toBe('Connect Wallet');

await browser.close();
previewServer.kill();
} catch (_) {
previewServer.kill();
}
});
});
8 changes: 5 additions & 3 deletions ui/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
"noFallthroughCasesInSwitch": true,

"types": ["vitest/globals"],
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
"include": ["src", "test"],
"references": [{ "path": "./tsconfig.node.json" }],
}
9 changes: 9 additions & 0 deletions ui/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
test: {
globals: true,
environment: 'happy-dom',
testTimeout: 20000, // 20 seconds for puppeteer CI
// modified import('vitest/dist/config.js').defaultInclude
include: '**/*.{spec,e2e}.?(c|m)[jt]s?(x)',
},
});
Loading
Loading