55 *
66 * Copyright Oxide Computer Company
77 */
8- import { clickRowAction , expect , test } from './utils'
8+ import { expect , test , type Page } from '@playwright/test'
9+
10+ import { clickRowAction } from './utils'
911
1012test ( 'serial console can connect while starting' , async ( { page } ) => {
1113 // create an instance
@@ -29,11 +31,10 @@ test('serial console can connect while starting', async ({ page }) => {
2931 await expect ( page . getByText ( 'The instance is starting' ) ) . toBeVisible ( )
3032 await expect ( page . getByText ( 'The instance is' ) ) . toBeHidden ( )
3133
32- // Here it would be nice to test that the serial console connects, but we
33- // can't mock websockets with MSW yet: https://github.com/mswjs/msw/pull/2011
34+ await testSerialConsole ( page )
3435} )
3536
36- test ( 'links in instance actions ' , async ( { page } ) => {
37+ test ( 'serial console for existing instance ' , async ( { page } ) => {
3738 await page . goto ( '/projects/mock-project/instances' )
3839 await clickRowAction ( page , 'db1' , 'View serial console' )
3940 await expect ( page ) . toHaveURL ( '/projects/mock-project/instances/db1/serial-console' )
@@ -42,4 +43,23 @@ test('links in instance actions', async ({ page }) => {
4243 await page . getByRole ( 'button' , { name : 'Instance actions' } ) . click ( )
4344 await page . getByRole ( 'menuitem' , { name : 'View serial console' } ) . click ( )
4445 await expect ( page ) . toHaveURL ( '/projects/mock-project/instances/db1/serial-console' )
46+
47+ await testSerialConsole ( page )
4548} )
49+
50+ async function testSerialConsole ( page : Page ) {
51+ const xterm = page . getByRole ( 'application' )
52+
53+ // MSW mocks a message. use first() because there are multiple copies on screen
54+ await expect ( xterm . getByText ( 'Wake up Neo...' ) . first ( ) ) . toBeVisible ( )
55+
56+ // we need to do this for our keypresses to land
57+ await page . locator ( '.xterm-helper-textarea' ) . focus ( )
58+
59+ await xterm . pressSequentially ( 'abc' )
60+ await expect ( xterm . getByText ( 'Wake up Neo...abc' ) . first ( ) ) . toBeVisible ( )
61+ await xterm . press ( 'Enter' )
62+ await xterm . pressSequentially ( 'def' )
63+ await expect ( xterm . getByText ( 'Wake up Neo...abc' ) . first ( ) ) . toBeVisible ( )
64+ await expect ( xterm . getByText ( 'def' ) . first ( ) ) . toBeVisible ( )
65+ }
0 commit comments