Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active October 5, 2023 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/b7e8bc644264fcae205db5464de3c57e to your computer and use it in GitHub Desktop.
Save YonatanKra/b7e8bc644264fcae205db5464de3c57e to your computer and use it in GitHub Desktop.
Tauri-demo: add an alert
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);
});
});
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