@operato/help 10.29.17 → 10.29.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,94 @@
1
+ import { expect, fixture, html, waitUntil } from '@open-wc/testing'
2
+
3
+ import '../src/components/ox-doc.js'
4
+ import '../src/components/ox-help-spot.js'
5
+ import type { OxDoc } from '../src/components/ox-doc.js'
6
+
7
+ /**
8
+ * ox-doc reads /helps/{topic}.html and renders it; the products that used to keep their own copy rely on
9
+ * these behaviours.
10
+ */
11
+ const DOCS: Record<string, string> = {
12
+ 'a/one': `<h1 id="top">One</h1><p>lead</p><h2 id="part">Part</h2><p>in part</p><table><tr><td>x</td></tr></table><h2 id="next">Next</h2><p>after</p><a data-topic="a/two#end">two</a>`,
13
+ 'a/two': `<h1>Two</h1><h2 id="end">End</h2>`
14
+ }
15
+
16
+ let requests: string[] = []
17
+ const realFetch = window.fetch
18
+
19
+ beforeEach(() => {
20
+ requests = []
21
+ window.fetch = (async (input: RequestInfo | URL) => {
22
+ const url = String(input)
23
+ requests.push(url)
24
+ const topic = url.replace(/^\/helps\//, '').replace(/\.html.*$/, '')
25
+ return DOCS[topic] ? new Response(DOCS[topic]) : new Response('', { status: 404 })
26
+ }) as typeof window.fetch
27
+ })
28
+
29
+ afterEach(() => {
30
+ window.fetch = realFetch
31
+ })
32
+
33
+ const bodyOf = (el: OxDoc) => el.shadowRoot!.querySelector('.body') as HTMLElement
34
+
35
+ describe('ox-doc', () => {
36
+ it('reads /helps/{topic}.html with the language and renders it', async () => {
37
+ const el = await fixture<OxDoc>(html`<ox-doc topic="a/one"></ox-doc>`)
38
+ await waitUntil(() => bodyOf(el)?.querySelector('h1'))
39
+
40
+ expect(requests[0]).to.match(/^\/helps\/a\/one\.html\?lng=/)
41
+ expect(bodyOf(el).querySelector('h1')!.textContent).to.equal('One')
42
+ })
43
+
44
+ it('wraps tables in a scrolling box so they do not push the page wide', async () => {
45
+ const el = await fixture<OxDoc>(html`<ox-doc topic="a/one"></ox-doc>`)
46
+ await waitUntil(() => bodyOf(el)?.querySelector('table'))
47
+
48
+ expect(bodyOf(el).querySelector('table')!.parentElement!.classList.contains('tablewrap')).to.equal(true)
49
+ })
50
+
51
+ it('shows only the named section, up to the next heading of its level', async () => {
52
+ const el = await fixture<OxDoc>(html`<ox-doc topic="a/one" section="part"></ox-doc>`)
53
+ await waitUntil(() => bodyOf(el)?.querySelector('h2'))
54
+
55
+ expect(bodyOf(el).textContent).to.contain('in part')
56
+ expect(bodyOf(el).textContent).to.not.contain('lead')
57
+ expect(bodyOf(el).textContent).to.not.contain('after')
58
+ })
59
+
60
+ it('follows a topic link in place and tells the host, without keeping the anchor in the file name', async () => {
61
+ const el = await fixture<OxDoc>(html`<ox-doc topic="a/one"></ox-doc>`)
62
+ await waitUntil(() => bodyOf(el)?.querySelector('a[data-topic]'))
63
+
64
+ let told: any
65
+ el.addEventListener('ox-doc-topic', e => (told = (e as CustomEvent).detail))
66
+ ;(bodyOf(el).querySelector('a[data-topic]') as HTMLElement).click()
67
+ await waitUntil(() => bodyOf(el)?.querySelector('h1')?.textContent === 'Two')
68
+
69
+ expect(told).to.deep.equal({ topic: 'a/two', hash: 'end' })
70
+ expect(requests[requests.length - 1]).to.match(/^\/helps\/a\/two\.html\?/)
71
+ })
72
+
73
+ it('says the topic is missing instead of showing an empty page', async () => {
74
+ const el = await fixture<OxDoc>(html`<ox-doc topic="a/none"></ox-doc>`)
75
+ await waitUntil(() => el.shadowRoot!.querySelector('.status.err'))
76
+
77
+ expect(el.shadowRoot!.querySelector('.status.err')!.textContent).to.contain('a/none')
78
+ })
79
+ })
80
+
81
+ describe('ox-help-spot', () => {
82
+ it('opens the section in place and closes on Escape', async () => {
83
+ const el = await fixture<HTMLElement>(html`<ox-help-spot topic="a/one" section="part"></ox-help-spot>`)
84
+ ;(el.shadowRoot!.querySelector('button.q') as HTMLButtonElement).click()
85
+ await waitUntil(() => el.shadowRoot!.querySelector('ox-doc'))
86
+
87
+ const doc = el.shadowRoot!.querySelector('ox-doc') as OxDoc
88
+ expect(doc.getAttribute('section')).to.equal('part')
89
+ expect(doc.hasAttribute('compact')).to.equal(true)
90
+
91
+ el.shadowRoot!.querySelector('.panel')!.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true, composed: true }))
92
+ await waitUntil(() => !el.shadowRoot!.querySelector('.panel'))
93
+ })
94
+ })