@@ -6,105 +6,78 @@ import * as SDK from '../../core/sdk/sdk.js';
66import { assertScreenshot , renderElementIntoDOM } from '../../testing/DOMHelpers.js' ;
77import { createTarget , stubNoopSettings } from '../../testing/EnvironmentHelpers.js' ;
88import { describeWithMockConnection , setMockConnectionResponseHandler } from '../../testing/MockConnection.js' ;
9+ import { createViewFunctionStub } from '../../testing/ViewFunctionHelpers.js' ;
910
1011import * as Accessibility from './accessibility.js' ;
1112
1213describeWithMockConnection ( 'ARIAAttributesView' , ( ) => {
13- let target : SDK . Target . Target ;
14- let domModel : SDK . DOMModel . DOMModel ;
1514 let node : SDK . DOMModel . DOMNode ;
16- let setAttributeValueSpy : sinon . SinonSpy ;
1715
1816 beforeEach ( ( ) => {
1917 setMockConnectionResponseHandler ( 'Debugger.enable' , ( ) => ( { } ) ) ;
2018 setMockConnectionResponseHandler ( 'Storage.getStorageKeyForFrame' , ( ) => ( { } ) ) ;
2119 stubNoopSettings ( ) ;
22- target = createTarget ( ) ;
23- domModel = target . model ( SDK . DOMModel . DOMModel ) as SDK . DOMModel . DOMModel ;
20+ const target = createTarget ( ) ;
21+ const domModel = target . model ( SDK . DOMModel . DOMModel ) as SDK . DOMModel . DOMModel ;
2422 node = new SDK . DOMModel . DOMNode ( domModel ) ;
2523 node . setAttributesPayload ( [ 'role' , 'checkbox' , 'aria-checked' , 'true' ] ) ;
26- setAttributeValueSpy = sinon . spy ( node , 'setAttributeValue' ) ;
2724 } ) ;
2825
29- const modifyAttribute =
30- ( view : Accessibility . ARIAAttributesView . ARIAAttributesPane , childIndex : number , newValue : string ) => {
31- const treeOutline = view . getTreeOutlineForTesting ( ) ;
32- assert . exists ( treeOutline ) ;
33- const treeElement =
34- treeOutline . rootElement ( ) . childAt ( childIndex ) as Accessibility . ARIAAttributesView . ARIAAttributesTreeElement ;
35- assert . exists ( treeElement ) ;
36- treeElement . listItemElement . querySelector ( 'span' ) ?. click ( ) ;
37-
38- const prompt = treeElement . getPromptForTesting ( ) ;
39- assert . exists ( prompt ) ;
40- const proxyElement = prompt . element ( ) ;
41- ( proxyElement as HTMLElement ) . textContent = newValue ;
42-
43- proxyElement . dispatchEvent ( new FocusEvent ( 'blur' ) ) ;
44- } ;
45-
46- it ( 'should render attributes' , async ( ) => {
47- const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( ) ;
48- renderElementIntoDOM ( view , { includeCommonStyles : true } ) ;
49- view . setNode ( node ) ;
50- await assertScreenshot ( 'accessibility/aria-attributes.png' ) ;
51- } ) ;
52-
53- it ( 'can modify an ARIA attribute value' , ( ) => {
54- const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( ) ;
55- renderElementIntoDOM ( view ) ;
26+ it ( 'can modify an ARIA attribute value' , async ( ) => {
27+ const viewFunction = createViewFunctionStub ( Accessibility . ARIAAttributesView . ARIAAttributesPane ) ;
28+ const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( viewFunction ) ;
5629 view . setNode ( node ) ;
5730
58- modifyAttribute ( view , 1 , 'false' ) ;
31+ const input = await viewFunction . nextInput ;
32+ const ariaChecked = input . attributes . find ( attr => attr . name === 'aria-checked' ) ;
33+ assert . exists ( ariaChecked ) ;
34+ const setAttributeValueSpy = sinon . spy ( node , 'setAttributeValue' ) ;
35+ input . onCommitEditing ( ariaChecked , 'false' ) ;
5936
6037 sinon . assert . calledOnceWithExactly ( setAttributeValueSpy , 'aria-checked' , 'false' ) ;
6138 } ) ;
6239
63- it ( 'can modify an ARIA role' , ( ) => {
64- const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( ) ;
65- renderElementIntoDOM ( view ) ;
40+ it ( 'can modify an ARIA role' , async ( ) => {
41+ const viewFunction = createViewFunctionStub ( Accessibility . ARIAAttributesView . ARIAAttributesPane ) ;
42+ const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( viewFunction ) ;
6643 view . setNode ( node ) ;
6744
68- modifyAttribute ( view , 0 , 'radio' ) ;
45+ const input = await viewFunction . nextInput ;
46+ const role = input . attributes . find ( attr => attr . name === 'role' ) ;
47+ assert . exists ( role ) ;
48+ const setAttributeValueSpy = sinon . spy ( node , 'setAttributeValue' ) ;
49+ input . onCommitEditing ( role , 'radio' ) ;
6950
7051 sinon . assert . calledOnceWithExactly ( setAttributeValueSpy , 'role' , 'radio' ) ;
7152 } ) ;
72- } ) ;
73-
74- describe ( 'ARIAAttributesTreeElement' , ( ) => {
75- it ( 'should create a value element with the correct class and text content' , ( ) => {
76- const value = 'test value' ;
77- const element = Accessibility . ARIAAttributesView . ARIAAttributesTreeElement . createARIAValueElement ( value ) ;
78- assert . strictEqual ( element . textContent , value ) ;
79- assert . isTrue ( element . classList . contains ( 'monospace' ) ) ;
80- } ) ;
81-
82- it ( 'should append a name element with the correct classes and text content' , ( ) => {
83- const parentPane = { } as Accessibility . ARIAAttributesView . ARIAAttributesPane ;
84- const attribute = { name : 'aria-label' , value : 'test' } as SDK . DOMModel . Attribute ;
85- const target = { } as SDK . Target . Target ;
86- const treeElement = new Accessibility . ARIAAttributesView . ARIAAttributesTreeElement ( parentPane , attribute , target ) ;
87- treeElement . onattach ( ) ;
8853
89- treeElement . appendNameElement ( 'aria-label' ) ;
54+ it ( 'autocompletes attributes' , async ( ) => {
55+ const viewFunction = createViewFunctionStub ( Accessibility . ARIAAttributesView . ARIAAttributesPane ) ;
56+ const view = new Accessibility . ARIAAttributesView . ARIAAttributesPane ( viewFunction ) ;
57+ view . setNode ( node ) ;
9058
91- const nameElement = treeElement . listItemElement . querySelector ( '.ax-name' ) ;
92- assert . exists ( nameElement ) ;
93- assert . strictEqual ( nameElement . textContent , 'aria-label' ) ;
94- assert . isTrue ( nameElement . classList . contains ( 'monospace' ) ) ;
59+ const input = await viewFunction . nextInput ;
60+ const role = input . attributes . find ( attr => attr . name === 'role' ) ;
61+ assert . exists ( role ) ;
62+ const ariaChecked = input . attributes . find ( attr => attr . name === 'aria-checked' ) ;
63+ assert . exists ( ariaChecked ) ;
64+ assert . deepEqual ( await input . propertyCompletions . get ( ariaChecked ) , [ 'true' , 'false' , 'mixed' , 'undefined' ] ) ;
65+ assert . isTrue ( await input . propertyCompletions . has ( role ) ) ;
9566 } ) ;
9667
97- it ( 'should append a value element with the correct text content' , ( ) => {
98- const parentPane = { } as Accessibility . ARIAAttributesView . ARIAAttributesPane ;
99- const attribute = { name : 'aria-label' , value : 'test' } as SDK . DOMModel . Attribute ;
100- const target = { } as SDK . Target . Target ;
101- const treeElement = new Accessibility . ARIAAttributesView . ARIAAttributesTreeElement ( parentPane , attribute , target ) ;
102- treeElement . onattach ( ) ;
103-
104- treeElement . appendAttributeValueElement ( 'test' ) ;
68+ it ( 'should render attributes' , async ( ) => {
69+ const container = document . createElement ( 'div' ) ;
70+ renderElementIntoDOM ( container , { includeCommonStyles : true } ) ;
71+ const input = {
72+ onStartEditing : sinon . stub ( ) ,
73+ onCommitEditing : sinon . stub ( ) ,
74+ onCancelEditing : sinon . stub ( ) ,
75+ attributeBeingEdited : null ,
76+ attributes : node . attributes ( ) ,
77+ propertyCompletions : new Map ( ) ,
78+ } ;
79+ Accessibility . ARIAAttributesView . DEFAULT_VIEW ( input , { } , container ) ;
10580
106- const valueElement = treeElement . listItemElement . querySelector ( 'span:not(.ax-name):not(.separator)' ) ;
107- assert . exists ( valueElement ) ;
108- assert . strictEqual ( valueElement . textContent , 'test' ) ;
81+ await assertScreenshot ( 'accessibility/aria-attributes.png' ) ;
10982 } ) ;
11083} ) ;
0 commit comments