Last active
October 5, 2023 03:16
-
-
Save YonatanKra/b7e8bc644264fcae205db5464de3c57e to your computer and use it in GitHub Desktop.
Tauri-demo: add an alert
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
describe('alert', () => { | |
it('should display an alert with given message and title', () => { | |
app.connectedCallback(); | |
const message = 'some message'; | |
const title = 'some title'; | |
app.alert({message, title}); | |
const alert = app.shadowRoot?.querySelector('#alert'); | |
expect(alert?.getAttribute('Headline')).toBe(title); | |
expect(alert?.getAttribute('text')).toBe(message); | |
}); | |
it('should display an alert with given message and default title', () => { | |
app.connectedCallback(); | |
const message = 'some message'; | |
app.alert({message}); | |
const alert = app.shadowRoot?.querySelector('#alert'); | |
expect(alert?.getAttribute('Headline')).toBe('Alert'); | |
expect(alert?.getAttribute('text')).toBe(message); | |
}); | |
it('should open the alert', () => { | |
app.connectedCallback(); | |
const message = 'some message'; | |
app.alert({message}); | |
const alert = app.shadowRoot?.querySelector('#alert'); | |
expect(alert?.hasAttribute('open')).toBe(true); | |
}); | |
}); |
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
get #alertComponent() { | |
return this.shadowRoot!.getElementById('alert') as HTMLElement; | |
} | |
alert({message, title = 'Alert'} : {message: string, title?: string}) { | |
this.#alertComponent.setAttribute('headline', title!); | |
this.#alertComponent.setAttribute('text', message); | |
this.#alertComponent.toggleAttribute('open', true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment