UNPKG

@angular/cdk

Version:

Angular Material Component Development Kit

69 lines 13.6 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("tslib"),require("@angular/cdk/testing"),require("@angular/core/testing"),require("rxjs/operators"),require("rxjs"),require("@angular/cdk/keycodes")):"function"==typeof define&&define.amd?define("@angular/cdk/testing/testbed",["exports","tslib","@angular/cdk/testing","@angular/core/testing","rxjs/operators","rxjs","@angular/cdk/keycodes"],t):t(((e=e||self).ng=e.ng||{},e.ng.cdk=e.ng.cdk||{},e.ng.cdk.testing=e.ng.cdk.testing||{},e.ng.cdk.testing.testbed={}),e.tslib,e.ng.cdk.testing,e.ng.core.testing,e.rxjs.operators,e.rxjs,e.ng.cdk.keycodes)}(this,(function(e,t,n,r,i,o,s){"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 a,u=Symbol("ProxyZone_PATCHED#stateObservable"),c=function(){function e(e){this._lastState=e,this._stateSubject=new o.BehaviorSubject(this._lastState?this._getTaskStateFromInternalZoneState(this._lastState):{stable:!0}),this.state=this._stateSubject.asObservable()}return e.prototype.onHasTask=function(e,t,n,r){t===n&&this._stateSubject.next(this._getTaskStateFromInternalZoneState(r))},e.prototype._getTaskStateFromInternalZoneState=function(e){return{stable:!e.macroTask&&!e.microTask}},e.setup=function(){if(void 0===Zone)throw Error("Could not find ZoneJS. For test harnesses running in TestBed, ZoneJS needs to be installed.");var n=Zone.ProxyZoneSpec;if(!n)throw Error("ProxyZoneSpec is needed for the test harnesses but could not be found. Please make sure that your environment includes zone.js/dist/zone-testing.js");var r=n.assertPresent();if(r[u])return r[u];var i=new e(r.lastTaskState),o=r.onHasTask.bind(r);return r.onHasTask=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];o.apply(void 0,t.__spread(e)),i.onHasTask.apply(i,t.__spread(e))},r[u]=i.state},e}(); /** * @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 */ function l(e,t){return e.dispatchEvent(t),t}function d(e,t,n){return l(e,function r(e,t,n){void 0===t&&(t=!1),void 0===n&&(n=!0);var r=document.createEvent("Event");return r.initEvent(e,t,n),r}(t,n))}function y(e,t,n,r,i,o){return l(e,function s(e,t,n,r,i){void 0===t&&(t=0),void 0===n&&(n=""),void 0===i&&(i={});var o=document.createEvent("KeyboardEvent"),s=o.preventDefault;if(o.initKeyEvent)o.initKeyEvent(e,!0,!0,window,i.control,i.alt,i.shift,i.meta,t);else{var a=(i.control?"Control ":""+i.alt?"Alt ":""+i.shift?"Shift ":""+i.meta?"Meta":"").trim();o.initKeyboardEvent(e,!0,!0,window,0,n,0,a,!1)}return Object.defineProperties(o,{keyCode:{get:function(){return t}},key:{get:function(){return n}},target:{get:function(){return r}},ctrlKey:{get:function(){return!!i.control}},altKey:{get:function(){return!!i.alt}},shiftKey:{get:function(){return!!i.shift}},metaKey:{get:function(){return!!i.meta}}}),o.preventDefault=function(){return Object.defineProperty(o,"defaultPrevented",{get:function(){return!0}}),s.apply(this,arguments)},o}(t,n,r,i,o))}function f(e,t,n,r,i){return void 0===n&&(n=0),void 0===r&&(r=0),void 0===i&&(i= /** * @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 */ function o(e,t,n,r){void 0===t&&(t=0),void 0===n&&(n=0),void 0===r&&(r=0);var i=document.createEvent("MouseEvent"),o=i.preventDefault.bind(i);return i.initMouseEvent(e,!0,!0,window,0,t,n,t,n,!1,!1,!1,!1,r,null),Object.defineProperty(i,"buttons",{get:function(){return 1}}),i.preventDefault=function(){return Object.defineProperty(i,"defaultPrevented",{get:function(){return!0}}),o()},i}(t,n,r)),l(e,i)} /** * @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 */ function h(e,t){var n=!1,r=function(){return n=!0};e.addEventListener(t,r),e[t](),e.removeEventListener(t,r),n||d(e,t)}function _(e){h(e,"focus")} /** * @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 */ function v(e){var t=e.nodeName.toLowerCase();return"input"===t||"textarea"===t}function k(e){for(var n,r,i=[],o=1;o<arguments.length;o++)i[o-1]=arguments[o];var s,a,u=i[0];"string"!=typeof u&&void 0===u.keyCode&&void 0===u.key?(s=u,a=i.slice(1)):(s={},a=i);var c=a.map((function(e){return"string"==typeof e?e.split("").map((function(e){return{keyCode:e.toUpperCase().charCodeAt(0),key:e}})):[e]})).reduce((function(e,t){return e.concat(t)}),[]);_(e);try{for(var l=t.__values(c),f=l.next();!f.done;f=l.next()){var h=f.value;y(e,"keydown",h.keyCode,h.key,e,s),y(e,"keypress",h.keyCode,h.key,e,s),v(e)&&h.key&&1===h.key.length&&(e.value+=h.key,d(e,"input")),y(e,"keyup",h.keyCode,h.key,e,s)}}catch(e){n={error:e}}finally{try{f&&!f.done&&(r=l.return)&&r.call(l)}finally{if(n)throw n.error}}}var p=((a={})[n.TestKey.BACKSPACE]={keyCode:s.BACKSPACE,key:"Backspace"},a[n.TestKey.TAB]={keyCode:s.TAB,key:"Tab"},a[n.TestKey.ENTER]={keyCode:s.ENTER,key:"Enter"},a[n.TestKey.SHIFT]={keyCode:s.SHIFT,key:"Shift"},a[n.TestKey.CONTROL]={keyCode:s.CONTROL,key:"Control"},a[n.TestKey.ALT]={keyCode:s.ALT,key:"Alt"},a[n.TestKey.ESCAPE]={keyCode:s.ESCAPE,key:"Escape"},a[n.TestKey.PAGE_UP]={keyCode:s.PAGE_UP,key:"PageUp"},a[n.TestKey.PAGE_DOWN]={keyCode:s.PAGE_DOWN,key:"PageDown"},a[n.TestKey.END]={keyCode:s.END,key:"End"},a[n.TestKey.HOME]={keyCode:s.HOME,key:"Home"},a[n.TestKey.LEFT_ARROW]={keyCode:s.LEFT_ARROW,key:"ArrowLeft"},a[n.TestKey.UP_ARROW]={keyCode:s.UP_ARROW,key:"ArrowUp"},a[n.TestKey.RIGHT_ARROW]={keyCode:s.RIGHT_ARROW,key:"ArrowRight"},a[n.TestKey.DOWN_ARROW]={keyCode:s.DOWN_ARROW,key:"ArrowDown"},a[n.TestKey.INSERT]={keyCode:s.INSERT,key:"Insert"},a[n.TestKey.DELETE]={keyCode:s.DELETE,key:"Delete"},a[n.TestKey.F1]={keyCode:s.F1,key:"F1"},a[n.TestKey.F2]={keyCode:s.F2,key:"F2"},a[n.TestKey.F3]={keyCode:s.F3,key:"F3"},a[n.TestKey.F4]={keyCode:s.F4,key:"F4"},a[n.TestKey.F5]={keyCode:s.F5,key:"F5"},a[n.TestKey.F6]={keyCode:s.F6,key:"F6"},a[n.TestKey.F7]={keyCode:s.F7,key:"F7"},a[n.TestKey.F8]={keyCode:s.F8,key:"F8"},a[n.TestKey.F9]={keyCode:s.F9,key:"F9"},a[n.TestKey.F10]={keyCode:s.F10,key:"F10"},a[n.TestKey.F11]={keyCode:s.F11,key:"F11"},a[n.TestKey.F12]={keyCode:s.F12,key:"F12"},a[n.TestKey.META]={keyCode:s.META,key:"Meta"},a),g=function(){function e(e,t){this.element=e,this._stabilize=t}return e.prototype.blur=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:return e.sent(),function t(e){h(e,"blur")}(this.element),[4,this._stabilize()];case 2:return e.sent(),[2]}}))}))},e.prototype.clear=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:if(e.sent(),!v(this.element))throw Error("Attempting to clear an invalid element");return function t(e){_(e),e.value="",d(e,"input")} /** * @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 */(this.element),[4,this._stabilize()];case 2:return e.sent(),[2]}}))}))},e.prototype.click=function(e,n){return void 0===e&&(e=0),void 0===n&&(n=0),t.__awaiter(this,void 0,void 0,(function(){var r,i,o,s;return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),r=this.element.getBoundingClientRect(),i=r.top,o=Math.round(r.left+e),s=Math.round(i+n),f(this.element,"mousedown",o,s),f(this.element,"mouseup",o,s),f(this.element,"click",o,s),[4,this._stabilize()];case 2:return t.sent(),[2]}}))}))},e.prototype.focus=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:return e.sent(),_(this.element),[4,this._stabilize()];case 2:return e.sent(),[2]}}))}))},e.prototype.getCssValue=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),[2,getComputedStyle(this.element).getPropertyValue(e)]}}))}))},e.prototype.hover=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:return e.sent(),f(this.element,"mouseenter"),[4,this._stabilize()];case 2:return e.sent(),[2]}}))}))},e.prototype.sendKeys=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return t.__awaiter(this,void 0,void 0,(function(){var n;return t.__generator(this,(function(r){switch(r.label){case 0:return[4,this._stabilize()];case 1:return r.sent(),n=e.map((function(e){return"number"==typeof e?p[e]:e})),k.apply(void 0,t.__spread([this.element],n)),[4,this._stabilize()];case 2:return r.sent(),[2]}}))}))},e.prototype.text=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:return e.sent(),[2,(this.element.textContent||"").trim()]}}))}))},e.prototype.getAttribute=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),[2,this.element.getAttribute(e)]}}))}))},e.prototype.hasClass=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),[2,this.element.classList.contains(e)]}}))}))},e.prototype.getDimensions=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return[4,this._stabilize()];case 1:return e.sent(),[2,this.element.getBoundingClientRect()]}}))}))},e.prototype.getProperty=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),[2,this.element[e]]}}))}))},e.prototype.matchesSelector=function(e){return t.__awaiter(this,void 0,void 0,(function(){var n;return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this._stabilize()];case 1:return t.sent(),[2,((n=Element.prototype).matches||n.msMatchesSelector).call(this.element,e)]}}))}))},e}(),b=function(e){function n(t,n){var r=e.call(this,t)||this;return r._fixture=n,r._destroyed=!1,r._taskState=c.setup(),n.componentRef.onDestroy((function(){return r._destroyed=!0})),r}return t.__extends(n,e),n.loader=function(e){return new n(e.nativeElement,e)},n.documentRootLoader=function(e){return new n(document.body,e)},n.harnessForFixture=function(e,r){return t.__awaiter(this,void 0,void 0,(function(){var i;return t.__generator(this,(function(t){switch(t.label){case 0:return[4,(i=new n(e.nativeElement,e)).forceStabilize()];case 1:return t.sent(),[2,i.createComponentHarness(r,e.nativeElement)]}}))}))},n.prototype.forceStabilize=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:if(this._destroyed)throw Error("Harness is attempting to use a fixture that has already been destroyed.");return this._fixture.detectChanges(),[4,this._fixture.whenStable()];case 1:return e.sent(),[2]}}))}))},n.prototype.waitForTasksOutsideAngular=function(){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(e){switch(e.label){case 0:return Zone.current.get("FakeAsyncTestZoneSpec")&&r.flush(),[4,this._taskState.pipe(i.takeWhile((function(e){return!e.stable}))).toPromise()];case 1:return e.sent(),[2]}}))}))},n.prototype.getDocumentRoot=function(){return document.body},n.prototype.createTestElement=function(e){var t=this;return new g(e,(function(){return t.forceStabilize()}))},n.prototype.createEnvironment=function(e){return new n(e,this._fixture)},n.prototype.getAllRawElements=function(e){return t.__awaiter(this,void 0,void 0,(function(){return t.__generator(this,(function(t){switch(t.label){case 0:return[4,this.forceStabilize()];case 1:return t.sent(),[2,Array.from(this.rawRootElement.querySelectorAll(e))]}}))}))},n}(n.HarnessEnvironment); /** * @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 */ e.TestbedHarnessEnvironment=b,e.UnitTestElement=g,Object.defineProperty(e,"__esModule",{value:!0})}));