UNPKG

@angular/material

Version:
38 lines (36 loc) 9.63 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/cdk/testing"),require("@angular/cdk/coercion")):"function"==typeof define&&define.amd?define("@angular/material/menu/testing",["exports","@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.ng.cdk.testing,t.ng.cdk.coercion)}(this,(function(t,e,n){"use strict"; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function o(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var i=function(){return(i=Object.assign||function t(e){for(var n,r=1,o=arguments.length;r<o;r++)for(var i in n=arguments[r])Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i]);return e}).apply(this,arguments)};function u(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){t.done?o(t.value):new n((function(e){e(t.value)})).then(u,s)}c((r=r.apply(t,e||[])).next())}))}function s(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function c(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=(o=u.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function c(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u}function a(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(c(arguments[e]));return t} /** * @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 l=function(t){function r(){var e=null!==t&&t.apply(this,arguments)||this;return e._documentRootLocator=e.documentRootLocatorFactory(),e}return o(r,t),r.with=function(t){return void 0===t&&(t={}),new e.HarnessPredicate(r,t).addOption("triggerText",t.triggerText,(function(t,n){return e.HarnessPredicate.stringMatches(t.getTriggerText(),n)}))},r.prototype.isDisabled=function(){return u(this,void 0,void 0,(function(){var t,e;return s(this,(function(r){switch(r.label){case 0:return[4,this.host()];case 1:return t=r.sent().getAttribute("disabled"),e=n.coerceBooleanProperty,[4,t];case 2:return[2,e.apply(void 0,[r.sent()])]}}))}))},r.prototype.isOpen=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this._getMenuPanel()];case 1:return[2,!!t.sent()]}}))}))},r.prototype.getTriggerText=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().text()]}}))}))},r.prototype.focus=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().focus()]}}))}))},r.prototype.blur=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().blur()]}}))}))},r.prototype.open=function(){return u(this,void 0,void 0,(function(){return s(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]}}))}))},r.prototype.close=function(){return u(this,void 0,void 0,(function(){var t;return s(this,(function(n){switch(n.label){case 0:return[4,this._getMenuPanel()];case 1:return(t=n.sent())?[2,t.sendKeys(e.TestKey.ESCAPE)]:[2]}}))}))},r.prototype.getItems=function(t){return void 0===t&&(t={}),u(this,void 0,void 0,(function(){var e;return s(this,(function(n){switch(n.label){case 0:return[4,this._getPanelId()];case 1:return(e=n.sent())?[2,this._documentRootLocator.locatorForAll(h.with(i(i({},t),{ancestor:"#"+e})))()]:[2,[]]}}))}))},r.prototype.clickItem=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];return u(this,void 0,void 0,(function(){var n,r;return s(this,(function(o){switch(o.label){case 0:return[4,this.open()];case 1:return o.sent(),[4,this.getItems(t)];case 2:if(!(n=o.sent()).length)throw Error("Could not find item matching "+JSON.stringify(t));return e.length?[3,4]:[4,n[0].click()];case 3:return[2,o.sent()];case 4:return[4,n[0].getSubmenu()];case 5:if(!(r=o.sent()))throw Error("Item matching "+JSON.stringify(t)+" does not have a submenu");return[2,r.clickItem.apply(r,a(e))]}}))}))},r.prototype._getMenuPanel=function(){return u(this,void 0,void 0,(function(){var t;return s(this,(function(e){switch(e.label){case 0:return[4,this._getPanelId()];case 1:return[2,(t=e.sent())?this._documentRootLocator.locatorForOptional("#"+t)():null]}}))}))},r.prototype._getPanelId=function(){return u(this,void 0,void 0,(function(){return s(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]}}))}))},r.hostSelector=".mat-menu-trigger",r}(e.ComponentHarness),h=function(t){function r(){return null!==t&&t.apply(this,arguments)||this}return o(r,t),r.with=function(t){var n=this;return void 0===t&&(t={}),new e.HarnessPredicate(r,t).addOption("text",t.text,(function(t,n){return e.HarnessPredicate.stringMatches(t.getText(),n)})).addOption("hasSubmenu",t.hasSubmenu,(function(t,e){return u(n,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:return[4,t.hasSubmenu()];case 1:return[2,n.sent()===e]}}))}))}))},r.prototype.isDisabled=function(){return u(this,void 0,void 0,(function(){var t,e;return s(this,(function(r){switch(r.label){case 0:return[4,this.host()];case 1:return t=r.sent().getAttribute("disabled"),e=n.coerceBooleanProperty,[4,t];case 2:return[2,e.apply(void 0,[r.sent()])]}}))}))},r.prototype.getText=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().text()]}}))}))},r.prototype.focus=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().focus()]}}))}))},r.prototype.blur=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().blur()]}}))}))},r.prototype.click=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().click()]}}))}))},r.prototype.hasSubmenu=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.host()];case 1:return[2,t.sent().matchesSelector(l.hostSelector)]}}))}))},r.prototype.getSubmenu=function(){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.hasSubmenu()];case 1:return t.sent()?[2,new l(this.locatorFactory)]:[2,null]}}))}))},r.hostSelector=".mat-menu-item",r}(e.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=l,t.MatMenuItemHarness=h,Object.defineProperty(t,"__esModule",{value:!0})}));