UNPKG

@angular/material

Version:
23 lines 8.51 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("tslib"),require("@angular/cdk/coercion"),require("@angular/cdk/testing")):"function"==typeof define&&define.amd?define("@angular/material/radio/testing",["exports","tslib","@angular/cdk/coercion","@angular/cdk/testing"],e):e(((t=t||self).ng=t.ng||{},t.ng.material=t.ng.material||{},t.ng.material.radio=t.ng.material.radio||{},t.ng.material.radio.testing={}),t.tslib,t.ng.cdk.coercion,t.ng.cdk.testing)}(this,(function(t,e,r,n){"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 r(){return null!==t&&t.apply(this,arguments)||this}return e.__extends(r,t),r.with=function(t){return void 0===t&&(t={}),new n.HarnessPredicate(r,t).addOption("name",t.name,this._checkRadioGroupName)},r.prototype.getName=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,r;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this._getGroupNameFromHost()];case 1:return null!==(t=e.sent())?[2,t]:[4,this._getNamesFromRadioButtons()];case 2:if(!(r=e.sent()).length)return[2,null];if(!this._checkRadioNamesInGroupEqual(r))throw Error("Radio buttons in radio-group have mismatching names.");return[2,r[0]]}}))}))},r.prototype.getId=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().getProperty("id")]}}))}))},r.prototype.getCheckedRadioButton=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,r,n,i,o,a;return e.__generator(this,(function(u){switch(u.label){case 0:return u.trys.push([0,6,7,8]),[4,this.getRadioButtons()];case 1:t=e.__values.apply(void 0,[u.sent()]),r=t.next(),u.label=2;case 2:return r.done?[3,5]:[4,(n=r.value).isChecked()];case 3:if(u.sent())return[2,n];u.label=4;case 4:return r=t.next(),[3,2];case 5:return[3,8];case 6:return i=u.sent(),o={error:i},[3,8];case 7:try{r&&!r.done&&(a=t.return)&&a.call(t)}finally{if(o)throw o.error}return[7];case 8:return[2,null]}}))}))},r.prototype.getCheckedValue=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.getCheckedRadioButton()];case 1:return(t=e.sent())?[2,t.getValue()]:[2,null]}}))}))},r.prototype.getRadioButtons=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(e){return[2,this.locatorForAll(o.with(t))()]}))}))},r.prototype.checkRadioButton=function(t){return void 0===t&&(t={}),e.__awaiter(this,void 0,void 0,(function(){var r;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,this.getRadioButtons(t)];case 1:if(!(r=e.sent()).length)throw Error("Could not find radio button matching "+JSON.stringify(t));return[2,r[0].check()]}}))}))},r.prototype._getGroupNameFromHost=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().getAttribute("name")]}}))}))},r.prototype._getNamesFromRadioButtons=function(){return e.__awaiter(this,void 0,void 0,(function(){var t,r,n,i,o,a,u;return e.__generator(this,(function(s){switch(s.label){case 0:t=[],s.label=1;case 1:return s.trys.push([1,7,8,9]),[4,this.getRadioButtons()];case 2:r=e.__values.apply(void 0,[s.sent()]),n=r.next(),s.label=3;case 3:return n.done?[3,6]:[4,n.value.getName()];case 4:null!==(i=s.sent())&&t.push(i),s.label=5;case 5:return n=r.next(),[3,3];case 6:return[3,9];case 7:return o=s.sent(),a={error:o},[3,9];case 8:try{n&&!n.done&&(u=r.return)&&u.call(r)}finally{if(a)throw a.error}return[7];case 9:return[2,t]}}))}))},r.prototype._checkRadioNamesInGroupEqual=function(t){var r,n,i=null;try{for(var o=e.__values(t),a=o.next();!a.done;a=o.next()){var u=a.value;if(null===i)i=u;else if(i!==u)return!1}}catch(t){r={error:t}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}return!0},r._checkRadioGroupName=function(t,r){return e.__awaiter(this,void 0,void 0,(function(){var n;return e.__generator(this,(function(e){switch(e.label){case 0:return[4,t._getGroupNameFromHost()];case 1:return e.sent()===r?[2,!0]:[4,t._getNamesFromRadioButtons()];case 2:if(-1===(n=e.sent()).indexOf(r))return[2,!1];if(!t._checkRadioNamesInGroupEqual(n))throw Error('The locator found a radio-group with name "'+r+"\", but some radio-button's within the group have mismatching names, which is invalid.");return[2,!0]}}))}))},r.hostSelector="mat-radio-group",r}(n.ComponentHarness),o=function(t){function i(){var e=null!==t&&t.apply(this,arguments)||this;return e._textLabel=e.locatorFor(".mat-radio-label-content"),e._clickLabel=e.locatorFor(".mat-radio-label"),e._input=e.locatorFor("input"),e}return e.__extends(i,t),i.with=function(t){var r=this;return void 0===t&&(t={}),new n.HarnessPredicate(i,t).addOption("label",t.label,(function(t,e){return n.HarnessPredicate.stringMatches(t.getLabelText(),e)})).addOption("name",t.name,(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.getName()];case 1:return[2,e.sent()===n]}}))}))}))},i.prototype.isChecked=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._input()];case 1:return t=e.sent().getProperty("checked"),n=r.coerceBooleanProperty,[4,t];case 2:return[2,n.apply(void 0,[e.sent()])]}}))}))},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._input()];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.isRequired=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._input()];case 1:return t=e.sent().getAttribute("required"),n=r.coerceBooleanProperty,[4,t];case 2:return[2,n.apply(void 0,[e.sent()])]}}))}))},i.prototype.getName=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this._input()];case 1:return[2,t.sent().getAttribute("name")]}}))}))},i.prototype.getId=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().getProperty("id")]}}))}))},i.prototype.getValue=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this._input()];case 1:return[2,t.sent().getProperty("value")]}}))}))},i.prototype.getLabelText=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this._textLabel()];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._input()];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._input()];case 1:return[2,t.sent().blur()]}}))}))},i.prototype.check=function(){return e.__awaiter(this,void 0,void 0,(function(){return e.__generator(this,(function(t){switch(t.label){case 0:return[4,this.isChecked()];case 1:return t.sent()?[3,3]:[4,this._clickLabel()];case 2:return[2,t.sent().click()];case 3:return[2]}}))}))},i.hostSelector="mat-radio-button",i}(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.MatRadioButtonHarness=o,t.MatRadioGroupHarness=i,Object.defineProperty(t,"__esModule",{value:!0})}));