UNPKG

@angular/material

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