|
| 1 | +import { test, expect } from '@playwright/test'; |
| 2 | +import type { Page, BrowserContext } from '@playwright/test'; |
| 3 | + |
| 4 | +import { |
| 5 | + revokeObject, |
| 6 | + sendMessage, |
| 7 | + openObjectRegistryTab, |
| 8 | +} from './object-registry.ts'; |
| 9 | +import { makeLoadExtension } from '../helpers/extension.ts'; |
| 10 | + |
| 11 | +test.describe.configure({ mode: 'serial' }); |
| 12 | + |
| 13 | +test.describe('Object Registry', () => { |
| 14 | + let extensionContext: BrowserContext; |
| 15 | + let popupPage: Page; |
| 16 | + |
| 17 | + test.beforeEach(async () => { |
| 18 | + const extension = await makeLoadExtension(); |
| 19 | + extensionContext = extension.browserContext; |
| 20 | + popupPage = extension.popupPage; |
| 21 | + await openObjectRegistryTab(popupPage, expect); |
| 22 | + }); |
| 23 | + |
| 24 | + test.afterEach(async () => { |
| 25 | + await extensionContext.close(); |
| 26 | + }); |
| 27 | + |
| 28 | + test('should send a message to an object', async () => { |
| 29 | + const clearLogsButton = popupPage.locator( |
| 30 | + '[data-testid="clear-logs-button"]', |
| 31 | + ); |
| 32 | + await clearLogsButton.click(); |
| 33 | + await popupPage.click('button:text("Object Registry")'); |
| 34 | + await expect(popupPage.locator('#root')).toContainText( |
| 35 | + 'Alice (v1) - 3 objects, 3 promises', |
| 36 | + ); |
| 37 | + const targetSelect = popupPage.locator('[data-testid="message-target"]'); |
| 38 | + await expect(targetSelect).toBeVisible(); |
| 39 | + const options = targetSelect.locator('option:not([value=""])'); |
| 40 | + await expect(options).toHaveCount(await options.count()); |
| 41 | + expect(await options.count()).toBeGreaterThan(0); |
| 42 | + await targetSelect.selectOption({ index: 1 }); |
| 43 | + await expect(targetSelect).not.toHaveValue(''); |
| 44 | + const methodInput = popupPage.locator('[data-testid="message-method"]'); |
| 45 | + await expect(methodInput).toHaveValue('__getMethodNames__'); |
| 46 | + const paramsInput = popupPage.locator('[data-testid="message-params"]'); |
| 47 | + await expect(paramsInput).toHaveValue('[]'); |
| 48 | + await popupPage.click('[data-testid="message-send-button"]'); |
| 49 | + const messageResponse = popupPage.locator( |
| 50 | + '[data-testid="message-response"]', |
| 51 | + ); |
| 52 | + await expect(messageResponse).toBeVisible(); |
| 53 | + await expect(messageResponse).toContainText( |
| 54 | + '"body":"#[\\"__getMethodNames__\\",\\"bootstrap\\",\\"hello\\"]"', |
| 55 | + ); |
| 56 | + await expect(messageResponse).toContainText('"slots":[]'); |
| 57 | + await clearLogsButton.click(); |
| 58 | + await methodInput.fill('hello'); |
| 59 | + await paramsInput.fill('[]'); |
| 60 | + await popupPage.click('[data-testid="message-send-button"]'); |
| 61 | + await expect(messageResponse).toContainText('"body":"#\\"vat Alice got'); |
| 62 | + await expect(messageResponse).toContainText('"slots":['); |
| 63 | + await expect(popupPage.locator('#root')).toContainText( |
| 64 | + 'Alice (v1) - 3 objects, 5 promises', |
| 65 | + ); |
| 66 | + }); |
| 67 | + |
| 68 | + test('should revoke an object', async () => { |
| 69 | + const owner = 'v1'; |
| 70 | + const [target, method, params] = ['ko1', 'hello', '["Bob"]']; |
| 71 | + |
| 72 | + // Before revoking, we should be able to send a message to the object |
| 73 | + let response = await sendMessage(popupPage, target, method, params); |
| 74 | + await expect(response).toContainText(/body(.+):(.+)hello(.+)from(.+)Bob/u); |
| 75 | + |
| 76 | + response = await revokeObject(popupPage, owner, target); |
| 77 | + await expect(response).toContainText(`Revoked object ${target}`); |
| 78 | + |
| 79 | + // After revoking, the previously successful message should fail |
| 80 | + response = await sendMessage(popupPage, target, method, params); |
| 81 | + await expect(response).toContainText(/[Rr]evoked object/u); |
| 82 | + }); |
| 83 | +}); |
0 commit comments