Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/components/error-state/ErrorState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ export default class ErrorState extends WebComponent {
render () {
return html`
<section role="alert">
<solid-ui-button class="close-button" variant="ghost" aria-label="Close">
<solid-ui-button class="close-button" variant="ghost" @click=${this.onClose}>
<icon-lucide-x slot="icon" aria-hidden="true"></icon-lucide-x>
<span class="sr-only">Close</span>
</solid-ui-button>
<div class="icon">
<icon-lucide-triangle-alert aria-hidden="true"></icon-lucide-triangle-alert>
Expand All @@ -35,4 +36,11 @@ export default class ErrorState extends WebComponent {
</section>
`
}

private onClose () {
this.dispatchEvent(new CustomEvent('close', {
bubbles: true,
composed: true
}))
}
}
21 changes: 19 additions & 2 deletions test/components/error-state.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @vitest-environment jsdom

import { describe, expect, it } from 'vitest'
import { describe, expect, it, vi } from 'vitest'
import '../../src/components/error-state'

describe('solid-ui-error-state', () => {
Expand All @@ -17,7 +17,24 @@ describe('solid-ui-error-state', () => {
expect(element.shadowRoot?.textContent).toContain('Try again when your connection is restored.')
const closeButton = element.shadowRoot?.querySelector('solid-ui-button.close-button')
expect(closeButton?.getAttribute('variant')).toBe('ghost')
expect(closeButton?.getAttribute('aria-label')).toBe('Close')
expect(closeButton?.textContent).toContain('Close')
expect(element.querySelector('li')?.textContent).toBe('Network request failed')
})

it('dispatches a close event when the close button is activated', async () => {
const element = document.createElement('solid-ui-error-state')
document.body.append(element)

await (element as unknown as { updateComplete: Promise<boolean> }).updateComplete

const closeButton = element.shadowRoot?.querySelector('solid-ui-button.close-button')
const innerButton = closeButton?.shadowRoot?.querySelector('button')
const closeHandler = vi.fn()
element.addEventListener('close', closeHandler)

innerButton?.click()

expect(closeHandler).toHaveBeenCalledTimes(1)
expect(closeHandler.mock.calls[0][0]).toBeInstanceOf(CustomEvent)
})
})
Loading