Skip to content

Commit

Permalink
use socket for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
heapwolf committed Apr 24, 2024
1 parent de3d4b4 commit 4b2ba69
Show file tree
Hide file tree
Showing 30 changed files with 127 additions and 82 deletions.
2 changes: 1 addition & 1 deletion _test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
object-src 'none';
"
>
<script src="index.js" type="module"></script>
<script src="_test/index.js" type="module"></script>
</head>
<body>
</body>
Expand Down
2 changes: 1 addition & 1 deletion accordion/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'
import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'
Components(Tonic)

document.body.appendChild(html`
Expand Down
2 changes: 1 addition & 1 deletion badge/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion button/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion chart/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import chart from 'chart.js'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion checkbox/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion dialog/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion icon/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
3 changes: 2 additions & 1 deletion importmap.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"imports": {
"@socketsupply/tonic": "npm:@socketsupply/tonic"
"@socketsupply/tonic": "npm:@socketsupply/tonic",
"chart.js": "npm:chart.js"
}
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Components.Tonic = Tonic
//
// An example collection of components.
//
export function Components (Tonic) {
function Components (Tonic) {
if (once) {
return
}
Expand Down Expand Up @@ -83,4 +83,5 @@ export function Components (Tonic) {
Tonic.add(TonicToggle, 'tonic-toggle')
}

export { Components }
export default Components
2 changes: 1 addition & 1 deletion input/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
{
"name": "@socketsupply/components",
"version": "14.0.13",
"version": "14.1.0",
"description": "Example components",
"type": "module",
"scripts": {
"prepare": "npm run lint",
"prepublishOnly": "git push --follow-tags",
"lint": "standard -v",
"test": "standard && esbuild --format=esm --bundle _test/index.js | tape-run",
"test:ci": "esbuild --format=esm --bundle _test/index.js | tape-run",
"test:open": "esbuild --format=esm --bundle _test/index.js | tape-run --browser chrome --keep-open",
"test": "npm run lint && ssc build -r",
"pub": "npm pub && npm publish --registry https://npm.pkg.github.com"
},
"repository": {
Expand All @@ -30,8 +26,9 @@
},
"homepage": "https://github.com/socketsupply/components#readme",
"devDependencies": {
"@socketsupply/socket": "github:socketsupply/socket#next",
"@socketsupply/tonic": "15.0.0",
"standard": "16.0.4",
"chart.js": "^2.9.2"
"chart.js": "^2.9.2",
"standard": "16.0.4"
}
}
18 changes: 9 additions & 9 deletions panel/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down Expand Up @@ -81,24 +81,24 @@ panelPositionButton.addEventListener('click', e => panelPosition.show())

test('opening a panel', async t => {
const container = qs('#example-panel-default')
const overlay = qs('.tonic--overlay')
const overlay = qs('.tonic--dialog--overlay')
const main = qs('main', container)
const h3 = qs('h3', main)

t.ok(container)
t.ok(overlay)
t.ok(main)
t.ok(h3)
t.ok(container, 'container created')
t.ok(overlay, 'overlay created')
t.ok(main, 'main found')
t.ok(h3, 'h3 found')

t.equal(h3.textContent.trim(), 'Hello')
t.equal(h3.textContent.trim(), 'Hello', 'should contain "Hello"')

t.ok(container.hasAttribute('hidden'))
t.ok(container.hasAttribute('hidden'), 'should be hidden')

await container.show()

t.equal(container.hasAttribute('hidden'), false, 'is not hidden')

await container.hide()

t.ok(container.hasAttribute('hidden'))
t.ok(container.hasAttribute('hidden'), 'container is hidden')
})
18 changes: 10 additions & 8 deletions popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,17 @@ export class TonicPopover extends Tonic {
}
}

show (triggerNode) {
show () {
const triggerNode = document.querySelector(`#${this.props.for}`)
const popover = this.querySelector('.tonic--popover')
let scrollableArea = triggerNode.parentNode

while (true) {
if (!scrollableArea || scrollableArea.tagName === 'BODY') break
if (window.getComputedStyle(scrollableArea).overflow === 'scroll') break

const overflow = window.getComputedStyle(scrollableArea).overflow
if (['scroll', 'scroll-x', 'scroll-y', 'auto'].includes(overflow)) break

scrollableArea = scrollableArea.parentNode
}

Expand Down Expand Up @@ -147,19 +151,17 @@ export class TonicPopover extends Tonic {
left += triggerNode.offsetWidth - popover.offsetWidth
break
case 'bottom':
pos += triggerNode.offsetHeight + margin
pos += triggerNode.parentNodeNode.offsetHeight + margin
left += (triggerNode.offsetWidth / 2) - (popover.offsetWidth / 2)
break
}

popover.style.top = `${pos}px`
popover.style.left = `${left}px`

window.requestAnimationFrame(() => {
popover.className = `tonic--popover tonic--show tonic--popover--${this.props.position}`
const event = new window.Event('show')
this.dispatchEvent(event)
})
popover.className = `tonic--popover tonic--show tonic--popover--${this.props.position}`
const event = new window.Event('show')
this.dispatchEvent(event)
}

