/
HTMLDialogElement.test.ts
113 lines (97 loc) · 3.18 KB
/
HTMLDialogElement.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import Event from '../../../src/event/Event';
import IHTMLDialogElement from '../../../src/nodes/html-dialog-element/IHTMLDialogElement';
import Window from '../../../src/window/Window';
import IWindow from '../../../src/window/IWindow';
import IDocument from '../../../src/nodes/document/IDocument';
describe('HTMLDialogElement', () => {
let window: IWindow;
let document: IDocument;
let element: IHTMLDialogElement;
beforeEach(() => {
window = new Window();
document = window.document;
element = <IHTMLDialogElement>document.createElement('dialog');
});
describe('get open()', () => {
it('Should be closed by default', () => {
expect(element.open).toBe(false);
});
it('Should be open when show has been called', () => {
element.show();
expect(element.open).toBe(true);
});
it('Should be open when showModal has been called', () => {
element.showModal();
expect(element.open).toBe(true);
});
});
describe('get returnValue()', () => {
it('Should be empty string by default', () => {
expect(element.returnValue).toBe('');
});
it('Should be set when close has been called with a return value', () => {
element.close('foo');
expect(element.returnValue).toBe('foo');
});
});
describe('set returnValue()', () => {
it('Should be possible to set manually', () => {
element.returnValue = 'foo';
expect(element.returnValue).toBe('foo');
});
});
describe('close()', () => {
it('Should be possible to close an open dialog', () => {
element.show();
element.close();
expect(element.open).toBe(false);
expect(element.getAttributeNS(null, 'open')).toBe(null);
});
it('Should be possible to close an open modal dialog', () => {
element.showModal();
element.close();
expect(element.open).toBe(false);
expect(element.getAttributeNS(null, 'open')).toBe(null);
});
it('Should be possible to close the dialog with a return value', () => {
element.show();
element.close('foo');
expect(element.returnValue).toBe('foo');
});
it('Should be possible to close the modal dialog with a return value', () => {
element.showModal();
element.close('foo');
expect(element.returnValue).toBe('foo');
});
it('Should dispatch a close event', () => {
let dispatched: Event = null;
element.addEventListener('close', (event: Event) => (dispatched = event));
element.show();
element.close();
expect(dispatched.cancelable).toBe(false);
expect(dispatched.bubbles).toBe(false);
});
it('Should dispatch a close event when closing a modal', () => {
let dispatched: Event = null;
element.addEventListener('close', (event: Event) => (dispatched = event));
element.showModal();
element.close();
expect(dispatched.cancelable).toBe(false);
expect(dispatched.bubbles).toBe(false);
});
});
describe('showModal()', () => {
it('Should be possible to show a modal dialog', () => {
element.showModal();
expect(element.open).toBe(true);
expect(element.getAttributeNS(null, 'open')).toBe('');
});
});
describe('show()', () => {
it('Should be possible to show a dialog', () => {
element.show();
expect(element.open).toBe(true);
expect(element.getAttributeNS(null, 'open')).toBe('');
});
});
});