Skip to content
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: 1 addition & 1 deletion packages/extension/scripts/test-e2e-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ function cleanup() {
# Ensure we always close the server
trap cleanup EXIT

yarn test:e2e
yarn test:e2e "$@"
40 changes: 0 additions & 40 deletions packages/extension/test/e2e/control-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,46 +223,6 @@ test.describe('Control Panel', () => {
await popupPage.click('button:text("Control Panel")');
});

test('should send a message to a vat', async () => {
const clearLogsButton = popupPage.locator(
'[data-testid="clear-logs-button"]',
);
await clearLogsButton.click();
await popupPage.click('button:text("Object Registry")');
await expect(popupPage.locator('#root')).toContainText(
'Alice (v1) - 3 objects, 3 promises',
);
const targetSelect = popupPage.locator('[data-testid="message-target"]');
await expect(targetSelect).toBeVisible();
const options = targetSelect.locator('option:not([value=""])');
await expect(options).toHaveCount(await options.count());
expect(await options.count()).toBeGreaterThan(0);
await targetSelect.selectOption({ index: 1 });
await expect(targetSelect).not.toHaveValue('');
const methodInput = popupPage.locator('[data-testid="message-method"]');
await expect(methodInput).toHaveValue('__getMethodNames__');
const paramsInput = popupPage.locator('[data-testid="message-params"]');
await expect(paramsInput).toHaveValue('[]');
await popupPage.click('[data-testid="message-send-button"]');
const messageResponse = popupPage.locator(
'[data-testid="message-response"]',
);
await expect(messageResponse).toBeVisible();
await expect(messageResponse).toContainText(
'"body":"#[\\"__getMethodNames__\\",\\"bootstrap\\",\\"hello\\"]"',
);
await expect(messageResponse).toContainText('"slots":[]');
await clearLogsButton.click();
await methodInput.fill('hello');
await paramsInput.fill('[]');
await popupPage.click('[data-testid="message-send-button"]');
await expect(messageResponse).toContainText('"body":"#\\"vat Alice got');
await expect(messageResponse).toContainText('"slots":[');
await expect(popupPage.locator('#root')).toContainText(
'Alice (v1) - 3 objects, 5 promises',
);
});

test('should reload kernel state and load default vats', async () => {
test.slow();
await expect(
Expand Down
83 changes: 83 additions & 0 deletions packages/extension/test/e2e/object-registry.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { test, expect } from '@playwright/test';
import type { Page, BrowserContext } from '@playwright/test';

import {
revokeObject,
sendMessage,
openObjectRegistryTab,
} from './object-registry.ts';
import { makeLoadExtension } from '../helpers/extension.ts';

test.describe.configure({ mode: 'serial' });

test.describe('Object Registry', () => {
let extensionContext: BrowserContext;
let popupPage: Page;

test.beforeEach(async () => {
const extension = await makeLoadExtension();
extensionContext = extension.browserContext;
popupPage = extension.popupPage;
await openObjectRegistryTab(popupPage, expect);
});

test.afterEach(async () => {
await extensionContext.close();
});

test('should send a message to an object', async () => {
const clearLogsButton = popupPage.locator(
'[data-testid="clear-logs-button"]',
);
await clearLogsButton.click();
await popupPage.click('button:text("Object Registry")');
await expect(popupPage.locator('#root')).toContainText(
'Alice (v1) - 3 objects, 3 promises',
);
const targetSelect = popupPage.locator('[data-testid="message-target"]');
await expect(targetSelect).toBeVisible();
const options = targetSelect.locator('option:not([value=""])');
await expect(options).toHaveCount(await options.count());
expect(await options.count()).toBeGreaterThan(0);
await targetSelect.selectOption({ index: 1 });
await expect(targetSelect).not.toHaveValue('');
const methodInput = popupPage.locator('[data-testid="message-method"]');
await expect(methodInput).toHaveValue('__getMethodNames__');
const paramsInput = popupPage.locator('[data-testid="message-params"]');
await expect(paramsInput).toHaveValue('[]');
await popupPage.click('[data-testid="message-send-button"]');
const messageResponse = popupPage.locator(
'[data-testid="message-response"]',
);
await expect(messageResponse).toBeVisible();
await expect(messageResponse).toContainText(
'"body":"#[\\"__getMethodNames__\\",\\"bootstrap\\",\\"hello\\"]"',
);
await expect(messageResponse).toContainText('"slots":[]');
await clearLogsButton.click();
await methodInput.fill('hello');
await paramsInput.fill('[]');
await popupPage.click('[data-testid="message-send-button"]');
await expect(messageResponse).toContainText('"body":"#\\"vat Alice got');
await expect(messageResponse).toContainText('"slots":[');
await expect(popupPage.locator('#root')).toContainText(
'Alice (v1) - 3 objects, 5 promises',
);
});

test('should revoke an object', async () => {
const owner = 'v1';
const [target, method, params] = ['ko1', 'hello', '["Bob"]'];

// Before revoking, we should be able to send a message to the object
let response = await sendMessage(popupPage, target, method, params);
await expect(response).toContainText(/body(.+):(.+)hello(.+)from(.+)Bob/u);

response = await revokeObject(popupPage, owner, target);
await expect(response).toContainText(`Revoked object ${target}`);

// After revoking, the previously successful message should fail
response = await sendMessage(popupPage, target, method, params);
await expect(response).toContainText(/[Rr]evoked object/u);
});
});
36 changes: 36 additions & 0 deletions packages/extension/test/e2e/object-registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Page, Expect } from 'playwright/test';

export const openObjectRegistryTab = async (
page: Page,
expect?: Expect,
): Promise<void> => {
await page.click('button:text("Object Registry")');
await expect?.(page.locator('#root')).toContainText('Object Registry');
};

export const sendMessage = async (
page: Page,
target: string,
method: string,
params: string,
) => {
await page
.locator('select[data-testid="message-target"]')
.selectOption(target);
await page.locator('input[data-testid="message-method"]').fill(method);
await page.locator('input[data-testid="message-params"]').fill(params);
await page.locator('button:text("Send")').click();
return page.locator('[data-testid="message-response"]');
};

export const revokeObject = async (
page: Page,
owner: string,
target: string,
) => {
await page
.locator(`.accordion-header:has(.accordion-title:text("${owner}"))`)
.click();
await page.locator(`[data-testid="revoke-button-${target}"]`).click();
return page.locator('[data-testid="message-output"]');
};
Loading