How to use manager method in localstack

Best Python code snippet using localstack_python

addNewMember.js

Source:addNewMember.js Github

copy

Full Screen

1import React, { Component } from "react";2import { reduxForm, Field, change as changeField } from "redux-form";3const {4 defaultConfig: { PLATFORM, LOCATION },5} = require(`../../../../../../config/default`);6const {7 DatePickerInput,8} = require(`../../../../../../components/${PLATFORM}/atoms/date-picker`);9const {10 getCountryData,11} = require(`../../../../../../helpers/${PLATFORM}/prepare-country-related-data`);12const {13 Select,14} = require(`../../../../../../components/${PLATFORM}/atoms/select`);15const {16 Input,17} = require(`../../../../../../components/${PLATFORM}/atoms/input`);18const {19 STRINGS,20} = require(`../../../../../../shared/${PLATFORM}/constants/${LOCATION}/strings`);21const {22 VALIDATION_MESSAGES,23 EMAIL_REGX,24 NAME_REGX,25 REFERENCE_REGX,26 PHONE_REGX,27} = require(`../../../../../../shared/${PLATFORM}/constants`);28const {29 getPhoneValid,30} = require(`../../../../../../helpers/${PLATFORM}/getPhoneValid`);31const {32 getCountryPrefix,33} = require(`../../../../../../helpers/${PLATFORM}/getCountryPrefix`);34let data = getCountryData();35let callingCodes = data.callingCodes;36let countries = data.nations;37let getCountry;38let number;39export default class addNewMember extends Component {40 constructor(props) {41 super(props);42 this.state = {43 branchManagerData: {44 email: "",45 password: "",46 confirmPassword: "",47 name: "",48 surname: "",49 dob: "",50 city: "",51 country: "",52 phoneCode: "",53 phoneNo: "",54 },55 branchManagerDataValidation: {56 email: "",57 password: "",58 confirmPassword: "",59 name: "",60 dob: "",61 city: "",62 country: "",63 phoneCode: "",64 phoneNo: "",65 },66 };67 }68 branchManagarValidate = () => {69 let validation = true;70 let number;71 const {72 email,73 password,74 confirmPassword,75 name,76 dob,77 city,78 country,79 phoneCode,80 phoneNo,81 } = this.state.branchManagerData;82 if (!email) {83 this.setState({84 branchManagerDataValidation: Object.assign(85 this.state.branchManagerDataValidation,86 { email: VALIDATION_MESSAGES.EMAIL_REQUIRED }87 ),88 });89 validation = false;90 }91 if (!password) {92 this.setState({93 branchManagerDataValidation: Object.assign(94 this.state.branchManagerDataValidation,95 { password: VALIDATION_MESSAGES.PASSWORD_REQUIRED }96 ),97 });98 validation = false;99 }100 if (!confirmPassword) {101 this.setState({102 branchManagerDataValidation: Object.assign(103 this.state.branchManagerDataValidation,104 { confirmPassword: VALIDATION_MESSAGES.PASSWORD_REQUIRED }105 ),106 });107 validation = false;108 }109 if (!name) {110 this.setState({111 branchManagerDataValidation: Object.assign(112 this.state.branchManagerDataValidation,113 { name: VALIDATION_MESSAGES.NAME_REQUIRED }114 ),115 });116 validation = false;117 }118 if (!(name && name.trim && name.trim())) {119 this.setState({120 branchManagerDataValidation: Object.assign(121 this.state.branchManagerDataValidation,122 { name: VALIDATION_MESSAGES.NAME_REQUIRED }123 ),124 });125 validation = false;126 }127 if (!dob) {128 this.setState({129 branchManagerDataValidation: Object.assign(130 this.state.branchManagerDataValidation,131 { dob: VALIDATION_MESSAGES.DOB_REQUIRED }132 ),133 });134 validation = false;135 }136 if (!city) {137 this.setState({138 branchManagerDataValidation: Object.assign(139 this.state.branchManagerDataValidation,140 { city: VALIDATION_MESSAGES.CITY_REQUIRED }141 ),142 });143 validation = false;144 }145 if (!(city && city.trim && city.trim())) {146 this.setState({147 branchManagerDataValidation: Object.assign(148 this.state.branchManagerDataValidation,149 { city: VALIDATION_MESSAGES.CITY_REQUIRED }150 ),151 });152 validation = false;153 }154 if (!country) {155 this.setState({156 branchManagerDataValidation: Object.assign(157 this.state.branchManagerDataValidation,158 { country: VALIDATION_MESSAGES.COUNTRY_REQUIRED }159 ),160 });161 validation = false;162 }163 if (!phoneCode) {164 this.setState({165 branchManagerDataValidation: Object.assign(166 this.state.branchManagerDataValidation,167 { phoneCode: VALIDATION_MESSAGES.PHONE_CODE_KEY_REQUIRED }168 ),169 });170 validation = false;171 }172 if (!phoneNo) {173 this.setState({174 branchManagerDataValidation: Object.assign(175 this.state.branchManagerDataValidation,176 { phoneNo: VALIDATION_MESSAGES.PHONE_NUMBER_REQUIRED }177 ),178 });179 validation = false;180 }181 if (!dob) {182 this.setState({183 branchManagerDataValidation: Object.assign(184 this.state.branchManagerDataValidation,185 { dob: VALIDATION_MESSAGES.DOB_REQUIRED }186 ),187 });188 validation = false;189 }190 Object.values(this.state.branchManagerDataValidation).find(191 (item, index) => {192 if (!!item) {193 validation = false;194 }195 }196 );197 return validation;198 };199 validatePhoneNumber(country) {200 if (country && this.state.branchManagerData.phoneNo) {201 number = getPhoneValid(this.state.branchManagerData.phoneNo, getCountry);202 if (number && number === "invalid") {203 this.setState({204 branchManagerDataValidation: {205 ...this.state.branchManagerDataValidation,206 phoneNo: VALIDATION_MESSAGES.INVALID_NUMBER_FOR_COUNTRY,207 },208 });209 } else {210 this.setState({211 branchManagerDataValidation: {212 ...this.state.branchManagerDataValidation,213 phoneNo: false,214 },215 });216 }217 }218 }219 render() {220 const maxDate = new Date();221 const { modalVisibility, onAddNewMember } = this.props;222 return (223 <div id="myModal" className="modal">224 <div className={`modal-content`}>225 <div226 className="modal_body"227 onClick={(e) => {228 e.stopPropagation();229 }}230 >231 <span232 className="close"233 onClick={() => {234 this.setState({235 addBranchManger: false,236 branchManagerData: {237 email: "",238 password: "",239 confirmPassword: "",240 name: "",241 surname: "",242 role: "",243 dob: "",244 city: "",245 country: "",246 phoneCode: "",247 phoneNo: "",248 },249 branchManagerDataValidation: {250 email: "",251 password: "",252 confirmPassword: "",253 name: "",254 surname: "",255 role: "",256 dob: "",257 city: "",258 country: "",259 phoneCode: "",260 phoneNo: "",261 },262 });263 modalVisibility();264 }}265 >266 &times;267 </span>268 <form>269 <h5 className="mb-3">{"Add new member"}</h5>270 <div className="form-row">271 <div className="col-sm-6">272 <Field273 name={STRINGS.BRANCH_MANAGER_EMAIL}274 component={Input}275 placeholder={STRINGS.EMAIL}276 onBlur={() => {277 if (!this.state.branchManagerData.email) {278 this.setState({279 branchManagerDataValidation: {280 ...this.state.branchManagerDataValidation,281 email: VALIDATION_MESSAGES.EMAIL_REQUIRED,282 },283 });284 } else if (285 !EMAIL_REGX.test(this.state.branchManagerData.email)286 ) {287 this.setState({288 branchManagerDataValidation: {289 ...this.state.branchManagerDataValidation,290 email: VALIDATION_MESSAGES.EMAIL_IS_NOT_VALID,291 },292 });293 }294 }}295 meta={{296 error: this.state.branchManagerDataValidation.email,297 touched:298 this.state.branchManagerDataValidation.email && true,299 }}300 config={{301 value: this.state.branchManagerData.email,302 onChange: (value) => {303 this.setState(304 {305 branchManagerData: {306 ...this.state.branchManagerData,307 email: value.target.value,308 },309 },310 () => {311 if (312 !EMAIL_REGX.test(313 this.state.branchManagerData.email314 )315 ) {316 this.setState({317 branchManagerDataValidation: {318 ...this.state.branchManagerDataValidation,319 email: VALIDATION_MESSAGES.EMAIL_IS_NOT_VALID,320 },321 });322 }323 if (!this.state.branchManagerData.email) {324 this.setState({325 branchManagerDataValidation: {326 ...this.state.branchManagerDataValidation,327 email: VALIDATION_MESSAGES.EMAIL_REQUIRED,328 },329 });330 }331 if (332 EMAIL_REGX.test(333 this.state.branchManagerData.email334 ) &&335 this.state.branchManagerData.email336 ) {337 this.setState({338 branchManagerDataValidation: {339 ...this.state.branchManagerDataValidation,340 email: false,341 },342 });343 }344 }345 );346 },347 type: "email",348 }}349 />350 </div>351 <div className="col-sm-6">352 <Field353 asterisk={true}354 name={STRINGS.BRANCH_MANAGER_DOB}355 component={DatePickerInput}356 placeholder={STRINGS.DOB_PLACEHOLDER}357 onBlur={() => {358 if (!this.state.branchManagerData.dob) {359 this.setState({360 branchManagerDataValidation: {361 ...this.state.branchManagerDataValidation,362 dob: VALIDATION_MESSAGES.DOB_REQUIRED,363 },364 });365 }366 }}367 maxDate={maxDate.setFullYear(maxDate.getFullYear() - 16)}368 meta={{369 error: this.state.branchManagerDataValidation.dob,370 touched:371 this.state.branchManagerDataValidation.dob && true,372 }}373 config={{374 value: this.state.branchManagerData.dob,375 onChange: (value) => {376 let val;377 this.setState(378 {379 branchManagerData: {380 ...this.state.branchManagerData,381 dob: value,382 },383 },384 () => {385 if (this.state.branchManagerData.dob) {386 this.setState({387 branchManagerDataValidation: {388 ...this.state.branchManagerDataValidation,389 dob: false,390 },391 });392 } else {393 this.setState({394 branchManagerDataValidation: {395 ...this.state.branchManagerDataValidation,396 dob: VALIDATION_MESSAGES.DOB_REQUIRED,397 },398 });399 }400 }401 );402 },403 }}404 />405 </div>406 </div>407 <div className="form-row">408 <div className="col-sm-6">409 <Field410 name={STRINGS.BRANCH_MANAGER_PASSWORD}411 component={Input}412 placeholder={STRINGS.PASSWORD_LABEL}413 meta={{414 error: this.state.branchManagerDataValidation.password,415 touched:416 this.state.branchManagerDataValidation.password && true,417 }}418 config={{419 value: this.state.branchManagerData.password,420 type: "password",421 maxLength: 15,422 onBlur: (e) => {423 e.preventDefault();424 if (!this.state.branchManagerData.password) {425 this.setState({426 branchManagerDataValidation: {427 ...this.state.branchManagerDataValidation,428 password: VALIDATION_MESSAGES.PASSWORD_REQUIRED,429 },430 });431 }432 },433 onChange: (evt) => {434 this.setState(435 {436 branchManagerData: {437 ...this.state.branchManagerData,438 password: evt.target.value,439 },440 },441 () => {442 if (!this.state.branchManagerData.password) {443 this.setState({444 branchManagerDataValidation: {445 ...this.state.branchManagerDataValidation,446 password:447 VALIDATION_MESSAGES.PASSWORD_REQUIRED,448 },449 });450 } else if (451 this.state.branchManagerData.password.toString()452 .length < 6453 ) {454 this.setState({455 branchManagerDataValidation: {456 ...this.state.branchManagerDataValidation,457 password:458 VALIDATION_MESSAGES.PASSWORD_MINLENGTH,459 },460 });461 } else if (462 this.state.branchManagerData.confirmPassword &&463 this.state.branchManagerData.confirmPassword !==464 this.state.branchManagerData.password465 ) {466 this.setState({467 branchManagerDataValidation: {468 ...this.state.branchManagerDataValidation,469 confirmPassword:470 VALIDATION_MESSAGES.PASSWORDS_DO_NOT_MATCH,471 },472 });473 } else {474 this.setState({475 branchManagerDataValidation: {476 ...this.state.branchManagerDataValidation,477 password: false,478 confirmPassword: false,479 },480 });481 }482 }483 );484 },485 }}486 />487 </div>488 <div className="col-sm-6">489 <Field490 name={STRINGS.CONFIRM_PASSWORD}491 component={Input}492 placeholder={STRINGS.RE_ENTER_PASSWORD}493 maxLength={15}494 meta={{495 error: this.state.branchManagerDataValidation496 .confirmPassword,497 touched:498 this.state.branchManagerDataValidation499 .confirmPassword && true,500 }}501 config={{502 value: this.state.branchManagerData.confirmPassword,503 type: "password",504 maxLength: 15,505 onBlur: (e) => {506 e.preventDefault();507 if (!this.state.branchManagerData.confirmPassword) {508 this.setState({509 branchManagerDataValidation: {510 ...this.state.branchManagerDataValidation,511 confirmPassword:512 VALIDATION_MESSAGES.PASSWORD_REQUIRED,513 },514 });515 } else if (516 this.state.branchManagerData.password !==517 this.state.branchManagerData.confirmPassword518 ) {519 this.setState({520 branchManagerDataValidation: {521 ...this.state.branchManagerDataValidation,522 confirmPassword:523 VALIDATION_MESSAGES.PASSWORDS_DO_NOT_MATCH,524 },525 });526 }527 },528 onChange: (evt) => {529 this.setState(530 {531 branchManagerData: {532 ...this.state.branchManagerData,533 confirmPassword: evt.target.value,534 },535 },536 () => {537 if (!this.state.branchManagerData.confirmPassword) {538 this.setState({539 branchManagerDataValidation: {540 ...this.state.branchManagerDataValidation,541 confirmPassword:542 VALIDATION_MESSAGES.PASSWORD_REQUIRED,543 },544 });545 } else if (546 this.state.branchManagerData.password !==547 this.state.branchManagerData.confirmPassword548 ) {549 this.setState({550 branchManagerDataValidation: {551 ...this.state.branchManagerDataValidation,552 confirmPassword:553 VALIDATION_MESSAGES.PASSWORDS_DO_NOT_MATCH,554 },555 });556 } else {557 this.setState({558 branchManagerDataValidation: {559 ...this.state.branchManagerDataValidation,560 confirmPassword: false,561 },562 });563 }564 }565 );566 },567 }}568 />569 </div>570 </div>571 <div className="form-row">572 <div className="col-sm-6">573 <Field574 name={STRINGS.MEMBER_CITY_INPUT}575 component={Input}576 placeholder={STRINGS.CITY}577 type={"text"}578 onBlur={() => {579 if (!this.state.branchManagerData.city) {580 this.setState({581 branchManagerDataValidation: {582 ...this.state.branchManagerDataValidation,583 city: VALIDATION_MESSAGES.CITY_REQUIRED,584 },585 });586 }587 }}588 meta={{589 error: this.state.branchManagerDataValidation.city,590 touched:591 this.state.branchManagerDataValidation.city && true,592 }}593 config={{594 value: this.state.branchManagerData.city,595 onChange: (value) => {596 if (NAME_REGX.test(value.target.value)) {597 this.setState(598 {599 branchManagerData: {600 ...this.state.branchManagerData,601 city: value.target.value,602 },603 },604 () => {605 if (!this.state.branchManagerData.city) {606 this.setState({607 branchManagerDataValidation: {608 ...this.state.branchManagerDataValidation,609 city: VALIDATION_MESSAGES.CITY_REQUIRED,610 },611 });612 } else {613 this.setState({614 branchManagerDataValidation: {615 ...this.state.branchManagerDataValidation,616 city: false,617 },618 });619 }620 }621 );622 } else if (value.target.value === "") {623 this.setState(624 {625 branchManagerData: {626 ...this.state.branchManagerData,627 city: value.target.value,628 },629 },630 () => {631 if (!this.state.branchManagerData.city) {632 this.setState({633 branchManagerDataValidation: {634 ...this.state.branchManagerDataValidation,635 city: VALIDATION_MESSAGES.CITY_REQUIRED,636 },637 });638 } else {639 this.setState({640 branchManagerDataValidation: {641 ...this.state.branchManagerDataValidation,642 city: false,643 },644 });645 }646 }647 );648 }649 },650 }}651 />652 </div>653 <div className="col-sm-6">654 <Field655 name={STRINGS.MEMBER_COUNTRY_INPUT}656 component={Select}657 placeholder={STRINGS.COUNTRY}658 // type={'text'}659 options={countries}660 isSearchable={true}661 meta={{662 error: this.state.branchManagerDataValidation.country,663 touched:664 this.state.branchManagerDataValidation.country && true,665 }}666 config={{667 value: this.state.branchManagerData.country,668 onBlur: (e) => {669 e.preventDefault();670 if (!this.state.branchManagerData.country) {671 this.setState({672 branchManagerDataValidation: {673 ...this.state.branchManagerDataValidation,674 country: VALIDATION_MESSAGES.COUNTRY_REQUIRED,675 },676 });677 }678 },679 onChange: (value) => {680 this.setState(681 {682 branchManagerData: {683 ...this.state.branchManagerData,684 country: value,685 phoneCode: value,686 },687 },688 () => {689 const { country } = this.state.branchManagerData;690 let requiredIndex;691 for (692 let index = 0;693 index < callingCodes.length;694 index++695 ) {696 let position = callingCodes[index].label.indexOf(697 country && country.value698 );699 if (position !== -1) {700 requiredIndex = index;701 break;702 }703 }704 if (country) {705 this.setState({706 branchManagerData: {707 ...this.state.branchManagerData,708 phoneCode: callingCodes[requiredIndex],709 },710 });711 let getCode = callingCodes[requiredIndex];712 if (getCode && getCode.value && getCode.label) {713 var code = getCode.value.replace("+", "");714 var label = getCode.label.split("(")[0];715 label = label.split(getCode.value)[1];716 getCountry = getCountryPrefix(717 code.trim(),718 label.trim()719 );720 }721 }722 if (this.state.branchManagerData.country) {723 this.setState(724 {725 branchManagerDataValidation: {726 ...this.state.branchManagerDataValidation,727 country: false,728 phoneCode: false,729 },730 },731 () => {732 this.validatePhoneNumber(getCountry);733 }734 );735 } else {736 this.setState({737 branchManagerDataValidation: {738 ...this.state.branchManagerDataValidation,739 country: VALIDATION_MESSAGES.COUNTRY_REQUIRED,740 },741 });742 }743 }744 );745 },746 }}747 />748 </div>749 </div>750 <div className="form-row">751 <div className="col-sm-6">752 <Field753 name={STRINGS.MEMBER_PHONE_KEY_INPUT}754 component={Select}755 options={callingCodes}756 isSearchable={true}757 placeholder={STRINGS.PHONE_NUMBER_PLACEHOLDER}758 meta={{759 error: this.state.branchManagerDataValidation.phoneCode,760 touched:761 this.state.branchManagerDataValidation.phoneCode &&762 true,763 }}764 config={{765 value: this.state.branchManagerData.phoneCode,766 onBlur: (e) => {767 e.preventDefault();768 if (!this.state.branchManagerData.phoneCode) {769 this.setState({770 branchManagerDataValidation: {771 ...this.state.branchManagerDataValidation,772 phoneCode:773 VALIDATION_MESSAGES.PHONE_CODE_KEY_REQUIRED,774 },775 });776 }777 },778 onChange: (value) => {779 this.setState(780 {781 branchManagerData: {782 ...this.state.branchManagerData,783 phoneCode: value,784 },785 },786 () => {787 if (this.state.branchManagerData.phoneCode) {788 this.setState(789 {790 branchManagerDataValidation: {791 ...this.state.branchManagerDataValidation,792 phoneCode: false,793 },794 },795 () => {796 let getCode = value;797 if (798 getCode &&799 getCode.value &&800 getCode.label801 ) {802 var code = getCode.value.replace("+", "");803 var label = getCode.label.split("(")[0];804 label = label.split(getCode.value)[1];805 getCountry = getCountryPrefix(806 code.trim(),807 label.trim()808 );809 }810 this.validatePhoneNumber(getCountry);811 }812 );813 } else {814 this.setState({815 branchManagerDataValidation: {816 ...this.state.branchManagerDataValidation,817 phoneCode:818 VALIDATION_MESSAGES.PHONE_CODE_KEY_REQUIRED,819 },820 });821 }822 }823 );824 },825 }}826 />827 </div>828 <div className="col-sm-6">829 <Field830 name={STRINGS.MEMBER_PHONE_INPUT}831 component={Input}832 placeholder={STRINGS.PHONE_NO}833 onBlur={() => {834 if (!this.state.branchManagerData.phoneNo) {835 this.setState({836 branchManagerDataValidation: {837 ...this.state.branchManagerDataValidation,838 phoneNo: VALIDATION_MESSAGES.PHONE_NUMBER_REQUIRED,839 },840 });841 } else {842 this.validatePhoneNumber(getCountry);843 }844 }}845 meta={{846 error: this.state.branchManagerDataValidation.phoneNo,847 touched:848 this.state.branchManagerDataValidation.phoneNo && true,849 }}850 config={{851 value: this.state.branchManagerData.phoneNo,852 onChange: (value) => {853 if (PHONE_REGX.test(value.target.value)) {854 this.setState(855 {856 branchManagerData: {857 ...this.state.branchManagerData,858 phoneNo: value.target.value,859 },860 },861 () => {862 if (!this.state.branchManagerData.phoneNo) {863 this.setState({864 branchManagerDataValidation: {865 ...this.state.branchManagerDataValidation,866 phoneNo:867 VALIDATION_MESSAGES.PHONE_NUMBER_REQUIRED,868 },869 });870 } else if (871 this.state.branchManagerData.phoneNo.toString()872 .length < 7 ||873 this.state.branchManagerData.phoneNo.toString()874 .length > 15875 ) {876 this.setState({877 branchManagerDataValidation: {878 ...this.state.branchManagerDataValidation,879 phoneNo:880 VALIDATION_MESSAGES.PHONE_NUMBER_CHARACTER_LENGTH,881 },882 });883 }884 // else if (this.state.branchManagerData.phoneNo.toString().length > 3 && this.state.branchManagerData.phoneNo.toString().length < 18) {885 // this.setState({886 // branchManagerDataValidation: { ...this.state.branchManagerDataValidation, phoneNo: false }887 // }, () => {888 // this.validatePhoneNumber(getCountry)889 // })890 // }891 else {892 this.setState(893 {894 branchManagerDataValidation: {895 ...this.state.branchManagerDataValidation,896 phoneNo: false,897 },898 },899 () => {900 this.validatePhoneNumber(getCountry);901 }902 );903 }904 }905 );906 } else if (value.target.value === "") {907 this.setState(908 {909 branchManagerData: {910 ...this.state.branchManagerData,911 phoneNo: value.target.value,912 },913 },914 () => {915 if (!this.state.branchManagerData.phoneNo) {916 this.setState({917 branchManagerDataValidation: {918 ...this.state.branchManagerDataValidation,919 phoneNo:920 VALIDATION_MESSAGES.PHONE_NUMBER_REQUIRED,921 },922 });923 } else {924 this.setState({925 branchManagerDataValidation: {926 ...this.state.branchManagerDataValidation,927 phoneNo: false,928 },929 });930 }931 }932 );933 }934 },935 }}936 />937 </div>938 </div>939 <div className="form-row">940 <div className="col-sm-6">941 <Field942 name={STRINGS.MEMBER_NAME_INPUT}943 component={Input}944 placeholder={STRINGS.NAME_PLACEHOLDER}945 type={"text"}946 onBlur={() => {947 if (!this.state.branchManagerData.name) {948 this.setState({949 branchManagerDataValidation: {950 ...this.state.branchManagerDataValidation,951 name: VALIDATION_MESSAGES.NAME_REQUIRED,952 },953 });954 }955 }}956 meta={{957 error: this.state.branchManagerDataValidation.name,958 touched:959 this.state.branchManagerDataValidation.name && true,960 }}961 config={{962 value: this.state.branchManagerData.name,963 onChange: (value) => {964 if (NAME_REGX.test(value.target.value)) {965 this.setState(966 {967 branchManagerData: {968 ...this.state.branchManagerData,969 name: value.target.value,970 },971 },972 () => {973 if (!this.state.branchManagerData.name) {974 this.setState({975 branchManagerDataValidation: {976 ...this.state.branchManagerDataValidation,977 name: VALIDATION_MESSAGES.NAME_REQUIRED,978 },979 });980 } else {981 this.setState({982 branchManagerDataValidation: {983 ...this.state.branchManagerDataValidation,984 name: false,985 },986 });987 }988 }989 );990 } else if (value.target.value === "") {991 this.setState(992 {993 branchManagerData: {994 ...this.state.branchManagerData,995 name: value.target.value,996 },997 },998 () => {999 if (!this.state.branchManagerData.name) {1000 this.setState({1001 branchManagerDataValidation: {1002 ...this.state.branchManagerDataValidation,1003 name: VALIDATION_MESSAGES.NAME_REQUIRED,1004 },1005 });1006 } else {1007 this.setState({1008 branchManagerDataValidation: {1009 ...this.state.branchManagerDataValidation,1010 name: false,1011 },1012 });1013 }1014 }1015 );1016 }1017 },1018 }}1019 />1020 </div>1021 <div className="col-sm-6">1022 <Field1023 name={STRINGS.SURNAME_INPUT}1024 component={Input}1025 placeholder={STRINGS.SURNAME_PLACEHOLDER}1026 type={"text"}1027 meta={{1028 error: this.state.branchManagerDataValidation.surname,1029 touched:1030 this.state.branchManagerDataValidation.surname && true,1031 }}1032 config={{1033 value: this.state.branchManagerData.surname,1034 onChange: (value) => {1035 if (NAME_REGX.test(value.target.value)) {1036 if (!value.target.value.startsWith(" ")) {1037 this.setState({1038 branchManagerData: {1039 ...this.state.branchManagerData,1040 surname: value.target.value,1041 },1042 });1043 }1044 } else if (value.target.value === "") {1045 this.setState({1046 branchManagerData: {1047 ...this.state.branchManagerData,1048 surname: value.target.value,1049 },1050 });1051 }1052 },1053 }}1054 />1055 <span className="text_label">optional</span>1056 </div>1057 </div>1058 <div className="group-btn text-center">1059 <button1060 className="btn btn-lg btn-primary text-capitalize"1061 type={"text"}1062 onClick={(e) => {1063 e.preventDefault();1064 if (this.branchManagarValidate()) {1065 onAddNewMember(this.state.branchManagerData);1066 }1067 }}1068 >1069 Submit1070 </button>1071 </div>1072 </form>1073 </div>1074 </div>1075 </div>1076 );1077 }...

Full Screen

Full Screen

dependency_manager_unittest.py

Source:dependency_manager_unittest.py Github

copy

Full Screen

1# Copyright 2015 The Chromium Authors. All rights reserved.2# Use of this source code is governed by a BSD-style license that can be3# found in the LICENSE file.4# pylint: disable=unused-argument5import mock6from pyfakefs import fake_filesystem_unittest7from py_utils import cloud_storage8import dependency_manager9from dependency_manager import exceptions10class DependencyManagerTest(fake_filesystem_unittest.TestCase):11 def setUp(self):12 self.lp_info012 = dependency_manager.LocalPathInfo(13 ['path0', 'path1', 'path2'])14 self.cloud_storage_info = dependency_manager.CloudStorageInfo(15 'cs_bucket', 'cs_hash', 'download_path', 'cs_remote_path')16 self.dep_info = dependency_manager.DependencyInfo(17 'dep', 'platform', 'config_file', local_path_info=self.lp_info012,18 cloud_storage_info=self.cloud_storage_info)19 self.setUpPyfakefs()20 def tearDown(self):21 self.tearDownPyfakefs()22 # TODO(nednguyen): add a test that construct23 # dependency_manager.DependencyManager from a list of DependencyInfo.24 def testErrorInit(self):25 with self.assertRaises(ValueError):26 dependency_manager.DependencyManager(None)27 with self.assertRaises(ValueError):28 dependency_manager.DependencyManager('config_file?')29 def testInitialUpdateDependencies(self):30 dep_manager = dependency_manager.DependencyManager([])31 # Empty BaseConfig.32 dep_manager._lookup_dict = {}33 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)34 base_config_mock.IterDependencyInfo.return_value = iter([])35 dep_manager._UpdateDependencies(base_config_mock)36 self.assertFalse(dep_manager._lookup_dict)37 # One dependency/platform in a BaseConfig.38 dep_manager._lookup_dict = {}39 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)40 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)41 dep = 'dependency'42 plat = 'platform'43 dep_info.dependency = dep44 dep_info.platform = plat45 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])46 expected_lookup_dict = {dep: {plat: dep_info}}47 dep_manager._UpdateDependencies(base_config_mock)48 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)49 self.assertFalse(dep_info.Update.called)50 # One dependency multiple platforms in a BaseConfig.51 dep_manager._lookup_dict = {}52 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)53 dep = 'dependency'54 plat1 = 'platform1'55 plat2 = 'platform2'56 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)57 dep_info1.dependency = dep58 dep_info1.platform = plat159 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)60 dep_info2.dependency = dep61 dep_info2.platform = plat262 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,63 dep_info2])64 expected_lookup_dict = {dep: {plat1: dep_info1,65 plat2: dep_info2}}66 dep_manager._UpdateDependencies(base_config_mock)67 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)68 self.assertFalse(dep_info1.Update.called)69 self.assertFalse(dep_info2.Update.called)70 # Multiple dependencies, multiple platforms in a BaseConfig.71 dep_manager._lookup_dict = {}72 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)73 dep1 = 'dependency1'74 dep2 = 'dependency2'75 plat1 = 'platform1'76 plat2 = 'platform2'77 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)78 dep_info1.dependency = dep179 dep_info1.platform = plat180 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)81 dep_info2.dependency = dep182 dep_info2.platform = plat283 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)84 dep_info3.dependency = dep285 dep_info3.platform = plat286 base_config_mock.IterDependencyInfo.return_value = iter(87 [dep_info1, dep_info2, dep_info3])88 expected_lookup_dict = {dep1: {plat1: dep_info1,89 plat2: dep_info2},90 dep2: {plat2: dep_info3}}91 dep_manager._UpdateDependencies(base_config_mock)92 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)93 self.assertFalse(dep_info1.Update.called)94 self.assertFalse(dep_info2.Update.called)95 self.assertFalse(dep_info3.Update.called)96 def testFollowupUpdateDependenciesNoOverlap(self):97 dep_manager = dependency_manager.DependencyManager([])98 dep = 'dependency'99 dep1 = 'dependency1'100 dep2 = 'dependency2'101 dep3 = 'dependency3'102 plat1 = 'platform1'103 plat2 = 'platform2'104 plat3 = 'platform3'105 dep_info_a = mock.MagicMock(spec=dependency_manager.DependencyInfo)106 dep_info_a.dependency = dep1107 dep_info_a.platform = plat1108 dep_info_b = mock.MagicMock(spec=dependency_manager.DependencyInfo)109 dep_info_b.dependency = dep1110 dep_info_b.platform = plat2111 dep_info_c = mock.MagicMock(spec=dependency_manager.DependencyInfo)112 dep_info_c.dependency = dep113 dep_info_c.platform = plat1114 start_lookup_dict = {dep: {plat1: dep_info_a,115 plat2: dep_info_b},116 dep1: {plat1: dep_info_c}}117 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)118 # Empty BaseConfig.119 dep_manager._lookup_dict = start_lookup_dict.copy()120 base_config_mock.IterDependencyInfo.return_value = iter([])121 dep_manager._UpdateDependencies(base_config_mock)122 self.assertEqual(start_lookup_dict, dep_manager._lookup_dict)123 # One dependency/platform in a BaseConfig.124 dep_manager._lookup_dict = start_lookup_dict.copy()125 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)126 dep_info.dependency = dep3127 dep_info.platform = plat1128 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])129 expected_lookup_dict = {dep: {plat1: dep_info_a,130 plat2: dep_info_b},131 dep1: {plat1: dep_info_c},132 dep3: {plat3: dep_info}}133 dep_manager._UpdateDependencies(base_config_mock)134 self.assertItemsEqual(expected_lookup_dict, dep_manager._lookup_dict)135 self.assertFalse(dep_info.Update.called)136 self.assertFalse(dep_info_a.Update.called)137 self.assertFalse(dep_info_b.Update.called)138 self.assertFalse(dep_info_c.Update.called)139 # One dependency multiple platforms in a BaseConfig.140 dep_manager._lookup_dict = start_lookup_dict.copy()141 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)142 dep_info1.dependency = dep2143 dep_info1.platform = plat1144 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)145 dep_info2.dependency = dep2146 dep_info2.platform = plat2147 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,148 dep_info2])149 expected_lookup_dict = {dep: {plat1: dep_info_a,150 plat2: dep_info_b},151 dep1: {plat1: dep_info_c},152 dep2: {plat1: dep_info1,153 plat2: dep_info2}}154 dep_manager._UpdateDependencies(base_config_mock)155 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)156 self.assertFalse(dep_info1.Update.called)157 self.assertFalse(dep_info2.Update.called)158 self.assertFalse(dep_info_a.Update.called)159 self.assertFalse(dep_info_b.Update.called)160 self.assertFalse(dep_info_c.Update.called)161 # Multiple dependencies, multiple platforms in a BaseConfig.162 dep_manager._lookup_dict = start_lookup_dict.copy()163 dep1 = 'dependency1'164 plat1 = 'platform1'165 plat2 = 'platform2'166 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)167 dep_info1.dependency = dep2168 dep_info1.platform = plat1169 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)170 dep_info2.dependency = dep2171 dep_info2.platform = plat2172 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)173 dep_info3.dependency = dep3174 dep_info3.platform = plat2175 base_config_mock.IterDependencyInfo.return_value = iter(176 [dep_info1, dep_info2, dep_info3])177 expected_lookup_dict = {dep: {plat1: dep_info_a,178 plat2: dep_info_b},179 dep1: {plat1: dep_info_c},180 dep2: {plat1: dep_info1,181 plat2: dep_info2},182 dep3: {plat2: dep_info3}}183 dep_manager._UpdateDependencies(base_config_mock)184 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)185 self.assertFalse(dep_info1.Update.called)186 self.assertFalse(dep_info2.Update.called)187 self.assertFalse(dep_info3.Update.called)188 self.assertFalse(dep_info_a.Update.called)189 self.assertFalse(dep_info_b.Update.called)190 self.assertFalse(dep_info_c.Update.called)191 # Ensure the testing data wasn't corrupted.192 self.assertEqual(start_lookup_dict,193 {dep: {plat1: dep_info_a,194 plat2: dep_info_b},195 dep1: {plat1: dep_info_c}})196 def testFollowupUpdateDependenciesWithCollisions(self):197 dep_manager = dependency_manager.DependencyManager([])198 dep = 'dependency'199 dep1 = 'dependency1'200 dep2 = 'dependency2'201 plat1 = 'platform1'202 plat2 = 'platform2'203 dep_info_a = mock.MagicMock(spec=dependency_manager.DependencyInfo)204 dep_info_a.dependency = dep1205 dep_info_a.platform = plat1206 dep_info_b = mock.MagicMock(spec=dependency_manager.DependencyInfo)207 dep_info_b.dependency = dep1208 dep_info_b.platform = plat2209 dep_info_c = mock.MagicMock(spec=dependency_manager.DependencyInfo)210 dep_info_c.dependency = dep211 dep_info_c.platform = plat1212 start_lookup_dict = {dep: {plat1: dep_info_a,213 plat2: dep_info_b},214 dep1: {plat1: dep_info_c}}215 base_config_mock = mock.MagicMock(spec=dependency_manager.BaseConfig)216 # One dependency/platform.217 dep_manager._lookup_dict = start_lookup_dict.copy()218 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)219 dep_info.dependency = dep220 dep_info.platform = plat1221 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])222 expected_lookup_dict = {dep: {plat1: dep_info_a,223 plat2: dep_info_b},224 dep1: {plat1: dep_info_c}}225 dep_manager._UpdateDependencies(base_config_mock)226 self.assertItemsEqual(expected_lookup_dict, dep_manager._lookup_dict)227 dep_info_a.Update.assert_called_once_with(dep_info)228 self.assertFalse(dep_info.Update.called)229 self.assertFalse(dep_info_b.Update.called)230 self.assertFalse(dep_info_c.Update.called)231 dep_info_a.reset_mock()232 dep_info_b.reset_mock()233 dep_info_c.reset_mock()234 # One dependency multiple platforms in a BaseConfig.235 dep_manager._lookup_dict = start_lookup_dict.copy()236 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)237 dep_info1.dependency = dep1238 dep_info1.platform = plat1239 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)240 dep_info2.dependency = dep2241 dep_info2.platform = plat2242 base_config_mock.IterDependencyInfo.return_value = iter([dep_info1,243 dep_info2])244 expected_lookup_dict = {dep: {plat1: dep_info_a,245 plat2: dep_info_b},246 dep1: {plat1: dep_info_c},247 dep2: {plat2: dep_info2}}248 dep_manager._UpdateDependencies(base_config_mock)249 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)250 self.assertFalse(dep_info1.Update.called)251 self.assertFalse(dep_info2.Update.called)252 self.assertFalse(dep_info_a.Update.called)253 self.assertFalse(dep_info_b.Update.called)254 dep_info_c.Update.assert_called_once_with(dep_info1)255 dep_info_a.reset_mock()256 dep_info_b.reset_mock()257 dep_info_c.reset_mock()258 # Multiple dependencies, multiple platforms in a BaseConfig.259 dep_manager._lookup_dict = start_lookup_dict.copy()260 dep1 = 'dependency1'261 plat1 = 'platform1'262 plat2 = 'platform2'263 dep_info1 = mock.MagicMock(spec=dependency_manager.DependencyInfo)264 dep_info1.dependency = dep265 dep_info1.platform = plat1266 dep_info2 = mock.MagicMock(spec=dependency_manager.DependencyInfo)267 dep_info2.dependency = dep1268 dep_info2.platform = plat1269 dep_info3 = mock.MagicMock(spec=dependency_manager.DependencyInfo)270 dep_info3.dependency = dep2271 dep_info3.platform = plat2272 base_config_mock.IterDependencyInfo.return_value = iter(273 [dep_info1, dep_info2, dep_info3])274 expected_lookup_dict = {dep: {plat1: dep_info_a,275 plat2: dep_info_b},276 dep1: {plat1: dep_info_c},277 dep2: {plat2: dep_info3}}278 dep_manager._UpdateDependencies(base_config_mock)279 self.assertEqual(expected_lookup_dict, dep_manager._lookup_dict)280 self.assertFalse(dep_info1.Update.called)281 self.assertFalse(dep_info2.Update.called)282 self.assertFalse(dep_info3.Update.called)283 self.assertFalse(dep_info_b.Update.called)284 dep_info_a.Update.assert_called_once_with(dep_info1)285 dep_info_c.Update.assert_called_once_with(dep_info2)286 # Collision error.287 dep_manager._lookup_dict = start_lookup_dict.copy()288 dep_info = mock.MagicMock(spec=dependency_manager.DependencyInfo)289 dep_info.dependency = dep290 dep_info.platform = plat1291 base_config_mock.IterDependencyInfo.return_value = iter([dep_info])292 dep_info_a.Update.side_effect = ValueError293 self.assertRaises(ValueError,294 dep_manager._UpdateDependencies, base_config_mock)295 # Ensure the testing data wasn't corrupted.296 self.assertEqual(start_lookup_dict,297 {dep: {plat1: dep_info_a,298 plat2: dep_info_b},299 dep1: {plat1: dep_info_c}})300 def testGetDependencyInfo(self):301 dep_manager = dependency_manager.DependencyManager([])302 self.assertFalse(dep_manager._lookup_dict)303 # No dependencies in the dependency manager.304 self.assertEqual(None, dep_manager._GetDependencyInfo('missing_dep',305 'missing_plat'))306 dep_manager._lookup_dict = {'dep1': {'plat1': 'dep_info11',307 'plat2': 'dep_info12',308 'plat3': 'dep_info13'},309 'dep2': {'plat1': 'dep_info11',310 'plat2': 'dep_info21',311 'plat3': 'dep_info23',312 'default': 'dep_info2d'},313 'dep3': {'plat1': 'dep_info31',314 'plat2': 'dep_info32',315 'default': 'dep_info3d'}}316 # Dependency not in the dependency manager.317 self.assertEqual(None, dep_manager._GetDependencyInfo(318 'missing_dep', 'missing_plat'))319 # Dependency in the dependency manager, but not the platform. No default.320 self.assertEqual(None, dep_manager._GetDependencyInfo(321 'dep1', 'missing_plat'))322 # Dependency in the dependency manager, but not the platform, but a default323 # exists.324 self.assertEqual('dep_info2d', dep_manager._GetDependencyInfo(325 'dep2', 'missing_plat'))326 # Dependency and platform in the dependency manager. A default exists.327 self.assertEqual('dep_info23', dep_manager._GetDependencyInfo(328 'dep2', 'plat3'))329 # Dependency and platform in the dependency manager. No default exists.330 self.assertEqual('dep_info12', dep_manager._GetDependencyInfo(331 'dep1', 'plat2'))332 @mock.patch(333 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long334 def testFetchPathUnititializedDependency(335 self, cs_path_mock):336 dep_manager = dependency_manager.DependencyManager([])337 self.assertFalse(cs_path_mock.call_args)338 cs_path = 'cs_path'339 cs_path_mock.return_value = cs_path340 # Empty lookup_dict341 with self.assertRaises(exceptions.NoPathFoundError):342 dep_manager.FetchPath('dep', 'plat_arch_x86')343 # Non-empty lookup dict that doesn't contain the dependency we're looking344 # for.345 dep_manager._lookup_dict = {'dep1': mock.MagicMock(),346 'dep2': mock.MagicMock()}347 with self.assertRaises(exceptions.NoPathFoundError):348 dep_manager.FetchPath('dep', 'plat_arch_x86')349 @mock.patch('os.path')350 @mock.patch(351 'dependency_manager.DependencyManager._GetDependencyInfo')352 @mock.patch(353 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long354 def testFetchPathLocalFile(self, cs_path_mock, dep_info_mock, path_mock):355 dep_manager = dependency_manager.DependencyManager([])356 self.assertFalse(cs_path_mock.call_args)357 cs_path = 'cs_path'358 dep_info = self.dep_info359 cs_path_mock.return_value = cs_path360 # The DependencyInfo returned should be passed through to LocalPath.361 dep_info_mock.return_value = dep_info362 # Non-empty lookup dict that contains the dependency we're looking for.363 # Local path exists.364 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info},365 'dep2': mock.MagicMock()}366 self.fs.CreateFile('path1')367 found_path = dep_manager.FetchPath('dep', 'platform')368 self.assertEqual('path1', found_path)369 self.assertFalse(cs_path_mock.call_args)370 @mock.patch(371 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long372 def testFetchPathRemoteFile(373 self, cs_path_mock):374 dep_manager = dependency_manager.DependencyManager([])375 self.assertFalse(cs_path_mock.call_args)376 cs_path = 'cs_path'377 def FakeCSPath():378 self.fs.CreateFile(cs_path)379 return cs_path380 cs_path_mock.side_effect = FakeCSPath381 # Non-empty lookup dict that contains the dependency we're looking for.382 # Local path doesn't exist, but cloud_storage_path is downloaded.383 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info,384 'plat1': mock.MagicMock()},385 'dep2': {'plat2': mock.MagicMock()}}386 found_path = dep_manager.FetchPath('dep', 'platform')387 self.assertEqual(cs_path, found_path)388 @mock.patch(389 'dependency_manager.dependency_info.DependencyInfo.GetRemotePath') # pylint: disable=line-too-long390 def testFetchPathError(391 self, cs_path_mock):392 dep_manager = dependency_manager.DependencyManager([])393 self.assertFalse(cs_path_mock.call_args)394 cs_path_mock.return_value = None395 dep_manager._lookup_dict = {'dep': {'platform' : self.dep_info,396 'plat1': mock.MagicMock()},397 'dep2': {'plat2': mock.MagicMock()}}398 # Non-empty lookup dict that contains the dependency we're looking for.399 # Local path doesn't exist, and cloud_storage path wasn't successfully400 # found.401 self.assertRaises(exceptions.NoPathFoundError,402 dep_manager.FetchPath, 'dep', 'platform')403 cs_path_mock.side_effect = cloud_storage.CredentialsError404 self.assertRaises(cloud_storage.CredentialsError,405 dep_manager.FetchPath, 'dep', 'platform')406 cs_path_mock.side_effect = cloud_storage.CloudStorageError407 self.assertRaises(cloud_storage.CloudStorageError,408 dep_manager.FetchPath, 'dep', 'platform')409 cs_path_mock.side_effect = cloud_storage.PermissionError410 self.assertRaises(cloud_storage.PermissionError,411 dep_manager.FetchPath, 'dep', 'platform')412 def testLocalPath(self):413 dep_manager = dependency_manager.DependencyManager([])414 # Empty lookup_dict415 with self.assertRaises(exceptions.NoPathFoundError):416 dep_manager.LocalPath('dep', 'plat')417 def testLocalPathNoDependency(self):418 # Non-empty lookup dict that doesn't contain the dependency we're looking419 # for.420 dep_manager = dependency_manager.DependencyManager([])421 dep_manager._lookup_dict = {'dep1': mock.MagicMock(),422 'dep2': mock.MagicMock()}423 with self.assertRaises(exceptions.NoPathFoundError):424 dep_manager.LocalPath('dep', 'plat')425 def testLocalPathExists(self):426 # Non-empty lookup dict that contains the dependency we're looking for.427 # Local path exists.428 dep_manager = dependency_manager.DependencyManager([])429 dep_manager._lookup_dict = {'dependency' : {'platform': self.dep_info},430 'dep1': mock.MagicMock(),431 'dep2': mock.MagicMock()}432 self.fs.CreateFile('path1')433 found_path = dep_manager.LocalPath('dependency', 'platform')434 self.assertEqual('path1', found_path)435 def testLocalPathMissingPaths(self):436 # Non-empty lookup dict that contains the dependency we're looking for.437 # Local path is found but doesn't exist.438 dep_manager = dependency_manager.DependencyManager([])439 dep_manager._lookup_dict = {'dependency' : {'platform': self.dep_info},440 'dep1': mock.MagicMock(),441 'dep2': mock.MagicMock()}442 self.assertRaises(exceptions.NoPathFoundError,443 dep_manager.LocalPath, 'dependency', 'platform')444 def testLocalPathNoPaths(self):445 # Non-empty lookup dict that contains the dependency we're looking for.446 # Local path isn't found.447 dep_manager = dependency_manager.DependencyManager([])448 dep_info = dependency_manager.DependencyInfo(449 'dep', 'platform', 'config_file',450 cloud_storage_info=self.cloud_storage_info)451 dep_manager._lookup_dict = {'dependency' : {'platform': dep_info},452 'dep1': mock.MagicMock(),453 'dep2': mock.MagicMock()}454 self.assertRaises(exceptions.NoPathFoundError,...

Full Screen

Full Screen

UndoManager.js

Source:UndoManager.js Github

copy

Full Screen

1import {expect, assert} from 'chai';2import UndoManager from '../../../src/store/undo/UndoManager';3import SectionManager from '../../../src/store/undo/SectionManager';4describe('Store', () => {5 describe('Undo', () => {6 describe('UndoManager', () => {7 const manager = new UndoManager();8 const makeDummyAction = () => ({ type: 'someType', data: false });9 const keyA = 'A';10 const stateA1 = { first: 'A' };11 const stateA2 = { second: 'A' };12 const stateA3 = { third: 'A' };13 const stateA4 = { fourth: 'A' };14 const sectionManagerA = new SectionManager(stateA1);15 manager.register(keyA, sectionManagerA);16 const keyB = 'B';17 const stateB1 = { first: 'B' };18 const stateB2 = { second: 'B' };19 const stateB3 = { third: 'B' };20 const stateB4 = { fourth: 'B' };21 const sectionManagerB = new SectionManager(stateB1);22 manager.register(keyB, sectionManagerB);23 it('patch(key, state, action) updates appropriate section by patching, no affect on past', () => {24 manager.patch(keyA, stateA2, makeDummyAction());25 expect(sectionManagerA.getCurrentState()).to.eql(stateA2);26 expect(sectionManagerA.getPast()).to.eql([]);27 expect(sectionManagerB.getCurrentState()).to.eql(stateB1);28 expect(manager.getLastHistoryItem()).to.eql(null);29 });30 it('insert(key, state, action) updates appropriate section by inserting, adds to past', () => {31 const action = makeDummyAction();32 //STATE - first insert33 manager.insert(keyB, stateB2, action);34 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);35 expect(sectionManagerB.getPast()).to.eql([stateB1]);36 expect(sectionManagerA.getCurrentState()).to.eql(stateA2);37 const lastItem = manager.getLastHistoryItem();38 expect(lastItem.keys[0]).to.equal(keyB);39 expect(lastItem.action).to.equal(action);40 });41 it('insert() updates past by key', () => {42 //STATE - second insert43 manager.insert(keyA, stateA3, makeDummyAction());44 //STATE - third insert45 manager.insert(keyB, stateB3, makeDummyAction());46 expect(sectionManagerA.getPast()).to.eql([stateA2]);47 expect(sectionManagerA.getCurrentState()).to.eql(stateA3);48 expect(sectionManagerB.getPast()).to.eql([stateB1, stateB2]);49 expect(sectionManagerB.getCurrentState()).to.eql(stateB3);50 expect(manager.past.map(item => item.keys[0])).to.eql([keyB, keyA, keyB]);51 });52 it('undo() goes in order by key', () => {53 //STATE - undo54 manager.undo(makeDummyAction());55 expect(manager.past.length).to.equal(2);56 expect(sectionManagerA.getPast()).to.eql([stateA2]);57 expect(sectionManagerA.getCurrentState()).to.eql(stateA3);58 expect(sectionManagerB.getPast()).to.eql([stateB1]);59 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);60 expect(sectionManagerB.getFuture()).to.eql([stateB3]);61 });62 it('undo() only runs once per action', () => {63 //STATE - undo64 const action = makeDummyAction();65 manager.undo(action);66 expect(manager.past.length).to.equal(1);67 expect(sectionManagerA.getPast()).to.eql([]);68 expect(sectionManagerA.getCurrentState()).to.eql(stateA2);69 expect(sectionManagerA.getFuture()).to.eql([stateA3]);70 expect(sectionManagerB.getPast()).to.eql([stateB1]);71 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);72 expect(sectionManagerB.getFuture()).to.eql([stateB3]);73 manager.undo(action);74 //same tests as chunk above75 expect(manager.past.length).to.equal(1);76 expect(sectionManagerA.getPast()).to.eql([]);77 expect(sectionManagerA.getCurrentState()).to.eql(stateA2);78 expect(sectionManagerA.getFuture()).to.eql([stateA3]);79 expect(sectionManagerB.getPast()).to.eql([stateB1]);80 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);81 expect(sectionManagerB.getFuture()).to.eql([stateB3]);82 });83 it('getUndoState() gives number of past and future state across all sections', () => {84 const { past, future } = manager.getUndoState();85 expect(past).to.equal(1);86 expect(future).to.equal(2);87 });88 it('redo()', () => {89 //STATE - redo90 manager.redo(makeDummyAction());91 expect(manager.past.length).to.equal(2);92 expect(sectionManagerA.getPast()).to.eql([stateA2]);93 expect(sectionManagerA.getCurrentState()).to.eql(stateA3);94 expect(sectionManagerB.getPast()).to.eql([stateB1]);95 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);96 expect(sectionManagerB.getFuture()).to.eql([stateB3]);97 });98 it('purge() clears history of all sectionManagers', () => {99 manager.purge(makeDummyAction());100 expect(sectionManagerA.getPast()).to.eql([]);101 expect(sectionManagerA.getCurrentState()).to.eql(stateA3);102 expect(sectionManagerA.getFuture()).to.eql([]);103 expect(sectionManagerB.getPast()).to.eql([]);104 expect(sectionManagerB.getCurrentState()).to.eql(stateB2);105 expect(sectionManagerB.getFuture()).to.eql([]);106 });107 describe('Transactions', () => {108 it('transact() sets all sectionManagers to transacting', () => {109 //init check110 expect(sectionManagerA.inTransaction()).to.equal(false);111 expect(sectionManagerB.inTransaction()).to.equal(false);112 manager.transact(makeDummyAction());113 expect(sectionManagerA.inTransaction()).to.equal(true);114 expect(sectionManagerB.inTransaction()).to.equal(true);115 });116 it('commit() commits all sections', () => {117 //init check118 expect(sectionManagerA.inTransaction()).to.equal(true);119 expect(sectionManagerB.inTransaction()).to.equal(true);120 const pastA = sectionManagerA.getPast();121 const presentA = sectionManagerA.getPresent();122 const futureA = sectionManagerA.getFuture();123 const pastB = sectionManagerB.getPast();124 const presentB = sectionManagerB.getPresent();125 const futureB = sectionManagerB.getFuture();126 manager.patch(keyA, stateA4, makeDummyAction());127 //dont insert anything on patch128 expect(manager.getLastHistoryItem()).to.eql(null);129 manager.insert(keyB, stateB4, makeDummyAction());130 //add this key to the undo keys for the last transaction131 expect(manager.getLastHistoryItem().keys).to.eql([keyB]);132 expect(sectionManagerA.getPast()).to.eql(pastA);133 expect(sectionManagerA.getPresent()).to.eql(presentA);134 expect(sectionManagerA.getCurrentState()).to.eql(stateA4);135 expect(sectionManagerA.getFuture()).to.eql(futureA);136 expect(sectionManagerB.getPast()).to.eql(pastB);137 expect(sectionManagerB.getPresent()).to.eql(presentB);138 expect(sectionManagerB.getCurrentState()).to.eql(stateB4);139 expect(sectionManagerB.getFuture()).to.eql(futureB);140 manager.commit(makeDummyAction());141 expect(sectionManagerA.getPast()).to.eql([...pastA, presentA]);142 expect(sectionManagerA.getPresent()).to.eql(stateA4);143 expect(sectionManagerA.getCurrentState()).to.eql(stateA4);144 expect(sectionManagerA.getFuture()).to.eql([]);145 expect(sectionManagerB.getPast()).to.eql([...pastB, presentB]);146 expect(sectionManagerB.getPresent()).to.eql(stateB4);147 expect(sectionManagerB.getCurrentState()).to.eql(stateB4);148 expect(sectionManagerB.getFuture()).to.eql([]);149 expect(manager.getLastHistoryItem().keys).to.eql([keyB]);150 });151 it('abort() aborts all sections', () => {152 //init check153 expect(sectionManagerA.inTransaction()).to.equal(false);154 expect(sectionManagerB.inTransaction()).to.equal(false);155 manager.transact(makeDummyAction());156 expect(sectionManagerA.inTransaction()).to.equal(true);157 expect(sectionManagerB.inTransaction()).to.equal(true);158 manager.abort(makeDummyAction());159 expect(sectionManagerA.inTransaction()).to.equal(false);160 expect(sectionManagerB.inTransaction()).to.equal(false);161 });162 });163 });164 });...

Full Screen

Full Screen

SectionManager.spec.js

Source:SectionManager.spec.js Github

copy

Full Screen

1import {expect, assert} from 'chai';2import SectionManager from '../../../src/store/undo/SectionManager';3describe('Store', () => {4 describe('Undo', () => {5 describe('SectionManager', () => {6 const initialState = { state: 'value' };7 const stateA = { state: 'A' };8 const stateB = { state: 'B', newVal: 'B' };9 const stateC = { state: 'C' };10 const manager = new SectionManager(initialState);11 it('constructor() creates initial state for present', () => {12 const present = manager.getPresent();13 expect(present).to.eql(initialState);14 expect(manager.getPast()).to.eql([]);15 expect(manager.getFuture()).to.eql([]);16 expect(manager.inTransaction()).to.equal(false);17 });18 it('patch() updates present, no nodes created', () => {19 manager.patch(stateA);20 expect(manager.getPresent()).to.eql(stateA);21 expect(manager.getPast()).to.eql([]);22 });23 it('getCurrentState() returns present state (not in a transaction)', () => {24 expect(manager.getCurrentState()).to.eql(stateA);25 expect(manager.getCurrentState()).to.eql(manager.getPresent());26 });27 it('insert() creates a history node', () => {28 manager.insert(stateB);29 expect(manager.getPresent()).to.eql(stateB);30 expect(manager.getPast()).to.eql([stateA]);31 });32 it('insert() ignores identical state to present', () => {33 manager.insert(stateB);34 expect(manager.getPresent()).to.eql(stateB);35 expect(manager.getPast()).to.eql([stateA]);36 });37 it('undo() goes back a step, updates present + future', () => {38 manager.undo();39 expect(manager.getPast()).to.eql([]);40 expect(manager.getPresent()).to.eql(stateA);41 expect(manager.getFuture()).to.eql([stateB]);42 });43 it('redo() goes forward a step, updates present + past', () => {44 manager.redo();45 expect(manager.getPast()).to.eql([stateA]);46 expect(manager.getPresent()).to.eql(stateB);47 expect(manager.getFuture()).to.eql([]);48 });49 describe('Transactions', () => {50 let preState; //dont set until this block runs51 const txnStateAlt = { state: 'txn alt' };52 const txnState = { state: 'transacting' };53 it('transact() starts a transaction, doesnt change current state', () => {54 preState = manager.getCurrentState();55 expect(manager.inTransaction()).to.equal(false);56 manager.transact();57 expect(manager.inTransaction()).to.equal(true);58 expect(manager.getPresent()).to.eql(preState);59 expect(manager.getCurrentState()).to.eql(preState);60 });61 it('patch() updates transactionState, not present', () => {62 expect(manager.inTransaction()).to.equal(true);63 manager.patch(txnStateAlt);64 expect(manager.inTransaction()).to.equal(true);65 expect(manager.getPresent()).to.eql(preState);66 expect(manager.getCurrentState()).to.eql(txnStateAlt);67 });68 it('insert() updates transactionState, not present', () => {69 manager.insert(txnState);70 expect(manager.inTransaction()).to.equal(true);71 expect(manager.getPresent()).to.eql(preState);72 expect(manager.getCurrentState()).to.eql(txnState);73 });74 it('commit() sets present to transaction state', () => {75 manager.commit();76 expect(manager.inTransaction()).to.equal(false);77 expect(manager.getPresent()).to.eql(txnState);78 expect(manager.getCurrentState()).to.eql(manager.getPresent());79 expect(manager.getPast().slice().pop()).to.eql(preState);80 });81 it('commit() does nothing when no changes in transaction, maintains reference', () => {82 const beforeState = manager.getPresent();83 manager.transact();84 manager.commit();85 expect(manager.getPresent()).to.equal(beforeState);86 });87 it('abort() leaves the present state, ends transaction', () => {88 const beforeState = manager.getCurrentState();89 const beforePastLength = manager.getPast().length;90 manager.transact();91 manager.patch(txnStateAlt);92 expect(manager.getCurrentState()).to.eql(txnStateAlt);93 manager.abort();94 expect(manager.inTransaction()).to.equal(false);95 expect(manager.getCurrentState()).to.eql(beforeState);96 expect(manager.getCurrentState()).to.eql(manager.getPresent());97 expect(manager.getPast().length).to.eql(beforePastLength);98 });99 it('supports nested transactions, only commit when all succeed', () => {100 expect(manager.inTransaction()).to.equal(false);101 manager.transact();102 expect(manager.inTransaction()).to.equal(true);103 manager.transact();104 expect(manager.inTransaction()).to.equal(true);105 manager.commit();106 expect(manager.inTransaction()).to.equal(true);107 manager.commit();108 expect(manager.inTransaction()).to.equal(false);109 });110 it('nested transactions only succeed when no aborts', () => {111 expect(manager.inTransaction()).to.equal(false);112 const beforeState = manager.getPresent();113 const tempState = { state: 'temp' };114 manager.transact();115 expect(manager.inTransaction()).to.equal(true);116 manager.transact();117 expect(manager.inTransaction()).to.equal(true);118 manager.patch(tempState);119 manager.commit();120 expect(manager.inTransaction()).to.equal(true);121 manager.abort();122 expect(manager.inTransaction()).to.equal(false);123 expect(manager.getCurrentState()).to.eql(beforeState);124 expect(manager.getCurrentState()).to.eql(manager.getPresent());125 });126 it('commit() outside transaction is idempotent', () => {127 expect(manager.commit).to.not.throw();128 });129 it('undo() in transaction ends transaction', () => {130 expect(manager.inTransaction()).to.equal(false);131 manager.transact();132 expect(manager.inTransaction()).to.equal(true);133 manager.undo();134 expect(manager.inTransaction()).to.equal(false);135 manager.commit();136 expect(manager.inTransaction()).to.equal(false);137 });138 });139 });140 });...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful