@angular/material
Version:
Angular Material
23 lines • 7.05 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/cdk/testing"),require("@angular/cdk/coercion")):"function"==typeof define&&define.amd?define("@angular/material/menu/testing",["exports","tslib","@angular/cdk/testing","@angular/cdk/coercion"],e):e(((t=t||self).ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.menu=t.ng.material.menu||{},t.ng.material.menu.testing={}),t.tslib,t.ng.cdk.testing,t.ng.cdk.coercion)}(this,(function(t,e,n,r){"use strict";
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/var i=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e._documentRootLocator=e.documentRootLocatorFactory(),e}return e.__extends(i,t),i.with=function(t){return void 0===t&&(t={}),new n.HarnessPredicate(i,t).addOption("triggerText",t.triggerText,(function(t,e){return n.HarnessPredicate.stringMatches(t.getTriggerText(),e)}))},i.prototype.isDisabled=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,n;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.host()];case 1:return t=e.sent().getAttribute("disabled"),n=r.coerceBooleanProperty,[4,t];case 2:return[2,n.apply(void 0,[e.sent()])]}}))}))},i.prototype.isOpen=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this._getMenuPanel()];case 1:return[2,!!t.sent()]}}))}))},i.prototype.getTriggerText=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().text()]}}))}))},i.prototype.focus=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().focus()]}}))}))},i.prototype.blur=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().blur()]}}))}))},i.prototype.open=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.isOpen()];case 1:return t.sent()?[3,3]:[4,this.host()];case 2:return[2,t.sent().click()];case 3:return[2]}}))}))},i.prototype.close=function(){return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this._getMenuPanel()];case 1:return(t=e.sent())?[2,t.sendKeys(n.TestKey.ESCAPE)]:[2]}}))}))},i.prototype.getItems=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,(function(){var n;return e.__generator(this,(function(r){switch(r.label){case 0:return[4,this._getPanelId()];case 1:return(n=r.sent())?[2,this._documentRootLocator.locatorForAll(o.with(e.__assign(e.__assign({},t),{ancestor:"#"+n})))()]:[2,[]]}}))}))},i.prototype.clickItem=function(t){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];return e.__awaiter(this,void 0,void 0,(function(){var r,i;return e.__generator(this,(function(o){switch(o.label){case 0:return[4,this.open()];case 1:return o.sent(),[4,this.getItems(t)];case 2:if(!(r=o.sent()).length)throw Error("Could not find item matching "+JSON.stringify(t));return n.length?[3,4]:[4,r[0].click()];case 3:return[2,o.sent()];case 4:return[4,r[0].getSubmenu()];case 5:if(!(i=o.sent()))throw Error("Item matching "+JSON.stringify(t)+" does not have a submenu");return[2,i.clickItem.apply(i,e.__spread(n))]}}))}))},i.prototype._getMenuPanel=function(){return e.__awaiter(this,void 0,void 0,(function(){var t;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this._getPanelId()];case 1:return[2,(t=e.sent())?this._documentRootLocator.locatorForOptional("#"+t)():null]}}))}))},i.prototype._getPanelId=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[4,t.sent().getAttribute("aria-controls")];case 2:return[2,t.sent()||null]}}))}))},i.hostSelector=".mat-menu-trigger",i}(n.ComponentHarness),o=function(t){function o(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(o,t),o.with=function(t){var r=this;return void 0===t&&(t={}),new n.HarnessPredicate(o,t).addOption("text",t.text,(function(t,e){return n.HarnessPredicate.stringMatches(t.getText(),e)})).addOption("hasSubmenu",t.hasSubmenu,(function(t,n){return e.__awaiter(r,void 0,void 0,(function(){return e.__generator(this,(function(e){switch(e.label){case 0:return[4,t.hasSubmenu()];case 1:return[2,e.sent()===n]}}))}))}))},o.prototype.isDisabled=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,n;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.host()];case 1:return t=e.sent().getAttribute("disabled"),n=r.coerceBooleanProperty,[4,t];case 2:return[2,n.apply(void 0,[e.sent()])]}}))}))},o.prototype.getText=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().text()]}}))}))},o.prototype.focus=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().focus()]}}))}))},o.prototype.blur=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().blur()]}}))}))},o.prototype.click=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().click()]}}))}))},o.prototype.hasSubmenu=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().matchesSelector(i.hostSelector)]}}))}))},o.prototype.getSubmenu=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.hasSubmenu()];case 1:return t.sent()?[2,new i(this.locatorFactory)]:[2,null]}}))}))},o.hostSelector=".mat-menu-item",o}(n.ComponentHarness);
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
t.MatMenuHarness=i,t.MatMenuItemHarness=o,Object.defineProperty(t,"__esModule",{value:!0})}));