hide () {
Expand Down
37 changes: 15 additions & 22 deletions popover/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand All @@ -13,9 +13,9 @@ document.body.appendChild(html`
<!-- Popover Default -->
<div class="test-container">
<span>Default Popover</span>
<tonic-button id="tonic-popover-default-button">
<button id="tonic-popover-default-button">
Open Popover
</tonic-button>
</button>
</div>
<tonic-popover
Expand All @@ -30,17 +30,6 @@ document.body.appendChild(html`
</section>
`)

//
// Panel Default
//
const popover = document.getElementById('tonic-popover-default')
popover.addEventListener('show', event => {
document.body.addEventListener('click', e => {
popover.hide()
}, { once: true })
})

// TODO: write tests for popover.
test('opening popover', async t => {
const container = qs('#popover')
const popover = qs('#tonic-popover-default', container)
Expand All @@ -49,20 +38,24 @@ test('opening popover', async t => {
t.ok(popover)
t.ok(button)

const popoverCont = qs('.tonic--popover', popover)
t.ok(popoverCont)
const coPopover = qs('.tonic--popover', popover)
t.ok(coPopover)

const divs = popoverCont.querySelectorAll('div')
popover.addEventListener('show', event => {
t.ok(coPopover.classList.contains('tonic--show'), 'the component should be visible')
popover.hide()
})

const divs = coPopover.querySelectorAll('div')
t.equal(divs.length, 3)

const styles = window.getComputedStyle(divs[0])
t.equal(styles.visibility, 'hidden')
t.ok(!coPopover.classList.contains('tonic--show'), 'the component should be hidden')

button.querySelector('button').click()
await sleep(512)
button.click()

const styles2 = window.getComputedStyle(divs[0])
t.equal(styles2.visibility, 'visible')
await sleep(512)
t.ok(!coPopover.classList.contains('tonic--show'), 'the component should not be visible')
})

function sleep (ms) {
Expand Down
2 changes: 1 addition & 1 deletion profile-image/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion progress-bar/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion range/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
4 changes: 2 additions & 2 deletions relative-time/test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Components } from '..'
import { RelativeTime } from '.'
import { Components } from '../index.js'
import { RelativeTime } from './index.js'
import { Tonic } from '@socketsupply/tonic'

Components(Tonic)
Expand Down
2 changes: 1 addition & 1 deletion router/test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { html } from '../_test/util.js'
import { Tonic } from '@socketsupply/tonic'

import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
2 changes: 1 addition & 1 deletion select/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { test } from 'socket:test'
import { html, qs } from '../_test/util.js'

import { Tonic } from '@socketsupply/tonic'
import { Components } from '..'
import { Components } from '../index.js'

Components(Tonic)

Expand Down
Loading

0 comments on commit 4b2ba69

Please sign in to comment.