-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a static "show" method to NotificationElement (#2322)
* Add a static "show" method to NotificationElement Fixes #914 * Remove unnecessary defaults * Use only one options parameter * add API docs for options object Co-authored-by: Sascha Ißbrücker <[email protected]>
- Loading branch information
1 parent
ab43882
commit abf0f69
Showing
4 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import { NotificationElement } from '../src/vaadin-notification.js'; | ||
import '../vaadin-notification.js'; | ||
import { html } from 'lit'; | ||
import { aTimeout } from '@vaadin/testing-helpers'; | ||
|
||
describe('static helpers', () => { | ||
it('show should show a text notification', () => { | ||
const notification = NotificationElement.show('Hello world'); | ||
const notificationDom = document.body.querySelector('vaadin-notification'); | ||
expect(notification).to.equal(notificationDom); | ||
|
||
expect(notification._card.innerText.trim()).to.equal('Hello world'); | ||
}); | ||
|
||
it('show should show a Lit template notificatipn', () => { | ||
const notification = NotificationElement.show(html`Hello world`); | ||
|
||
//const notificationDom = document.body.querySelector('vaadin-notification'); | ||
//FIXME This causes 'TypeError: Converting circular structure to JSON' | ||
// expect(notification).to.equal(notificationDom); | ||
|
||
expect(notification._card.innerText.trim()).to.equal('Hello world'); | ||
}); | ||
|
||
it('show should use a default duration of 5s and bottom-start', () => { | ||
const notification = NotificationElement.show('Hello world'); | ||
expect(notification.duration).to.equal(5000); | ||
expect(notification.position).to.equal('bottom-start'); | ||
}); | ||
|
||
it('show should use the given duration and position', () => { | ||
const notification = NotificationElement.show('Hello world', { duration: 123, position: 'top-center' }); | ||
expect(notification.duration).to.equal(123); | ||
expect(notification.position).to.equal('top-center'); | ||
}); | ||
|
||
it('show remove the element from the document after closing', async () => { | ||
const notification = NotificationElement.show('Hello world', { duration: 1 }); | ||
expect(notification.parentElement).to.equal(document.body); | ||
await aTimeout(10); | ||
expect(notification.parentElement).to.be.null; | ||
}); | ||
|
||
it('show should support Lit event handlers', () => { | ||
let clicked = 0; | ||
const doClose = () => { | ||
clicked++; | ||
}; | ||
const notification = NotificationElement.show(html`Click <button @click=${doClose}>this</button> to count`); | ||
notification._card.querySelector('button').click(); | ||
|
||
expect(clicked).to.equal(1); | ||
}); | ||
|
||
it('show should support closing through an event handler', () => { | ||
const notification = NotificationElement.show( | ||
html`Click | ||
<button | ||
@click=${() => { | ||
notification.opened = false; | ||
}} | ||
>this</button | ||
> | ||
to close` | ||
); | ||
notification._card.querySelector('button').click(); | ||
|
||
expect(notification.opened).to.equal(false); | ||
}); | ||
}); |