5
5
*
6
6
* Copyright Oxide Computer Company
7
7
*/
8
- import { clickRowAction , expect , test } from './utils'
8
+ import { expect , test , type Page } from '@playwright/test'
9
+
10
+ import { clickRowAction } from './utils'
9
11
10
12
test ( 'serial console can connect while starting' , async ( { page } ) => {
11
13
// create an instance
@@ -29,11 +31,10 @@ test('serial console can connect while starting', async ({ page }) => {
29
31
await expect ( page . getByText ( 'The instance is starting' ) ) . toBeVisible ( )
30
32
await expect ( page . getByText ( 'The instance is' ) ) . toBeHidden ( )
31
33
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 )
34
35
} )
35
36
36
- test ( 'links in instance actions ' , async ( { page } ) => {
37
+ test ( 'serial console for existing instance ' , async ( { page } ) => {
37
38
await page . goto ( '/projects/mock-project/instances' )
38
39
await clickRowAction ( page , 'db1' , 'View serial console' )
39
40
await expect ( page ) . toHaveURL ( '/projects/mock-project/instances/db1/serial-console' )
@@ -42,4 +43,23 @@ test('links in instance actions', async ({ page }) => {
42
43
await page . getByRole ( 'button' , { name : 'Instance actions' } ) . click ( )
43
44
await page . getByRole ( 'menuitem' , { name : 'View serial console' } ) . click ( )
44
45
await expect ( page ) . toHaveURL ( '/projects/mock-project/instances/db1/serial-console' )
46
+
47
+ await testSerialConsole ( page )
45
48
} )
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