Skip to content

Commit

Permalink
feat: add create workspace test
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlewind committed May 21, 2024
1 parent c376be4 commit 8f94fdb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
"dev:web": "pnpm --filter @notesuite/client dev & pnpm --filter @notesuite/common dev",
"dev:server": "pnpm --filter @notesuite/server start",
"dev:client": "pnpm --filter @notesuite/client tauri dev & pnpm --filter @notesuite/common dev",
"test": "playwright test",
"test:frontend1": "VITE_PORT=5174 BACKEND_URL=localhost:3001 pnpm dev:web",
"test:frontend2": "VITE_PORT=5175 BACKEND_URL=localhost:3002 pnpm dev:web",
"test": "playwright test --debug",
"test:clean": "pnpm clean && pnpm test",
"clean": "pnpm --filter @notesuite/server clean"
},
"devDependencies": {
Expand Down
29 changes: 17 additions & 12 deletions tests/basic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@ import { TestAgent } from './common/agent.js';

test.describe('basic test', () => {
const agent = new TestAgent();

test.beforeAll(() =>
agent.start({
name: 'test-basic',
webPort: 5173,
backendPort: 3000,
})
);
const options = {
name: 'test-basic',
webPort: 5173,
backendPort: 3000,
};
test.beforeAll(() => agent.start(options));

test('local server works', async ({ page }) => {
await page.goto('http://localhost:5173');
const title = await page.title();
expect(title).toBe('Note App');
await page.goto(agent.web.baseUrl);
expect(await page.title()).toBe('Note App');
});

test('can crete workspace', async ({ page }) => {
await page.goto(agent.web.baseUrl);
await page.getByPlaceholder('Workspace name').click();
await page.getByPlaceholder('Workspace name').fill('hello');
await page.getByRole('button', { name: 'Create' }).click();
await expect(page.getByText('Test Client')).toBeVisible();
});

test.afterAll(async () => await agent.stop());
test.afterAll(() => agent.stop());
});
21 changes: 21 additions & 0 deletions tests/common/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,31 @@ interface StartOptions {
backendPort: number;
}

class WebAgentInterface {
constructor(private agent: TestAgent) {}

get baseUrl() {
return `http://localhost:${this.agent.options.webPort}`;
}
}

class MockAgentInterface {
constructor(private agent: TestAgent) {}
}

export class TestAgent {
runner = new AppRunner();
web = new WebAgentInterface(this);
mock = new MockAgentInterface(this);

options = {
name: '',
webPort: 0,
backendPort: 0,
};

async start(options: StartOptions) {
this.options = options;
await Promise.all([
this.runner.startServer(options.backendPort, options.name),
this.runner.startWeb(options.webPort, options.backendPort),
Expand Down

0 comments on commit 8f94fdb

Please sign in to comment.