@ni/spright-components
Version:
NI Spright Components
74 lines • 2.61 kB
JavaScript
import { keyEnter } from '@ni/fast-web-utilities';
import { Button } from '@ni/nimble-components/dist/esm/button';
import { processUpdates, waitForUpdatesAsync } from '@ni/nimble-components/dist/esm/testing/async-helpers';
import { sendKeyDownEvent } from '@ni/nimble-components/dist/esm/utilities/testing/component';
/**
* Page object for the `spright-chat-input` component to provide consistent ways
* of querying and interacting with the component during tests.
*/
export class ChatInputPageObject {
constructor(element) {
this.element = element;
}
isSendButtonEnabled() {
return !this.getSendButton().disabled;
}
isTextAreaFocused() {
return this.element.textArea === this.element.shadowRoot?.activeElement;
}
clickSendButton() {
this.getSendButton().click();
}
getSendButtonTitle() {
return this.getSendButton().title;
}
getSendButtonTextContent() {
return this.getSendButton().textContent?.trim() ?? '';
}
getSendButtonTabIndex() {
return this.getSendButton().getAttribute('tabindex');
}
textAreaHasFocus() {
return (document.activeElement === this.element
&& this.element.shadowRoot?.activeElement === this.element.textArea);
}
getTextAreaTabIndex() {
return this.element.textArea.getAttribute('tabindex');
}
getPlaceholder() {
if (this.element.textArea.value) {
throw Error('Placeholder not visible');
}
return this.element.textArea.placeholder;
}
getRenderedText() {
return this.element.textArea.value;
}
setText(text) {
this.element.textArea.focus();
this.element.textArea.value = text;
this.element.textAreaInputHandler();
processUpdates();
}
async pressEnterKey() {
this.element.textArea.focus();
await this.sendEnterKeyEvents(false);
}
async pressShiftEnterKey() {
this.element.textArea.focus();
await this.sendEnterKeyEvents(true);
}
getSendButton() {
const sendButton = this.element.shadowRoot.querySelector('.send-button');
return sendButton;
}
async sendEnterKeyEvents(shiftKey) {
const keyDownEvent = await sendKeyDownEvent(this.element.textArea, keyEnter, { shiftKey });
if (!keyDownEvent.defaultPrevented) {
this.element.textArea.value += '\n';
this.element.textArea.dispatchEvent(new InputEvent('input'));
}
await waitForUpdatesAsync();
}
}
//# sourceMappingURL=chat-input.pageobject.js.map