* Opens the dialog. Defaults to using the interaction type set on the dialog tester.
(opts: DialogOpenOpts = {})
| 59 | * Opens the dialog. Defaults to using the interaction type set on the dialog tester. |
| 60 | */ |
| 61 | async open(opts: DialogOpenOpts = {}): Promise<void> { |
| 62 | let {interactionType = this._interactionType} = opts; |
| 63 | let trigger = this.getTrigger(); |
| 64 | if (!trigger.hasAttribute('disabled')) { |
| 65 | if (interactionType === 'mouse') { |
| 66 | await this.user.click(trigger); |
| 67 | } else if (interactionType === 'touch') { |
| 68 | await this.user.pointer({target: trigger, keys: '[TouchA]'}); |
| 69 | } else if (interactionType === 'keyboard') { |
| 70 | act(() => trigger.focus()); |
| 71 | await this.user.keyboard('[Enter]'); |
| 72 | } |
| 73 | |
| 74 | if (this._overlayType === 'popover') { |
| 75 | await waitFor(() => { |
| 76 | if (trigger.getAttribute('aria-controls') == null) { |
| 77 | throw new Error('No aria-controls found on dialog trigger element.'); |
| 78 | } else { |
| 79 | return true; |
| 80 | } |
| 81 | }); |
| 82 | |
| 83 | let dialogId = trigger.getAttribute('aria-controls'); |
| 84 | await waitFor(() => { |
| 85 | if (!dialogId || document.getElementById(dialogId) == null) { |
| 86 | throw new Error(`Dialog with id of ${dialogId} not found in document.`); |
| 87 | } else { |
| 88 | this._dialog = document.getElementById(dialogId)!; |
| 89 | return true; |
| 90 | } |
| 91 | }); |
| 92 | } else { |
| 93 | let dialog; |
| 94 | await waitFor(() => { |
| 95 | dialog = document.querySelector('[role=dialog], [role=alertdialog]'); |
| 96 | if (dialog == null) { |
| 97 | throw new Error( |
| 98 | 'No dialog of type role="dialog" or role="alertdialog" found after pressing the trigger.' |
| 99 | ); |
| 100 | } else { |
| 101 | return true; |
| 102 | } |
| 103 | }); |
| 104 | |
| 105 | if ( |
| 106 | dialog && |
| 107 | document.activeElement !== this._trigger && |
| 108 | dialog.contains(document.activeElement) |
| 109 | ) { |
| 110 | this._dialog = dialog; |
| 111 | } else { |
| 112 | throw new Error( |
| 113 | 'New modal dialog doesnt contain the active element OR the active element is still the trigger. Uncertain if the proper modal dialog was found' |
| 114 | ); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
nothing calls this directly
no test coverage detected