moh-common-lib
Version:
A library of Angular components, services, and styles for B.C. Government Ministry of Health (MoH).
212 lines (207 loc) • 7.42 kB
JavaScript
import { __awaiter } from 'tslib';
import { browser, by, element, $$, protractor } from 'protractor';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* AbstractTestPage provides common functionality for e2e tests that make use of
* the MoH Common Lib. For example, `getNameComponent()` and
* `getNameComponentVal()` both correspond to the NameComponent.
* @abstract
*/
class AbstractTestPage {
constructor() {
/**
* Clicking this button should complete the page, navigate to the next one.
* We default it to `.form-bar .submit` but you may overwrite as necessary.
*/
this.continueButton = element(by.css('.form-bar .submit'));
/**
* This is the 'Skip To Content' button for Screen Readers that appears when
* tabbed to. May be overwritten as necessary.
*/
this.skipToContentButton = element(by.css('.skip-to-content'));
}
/**
* @return {?}
*/
continue() {
this.continueButton.click();
}
/**
* @return {?}
*/
getContinueButton() {
return this.continueButton;
}
/**
* Scrolls down to the bottom of the page
* @return {?}
*/
scrollDown() {
browser.executeScript('window.scrollTo(0, document.body.scrollHeight)');
}
/**
* @return {?}
*/
clickSkipToContent() {
this.skipToContentButton.click();
}
/**
* **NameComponent** - Returns the NameComponent for an associated human
* readable label. If the label is a duplicate it will grab the first one
* only.
*
* TODO: Update to "common-name" component when it's imported from PRIME
*
* @param {?} labelName Human redable label name.
* @return {?}
*/
getNameComponent(labelName) {
return __awaiter(this, void 0, void 0, function* () {
/** @type {?} */
const label = element.all(by.cssContainingText('lib-prime-name label', labelName)).first();
return element(by.id(yield label.getAttribute('for')));
});
}
/**
* **NameComponent** - Returns the value within a given NameComponent
*
* TODO: Update to "common-name" component when it's imported from PRIME
*
* @param {?} labelName Human readable label name
* @return {?}
*/
getNameComponentVal(labelName) {
return __awaiter(this, void 0, void 0, function* () {
return (yield this.getNameComponent(labelName)).getAttribute('value');
});
}
/**
* @return {?}
*/
formErrors() {
return $$('[role=alert] .text-danger');
}
/**
* Selects from an ng-select component. This includes DropdownComponent
* others, like country, province, etc.
*
* TODO - Need to test this works! Right now just copied from GitHub with
* minor tweaks. IDEA - Mirror getNameComponent, where we lookup via the label
* text and use the 'for' attribute.
*
* @param {?} labelId corresponds to labelForId on the <ng-select>
* @param {?} optionText the option we want to select
* @return {?}
*/
selectOption(labelId, optionText) {
element(by.css(`ng-select[id="${labelId}"]`)).click(); // opens dropdown
element(by.cssContainingText('span.ng-option-label', optionText)).click(); // selects option by provided text
}
/**
* Works on same NgSelect components but it sends custom text instead of
* selecting a given choice.
* @param {?} labelId corresponds to labelForId on the <ng-select>
* @param {?} data the text we want to type
* @return {?}
*/
typeOption(labelId, data) {
element(by.css(`ng-select[id="${labelId}"]`)).click(); // opens dropdown
element(by.css(`input[role="combobox"]`)).sendKeys(data); // type option
browser.actions().sendKeys(protractor.Key.ENTER).perform(); // hit enter key
}
/**
* Enter text into an input via ng-reflect-name component
* @param {?} refNameVal Value of ng-reflect-name component
* @param {?} text Text to enter into the input
* @return {?}
*/
typeText(refNameVal, text) {
element(by.css(`input[ng-reflect-name^="${refNameVal}"]`)).sendKeys(text);
}
/**
* Clicks the button based on the text specified
* @param {?} classVal Human readable class value for a button
* @param {?} text Text inside the button
* @return {?}
*/
clickButton(classVal, text) {
element(by.cssContainingText(`button[class*="${classVal}"]`, text)).click();
}
/**
* Clicks the check box based on the ng-reflect-name component
* @param {?} refNameVal Value of ng-reflect-name component
* @return {?}
*/
clickCheckBox(refNameVal) {
element(by.css(`input[ng-reflect-name="${refNameVal}"]`)).click();
}
/**
* Clicks the checkbox which means the user agrees with the info collection notice.
* InfoColectionNoticeComponent <common-collection-modal>
* @return {?}
*/
agreeConsentModal() {
element(by.css('label[for="agree"]')).element(by.css('strong')).click();
}
/**
* Clicks continue inside the modal
* InfoColectionNoticeComponent <common-collection-modal>
* @return {?}
*/
clickConsentModalContinue() {
element(by.css('div[class="modal-footer"]')).element(by.css('button[type="submit"]')).click();
}
/**
* Checks if the consent modal is currently displayed or not
* @return {?}
*/
checkConsentModal() {
return element(by.css('common-consent-modal')).element(by.css('div[aria-labelledby="myLargeModalLabel"]')).isDisplayed();
}
/**
* Scrolls up to the top of the page
* @return {?}
*/
scrollUp() {
browser.executeScript('window.scrollTo(0,0)');
}
/**
* Types the text inside the first ocurrence of input field
* @param {?} refNameVal Value of ng-reflect-name component
* @param {?} text Text to enter into the input
* @return {?}
*/
typeTextFirstOccurrence(refNameVal, text) {
element.all(by.css(`input[ng-reflect-name^="${refNameVal}"]`)).first().sendKeys(text);
}
/**
* Clicks the link based from the label and text provided
* @param {?} label
* @param {?} text
* @return {?}
*/
clickLink(label, text) {
element(by.cssContainingText(label, text)).click();
}
/**
* Counts the number of options inside a dropdown box
* @param {?} refNameVal
* @return {?}
*/
countLength(refNameVal) {
return $$(`select[ng-reflect-name^="${refNameVal}"] option`);
}
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { AbstractTestPage };
//# sourceMappingURL=moh-common-lib-e2e.js.map