@@ -15,12 +15,15 @@ import { spy } from 'sinon';
1515
1616import '..' ;
1717import { Dialog , DialogWrapper } from '..' ;
18- import { Button } from '@spectrum-web-components/button' ;
18+ import '@spectrum-web-components/underlay' ;
19+ import { Underlay } from '@spectrum-web-components/underlay' ;
20+ import { Button , ActionButton } from '@spectrum-web-components/button' ;
1921import {
2022 wrapperLabeledHero ,
2123 wrapperDismissible ,
2224 wrapperButtons ,
2325 wrapperFullscreen ,
26+ wrapperButtonsUnderlay ,
2427} from '../stories/dialog-wrapper.stories.js' ;
2528
2629describe ( 'Dialog Wrapper' , ( ) => {
@@ -45,6 +48,24 @@ describe('Dialog Wrapper', () => {
4548
4649 await expect ( el ) . to . be . accessible ( ) ;
4750 } ) ;
51+ it ( 'loads with underlay and no headline accessibly' , async ( ) => {
52+ const el = await fixture < DialogWrapper > ( wrapperButtonsUnderlay ( ) ) ;
53+ await elementUpdated ( el ) ;
54+ el . headline = '' ;
55+ await elementUpdated ( el ) ;
56+ expect ( el ) . to . be . accessible ( ) ;
57+ } ) ;
58+ it ( 'dismisses via clicking the underlay' , async ( ) => {
59+ const el = await fixture < DialogWrapper > ( wrapperButtonsUnderlay ( ) ) ;
60+ await elementUpdated ( el ) ;
61+ expect ( el . open ) . to . be . true ;
62+ el . dismissible = true ;
63+ const root = el . shadowRoot ? el . shadowRoot : el ;
64+ const underlay = root . querySelector ( 'sp-underlay' ) as Underlay ;
65+ underlay . click ( ) ;
66+ await elementUpdated ( el ) ;
67+ expect ( el . open ) . to . be . false ;
68+ } ) ;
4869 it ( 'dismisses' , async ( ) => {
4970 const el = await fixture < DialogWrapper > ( wrapperDismissible ( ) ) ;
5071
@@ -58,6 +79,50 @@ describe('Dialog Wrapper', () => {
5879 await elementUpdated ( el ) ;
5980 expect ( el . open ) . to . be . false ;
6081 } ) ;
82+ it ( 'manages entry focus - dismissible' , async ( ) => {
83+ const el = await fixture < DialogWrapper > ( wrapperDismissible ( ) ) ;
84+
85+ await elementUpdated ( el ) ;
86+ expect ( el . open ) . to . be . true ;
87+ expect ( document . activeElement , 'no focused' ) . to . not . equal ( el ) ;
88+
89+ const root = el . shadowRoot ? el . shadowRoot : el ;
90+ const dialog = root . querySelector ( 'sp-dialog' ) as Dialog ;
91+ const dialogRoot = dialog . shadowRoot ? dialog . shadowRoot : dialog ;
92+ const dismissButton = dialogRoot . querySelector (
93+ '.close-button'
94+ ) as ActionButton ;
95+
96+ el . focus ( ) ;
97+ await elementUpdated ( el ) ;
98+ expect ( document . activeElement , 'focused generally' ) . to . equal ( el ) ;
99+ expect (
100+ ( dismissButton . getRootNode ( ) as Document ) . activeElement ,
101+ 'focused specifically'
102+ ) . to . equal ( dismissButton ) ;
103+
104+ dismissButton . click ( ) ;
105+ await elementUpdated ( el ) ;
106+ expect ( el . open ) . to . be . false ;
107+ } ) ;
108+ it ( 'manages entry focus - buttons' , async ( ) => {
109+ const el = await fixture < DialogWrapper > ( wrapperButtons ( ) ) ;
110+
111+ await elementUpdated ( el ) ;
112+ expect ( el . open ) . to . be . true ;
113+ expect ( document . activeElement , 'no focused' ) . to . not . equal ( el ) ;
114+
115+ const root = el . shadowRoot ? el . shadowRoot : el ;
116+ const button = root . querySelector ( 'sp-button' ) as Button ;
117+
118+ el . focus ( ) ;
119+ await elementUpdated ( el ) ;
120+ expect ( document . activeElement , 'focused generally' ) . to . equal ( el ) ;
121+ expect (
122+ ( button . getRootNode ( ) as Document ) . activeElement ,
123+ 'focused specifically'
124+ ) . to . equal ( button ) ;
125+ } ) ;
61126 it ( 'dispatches `confirm`, `cancel` and `secondary`' , async ( ) => {
62127 const confirmSpy = spy ( ) ;
63128 const cancelSpy = spy ( ) ;
0 commit comments