-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtest.js
71 lines (54 loc) · 1.86 KB
/
test.js
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
import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'
import { Tonic } from '@socketsupply/tonic'
import { Components } from '../index.js'
Components(Tonic)
class DialogInner extends Tonic {
async click (e) {
return Tonic.match(e.target, 'tonic-button')
}
render () {
return `
<header>Dialog</header>
<main>
${this.props.message || 'Ready'}
</main>
<footer>
<tonic-button class="tonic--close" id="close">Close</tonic-button>
</footer>
`
}
}
Tonic.add(DialogInner, 'dialog-inner')
document.body.appendChild(html`
<section id="dialog">
<h2>Dialog</h2>
<div id="dialog-1" class="test-container">
<span>Default Dialog</span>
<tonic-button id="dialog-default-button">Open</tonic-button>
<tonic-dialog id="dialog-default">
<dialog-inner message="Hello!"></dialog-inner>
</tonic-dialog>
</div>
</section>
`)
//
// Dialog Tests
//
test('{{dialog-1}} is constructed properly, opens and closes properly', async t => {
const container = qs('#dialog-1')
const component = qs('#dialog-default', container)
const isShowingInitialState = component.classList.contains('tonic--show')
t.equal(isShowingInitialState, false, 'the element has no show class')
t.ok(component.hasAttribute('id'), 'the component has an id')
const styles = window.getComputedStyle(component)
t.equal(styles.position, 'absolute')
await component.show()
const close = qs('.tonic--dialog--close', component)
t.ok(close, 'the component contains the close button')
const isShowingAfterOpen = component.classList.contains('tonic--show')
t.equal(isShowingAfterOpen, true, 'the element has been opened, has show class')
await component.hide()
const isShowing = component.classList.contains('tonic--show')
t.equal(isShowing, false, 'the element has been closed, has no show class')
})