@@ -14,15 +14,13 @@ import {
1414import { describeWithEnvironment } from '../../testing/EnvironmentHelpers.js' ;
1515import { expectCall } from '../../testing/ExpectStubCall.js' ;
1616import * as Menus from '../../ui/components/menus/menus.js' ;
17- import * as RenderCoordinator from '../../ui/components/render_coordinator/render_coordinator.js' ;
1817import type * as SuggestionInput from '../../ui/components/suggestion_input/suggestion_input.js' ;
19- import * as UI from '../../ui/legacy/legacy.js' ;
2018
2119import * as ProtocolMonitor from './protocol_monitor.js' ;
2220
2321describeWithEnvironment ( 'JSONEditor' , ( ) => {
2422 const renderJSONEditor = ( ) => {
25- const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( new Map ( ) , new Map ( ) , new Map ( ) ) ;
23+ const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( document . createElement ( 'div' ) ) ;
2624 jsonEditor . markAsRoot ( ) ;
2725 jsonEditor . show ( renderElementIntoDOM ( document . createElement ( 'main' ) ) ) ;
2826 return jsonEditor ;
@@ -479,8 +477,7 @@ describeWithEnvironment('JSONEditor', () => {
479477
480478 describe ( 'Display command written in editor inside input bar' , ( ) => {
481479 it ( 'should display the command edited inside the CDP editor into the input bar' , async ( ) => {
482- const split = new UI . SplitWidget . SplitWidget ( true , false , 'protocol-monitor-split-container' , 400 ) ;
483- const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( new Map ( ) , new Map ( ) , new Map ( ) ) ;
480+ const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( document . createElement ( 'div' ) ) ;
484481 jsonEditor . command = 'Test.test' ;
485482 jsonEditor . parameters = [
486483 {
@@ -491,36 +488,31 @@ describeWithEnvironment('JSONEditor', () => {
491488 value : 'test' ,
492489 } ,
493490 ] ;
494- const dataGrid = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorDataGrid ( split ) ;
495- split . setMainWidget ( dataGrid ) ;
496- split . setSidebarWidget ( jsonEditor ) ;
497- split . toggleSidebar ( ) ;
498- split . markAsRoot ( ) ;
499- split . show ( renderElementIntoDOM ( document . createElement ( 'main' ) ) ) ;
500- await RenderCoordinator . done ( ) ;
501-
502- const toolbarInput =
503- dataGrid . element . shadowRoot ! . querySelector ( '.protocol-monitor-bottom-toolbar' ) ! . querySelector (
504- '.toolbar-input-prompt' ) ;
505- assert . deepEqual ( toolbarInput ! . innerHTML , '{"command":"Test.test","parameters":{"test":"test"}}' ) ;
491+ const view = sinon . stub ( ) . callsFake ( ( _i , o , _t ) => {
492+ o . editorWidget = jsonEditor ;
493+ } ) ;
494+ const protocolMonitor = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorImpl ( view ) ;
495+ await protocolMonitor . updateComplete ;
496+ view . lastCall . firstArg . onSplitChange ( new CustomEvent ( 'change' , { detail : 'OnlyMain' } ) ) ;
497+ await protocolMonitor . updateComplete ;
498+
499+ assert . deepEqual ( view . lastCall . firstArg . command , '{"command":"Test.test","parameters":{"test":"test"}}' ) ;
506500 } ) ;
507501
508502 it ( 'should update the selected target inside the input bar' , async ( ) => {
509- const split = new UI . SplitWidget . SplitWidget ( true , false , 'protocol-monitor-split-container' , 400 ) ;
510- const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( new Map ( ) , new Map ( ) , new Map ( ) ) ;
503+ const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( document . createElement ( 'div' ) ) ;
511504 jsonEditor . targetId = 'value2' ;
512505 sinon . stub ( SDK . TargetManager . TargetManager . instance ( ) , 'targets' ) . returns ( [
513506 { id : ( ) => 'value1' } as SDK . Target . Target ,
514507 { id : ( ) => 'value2' } as SDK . Target . Target ,
515508 ] ) ;
516- const view = sinon . stub ( ) ;
517- const dataGrid = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorDataGrid ( split , view ) ;
518-
519- split . setMainWidget ( dataGrid ) ;
520- split . setSidebarWidget ( jsonEditor ) ;
521-
522- split . toggleSidebar ( ) ;
523- await RenderCoordinator . done ( { waitForWork : true } ) ;
509+ const view = sinon . stub ( ) . callsFake ( ( _i , o , _t ) => {
510+ o . editorWidget = jsonEditor ;
511+ } ) ;
512+ const protocolMonitor = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorImpl ( view ) ;
513+ await protocolMonitor . updateComplete ;
514+ view . lastCall . firstArg . onSplitChange ( new CustomEvent ( 'change' , { detail : 'OnlyMain' } ) ) ;
515+ await protocolMonitor . updateComplete ;
524516
525517 assert . deepEqual ( view . lastCall . firstArg . selectedTargetId , 'value2' ) ;
526518 } ) ;
@@ -529,20 +521,17 @@ describeWithEnvironment('JSONEditor', () => {
529521 it . skip (
530522 '[crbug.com/1484534]: should not display the command into the input bar if the command is empty string' ,
531523 async ( ) => {
532- const split = new UI . SplitWidget . SplitWidget ( true , false , 'protocol-monitor-split-container' , 400 ) ;
533- const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( new Map ( ) , new Map ( ) , new Map ( ) ) ;
524+ const jsonEditor = new ProtocolMonitor . JSONEditor . JSONEditor ( document . createElement ( 'div' ) ) ;
534525 jsonEditor . command = '' ;
535- const dataGrid = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorDataGrid ( split ) ;
536- split . setMainWidget ( dataGrid ) ;
537- split . setSidebarWidget ( jsonEditor ) ;
538- split . toggleSidebar ( ) ;
539-
540- await RenderCoordinator . done ( ) ;
541-
542- // The first input bar corresponds to the filter bar, so we query the second one which corresponds to the CDP one.
543- const toolbarInput = dataGrid . element . shadowRoot ?. querySelectorAll ( '.toolbar' ) [ 1 ] . shadowRoot ?. querySelector (
544- '.toolbar-input-prompt' ) ;
545- assert . deepEqual ( toolbarInput ?. innerHTML , '' ) ;
526+ const view = sinon . stub ( ) . callsFake ( ( _i , o , _t ) => {
527+ o . editorWidget = jsonEditor ;
528+ } ) ;
529+ const protocolMonitor = new ProtocolMonitor . ProtocolMonitor . ProtocolMonitorImpl ( view ) ;
530+ await protocolMonitor . updateComplete ;
531+ view . lastCall . firstArg . onSplitChange ( new CustomEvent ( 'change' , { detail : 'OnlyMain' } ) ) ;
532+ await protocolMonitor . updateComplete ;
533+
534+ assert . deepEqual ( view . lastCall . firstArg . command , '' ) ;
546535 } ) ;
547536 } ) ;
548537 describe ( 'Descriptions' , ( ) => {
0 commit comments