How to use provide method in ng-mocks

Best JavaScript code snippet using ng-mocks

inject.spec.js

Source:inject.spec.js Github

copy

Full Screen

1import Vue from 'vue'2import { Observer } from 'core/observer/index'3import { isNative, isObject, hasOwn } from 'core/util/index'4import testObjectOption from '../../../helpers/test-object-option'56describe('Options provide/inject', () => {7 testObjectOption('inject')89 let injected10 const injectedComp = {11 inject: ['foo', 'bar'],12 render () {},13 created () {14 injected = [this.foo, this.bar]15 }16 }1718 beforeEach(() => {19 injected = null20 })2122 it('should work', () => {23 new Vue({24 template: `<child/>`,25 provide: {26 foo: 1,27 bar: false28 },29 components: {30 child: {31 template: `<injected-comp/>`,32 components: {33 injectedComp34 }35 }36 }37 }).$mount()3839 expect(injected).toEqual([1, false])40 })4142 it('should use closest parent', () => {43 new Vue({44 template: `<child/>`,45 provide: {46 foo: 1,47 bar: null48 },49 components: {50 child: {51 provide: {52 foo: 353 },54 template: `<injected-comp/>`,55 components: {56 injectedComp57 }58 }59 }60 }).$mount()6162 expect(injected).toEqual([3, null])63 })6465 it('provide function', () => {66 new Vue({67 template: `<child/>`,68 data: {69 a: 1,70 b: false71 },72 provide () {73 return {74 foo: this.a,75 bar: this.b76 }77 },78 components: {79 child: {80 template: `<injected-comp/>`,81 components: {82 injectedComp83 }84 }85 }86 }).$mount()8788 expect(injected).toEqual([1, false])89 })9091 it('inject with alias', () => {92 const injectAlias = {93 inject: {94 baz: 'foo',95 qux: 'bar'96 },97 render () {},98 created () {99 injected = [this.baz, this.qux]100 }101 }102103 new Vue({104 template: `<child/>`,105 provide: {106 foo: false,107 bar: 2108 },109 components: {110 child: {111 template: `<inject-alias/>`,112 components: {113 injectAlias114 }115 }116 }117 }).$mount()118119 expect(injected).toEqual([false, 2])120 })121122 it('inject before resolving data/props', () => {123 const vm = new Vue({124 provide: {125 foo: 1126 }127 })128129 const child = new Vue({130 parent: vm,131 inject: ['foo'],132 data () {133 return {134 bar: this.foo + 1135 }136 },137 props: {138 baz: {139 default () {140 return this.foo + 2141 }142 }143 }144 })145146 expect(child.foo).toBe(1)147 expect(child.bar).toBe(2)148 expect(child.baz).toBe(3)149 })150151 // GitHub issue #5194152 it('should work with functional', () => {153 new Vue({154 template: `<child/>`,155 provide: {156 foo: 1,157 bar: false158 },159 components: {160 child: {161 functional: true,162 inject: ['foo', 'bar'],163 render (h, context) {164 const { injections } = context165 injected = [injections.foo, injections.bar]166 }167 }168 }169 }).$mount()170171 expect(injected).toEqual([1, false])172 })173174 if (typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys)) {175 it('with Symbol keys', () => {176 const s = Symbol()177 const vm = new Vue({178 template: `<child/>`,179 provide: {180 [s]: 123181 },182 components: {183 child: {184 inject: { s },185 template: `<div>{{ s }}</div>`186 }187 }188 }).$mount()189 expect(vm.$el.textContent).toBe('123')190 })191192 it('should merge symbol provide from mixins (functions)', () => {193 const keyA = Symbol('foo')194 const keyB = Symbol('bar')195196 const mixinA = { provide: () => ({ [keyA]: 'foo' }) }197 const mixinB = { provide: () => ({ [keyB]: 'bar' }) }198 const child = {199 inject: {200 foo: keyA,201 bar: keyB202 },203 template: `<span/>`,204 created () {205 injected = [this.foo, this.bar]206 }207 }208 new Vue({209 mixins: [mixinA, mixinB],210 render (h) {211 return h(child)212 }213 }).$mount()214215 expect(injected).toEqual(['foo', 'bar'])216 })217 }218219 // GitHub issue #5223220 it('should work with reactive array', done => {221 const vm = new Vue({222 template: `<div><child></child></div>`,223 data () {224 return {225 foo: []226 }227 },228 provide () {229 return {230 foo: this.foo231 }232 },233 components: {234 child: {235 inject: ['foo'],236 template: `<span>{{foo.length}}</span>`237 }238 }239 }).$mount()240241 expect(vm.$el.innerHTML).toEqual(`<span>0</span>`)242 vm.foo.push(vm.foo.length)243 vm.$nextTick(() => {244 expect(vm.$el.innerHTML).toEqual(`<span>1</span>`)245 vm.foo.pop()246 vm.$nextTick(() => {247 expect(vm.$el.innerHTML).toEqual(`<span>0</span>`)248 done()249 })250 })251 })252253 it('should extend properly', () => {254 const parent = Vue.extend({255 template: `<span/>`,256 inject: ['foo']257 })258259 const child = parent.extend({260 template: `<span/>`,261 inject: ['bar'],262 created () {263 injected = [this.foo, this.bar]264 }265 })266267 new Vue({268 template: `<div><parent/><child/></div>`,269 provide: {270 foo: 1,271 bar: false272 },273 components: {274 parent,275 child276 }277 }).$mount()278279 expect(injected).toEqual([1, false])280 })281282 it('should merge from mixins properly (objects)', () => {283 const mixinA = { inject: { foo: 'foo' }}284 const mixinB = { inject: { bar: 'bar' }}285 const child = {286 mixins: [mixinA, mixinB],287 template: `<span/>`,288 created () {289 injected = [this.foo, this.bar]290 }291 }292 new Vue({293 provide: { foo: 'foo', bar: 'bar', baz: 'baz' },294 render (h) {295 return h(child)296 }297 }).$mount()298299 expect(injected).toEqual(['foo', 'bar'])300 })301302 it('should merge from mixins properly (arrays)', () => {303 const mixinA = { inject: ['foo'] }304 const mixinB = { inject: ['bar'] }305 const child = {306 mixins: [mixinA, mixinB],307 inject: ['baz'],308 template: `<span/>`,309 created () {310 injected = [this.foo, this.bar, this.baz]311 }312 }313 new Vue({314 provide: { foo: 'foo', bar: 'bar', baz: 'baz' },315 render (h) {316 return h(child)317 }318 }).$mount()319320 expect(injected).toEqual(['foo', 'bar', 'baz'])321 })322323 it('should merge from mixins properly (mix of objects and arrays)', () => {324 const mixinA = { inject: { foo: 'foo' }}325 const mixinB = { inject: ['bar'] }326 const child = {327 mixins: [mixinA, mixinB],328 inject: { qux: 'baz' },329 template: `<span/>`,330 created () {331 injected = [this.foo, this.bar, this.qux]332 }333 }334 new Vue({335 provide: { foo: 'foo', bar: 'bar', baz: 'baz' },336 render (h) {337 return h(child)338 }339 }).$mount()340341 expect(injected).toEqual(['foo', 'bar', 'baz'])342 })343344 it('should warn when injections has been modified', () => {345 const key = 'foo'346 const vm = new Vue({347 provide: {348 foo: 1349 }350 })351352 const child = new Vue({353 parent: vm,354 inject: ['foo']355 })356357 expect(child.foo).toBe(1)358 child.foo = 2359 expect(360 `Avoid mutating an injected value directly since the changes will be ` +361 `overwritten whenever the provided component re-renders. ` +362 `injection being mutated: "${key}"`).toHaveBeenWarned()363 })364365 it('should warn when injections cannot be found', () => {366 const vm = new Vue({})367 new Vue({368 parent: vm,369 inject: ['foo', 'bar'],370 created () {}371 })372 expect(`Injection "foo" not found`).toHaveBeenWarned()373 expect(`Injection "bar" not found`).toHaveBeenWarned()374 })375376 it('should not warn when injections can be found', () => {377 const vm = new Vue({378 provide: {379 foo: 1,380 bar: false,381 baz: undefined382 }383 })384 new Vue({385 parent: vm,386 inject: ['foo', 'bar', 'baz'],387 created () {}388 })389 expect(`Injection "foo" not found`).not.toHaveBeenWarned()390 expect(`Injection "bar" not found`).not.toHaveBeenWarned()391 expect(`Injection "baz" not found`).not.toHaveBeenWarned()392 })393394 it('should not warn when injection key which is not provided is not enumerable', () => {395 const parent = new Vue({ provide: { foo: 1 }})396 const inject = { foo: 'foo' }397 Object.defineProperty(inject, '__ob__', { enumerable: false, value: '__ob__' })398 new Vue({ parent, inject })399 expect(`Injection "__ob__" not found`).not.toHaveBeenWarned()400 })401402 // Github issue #6097403 it('should not warn when injections cannot be found but have default value', () => {404 const vm = new Vue({})405 new Vue({406 parent: vm,407 inject: {408 foo: { default: 1 },409 bar: { default: false },410 baz: { default: undefined }411 },412 created () {413 injected = [this.foo, this.bar, this.baz]414 }415 })416 expect(injected).toEqual([1, false, undefined])417 })418419 it('should support name alias and default together', () => {420 const vm = new Vue({421 provide: {422 FOO: 2423 }424 })425 new Vue({426 parent: vm,427 inject: {428 foo: { from: 'FOO', default: 1 },429 bar: { default: false },430 baz: { default: undefined }431 },432 created () {433 injected = [this.foo, this.bar, this.baz]434 }435 })436 expect(injected).toEqual([2, false, undefined])437 })438439 it('should use provided value even if inject has default', () => {440 const vm = new Vue({441 provide: {442 foo: 1,443 bar: false,444 baz: undefined445 }446 })447 new Vue({448 parent: vm,449 inject: {450 foo: { default: 2 },451 bar: { default: 2 },452 baz: { default: 2 }453 },454 created () {455 injected = [this.foo, this.bar, this.baz]456 }457 })458 expect(injected).toEqual([1, false, undefined])459 })460461 // Github issue #6008462 it('should merge provide from mixins (objects)', () => {463 const mixinA = { provide: { foo: 'foo' }}464 const mixinB = { provide: { bar: 'bar' }}465 const child = {466 inject: ['foo', 'bar'],467 template: `<span/>`,468 created () {469 injected = [this.foo, this.bar]470 }471 }472 new Vue({473 mixins: [mixinA, mixinB],474 render (h) {475 return h(child)476 }477 }).$mount()478479 expect(injected).toEqual(['foo', 'bar'])480 })481482 it('should merge provide from mixins (functions)', () => {483 const mixinA = { provide: () => ({ foo: 'foo' }) }484 const mixinB = { provide: () => ({ bar: 'bar' }) }485 const child = {486 inject: ['foo', 'bar'],487 template: `<span/>`,488 created () {489 injected = [this.foo, this.bar]490 }491 }492 new Vue({493 mixins: [mixinA, mixinB],494 render (h) {495 return h(child)496 }497 }).$mount()498499 expect(injected).toEqual(['foo', 'bar'])500 })501502 it('should merge provide from mixins (mix of objects and functions)', () => {503 const mixinA = { provide: { foo: 'foo' }}504 const mixinB = { provide: () => ({ bar: 'bar' }) }505 const mixinC = { provide: { baz: 'baz' }}506 const mixinD = { provide: () => ({ bam: 'bam' }) }507 const child = {508 inject: ['foo', 'bar', 'baz', 'bam'],509 template: `<span/>`,510 created () {511 injected = [this.foo, this.bar, this.baz, this.bam]512 }513 }514 new Vue({515 mixins: [mixinA, mixinB, mixinC, mixinD],516 render (h) {517 return h(child)518 }519 }).$mount()520521 expect(injected).toEqual(['foo', 'bar', 'baz', 'bam'])522 })523524 it('should merge provide from mixins and override existing keys', () => {525 const mixinA = { provide: { foo: 'foo' }}526 const mixinB = { provide: { foo: 'bar' }}527 const child = {528 inject: ['foo'],529 template: `<span/>`,530 created () {531 injected = [this.foo]532 }533 }534 new Vue({535 mixins: [mixinA, mixinB],536 render (h) {537 return h(child)538 }539 }).$mount()540541 expect(injected).toEqual(['bar'])542 })543544 it('should merge provide when Vue.extend', () => {545 const mixinA = { provide: () => ({ foo: 'foo' }) }546 const child = {547 inject: ['foo', 'bar'],548 template: `<span/>`,549 created () {550 injected = [this.foo, this.bar]551 }552 }553 const Ctor = Vue.extend({554 mixins: [mixinA],555 provide: { bar: 'bar' },556 render (h) {557 return h(child)558 }559 })560561 new Ctor().$mount()562563 expect(injected).toEqual(['foo', 'bar'])564 })565566 // #5913567 it('should keep the reactive with provide', () => {568 function isObserver (obj) {569 if (isObject(obj)) {570 return hasOwn(obj, '__ob__') && obj.__ob__ instanceof Observer571 }572 return false573 }574575 const vm = new Vue({576 template: `<div><child ref='child'></child></div>`,577 data () {578 return {579 foo: {},580 $foo: {},581 foo1: []582 }583 },584 provide () {585 return {586 foo: this.foo,587 $foo: this.$foo,588 foo1: this.foo1,589 bar: {},590 baz: []591 }592 },593 components: {594 child: {595 inject: ['foo', '$foo', 'foo1', 'bar', 'baz'],596 template: `<span/>`597 }598 }599 }).$mount()600 const child = vm.$refs.child601 expect(isObserver(child.foo)).toBe(true)602 expect(isObserver(child.$foo)).toBe(false)603 expect(isObserver(child.foo1)).toBe(true)604 expect(isObserver(child.bar)).toBe(false)605 expect(isObserver(child.baz)).toBe(false)606 })607608 // #6175609 it('merge provide properly from mixins', () => {610 const ProvideFooMixin = {611 provide: {612 foo: 'foo injected'613 }614 }615616 const ProvideBarMixin = {617 provide: {618 bar: 'bar injected'619 }620 }621622 const Child = {623 inject: ['foo', 'bar'],624 render (h) {625 return h('div', [`foo: ${this.foo}, `, `bar: ${this.bar}`])626 }627 }628629 const Parent = {630 mixins: [ProvideFooMixin, ProvideBarMixin],631 render (h) {632 return h(Child)633 }634 }635636 const vm = new Vue({637 render (h) {638 return h(Parent)639 }640 }).$mount()641642 expect(vm.$el.textContent).toBe(`foo: foo injected, bar: bar injected`)643 })644645 it('merge provide with object syntax when using Vue.extend', () => {646 const child = {647 inject: ['foo'],648 template: `<span/>`,649 created () {650 injected = this.foo651 }652 }653 const Ctor = Vue.extend({654 provide: { foo: 'foo' },655 render (h) {656 return h(child)657 }658 })659660 new Ctor().$mount()661662 expect(injected).toEqual('foo')663 })664665 // #7284666 it('should not inject prototype properties', () => {667 const vm = new Vue({668 provide: {}669 })670 new Vue({671 parent: vm,672 inject: ['constructor']673 })674 expect(`Injection "constructor" not found`).toHaveBeenWarned()675 }) ...

Full Screen

Full Screen

add_masterfile.js

Source:add_masterfile.js Github

copy

Full Screen

1$('#b_role').on('change', function(){2 var role = $(this).val();34 if(role == 'land_lord' || role == 'property_manager' || role == 'contractor' || role == 'supplier'){5 // alert('working');6 $('#account_no').removeAttr('disabled').val('');7 $('#bank_name').removeAttr('disabled').val('');8 $('#branch_name').removeAttr('disabled').val('');9 $('#pin_no').removeAttr('disabled').val('');10 }else if(role == 'tenant'){11 $('#account_no').attr('disabled', 'disabled').val('');12 $('#bank_name').attr('disabled', 'disabled').val('');13 $('#branch_name').attr('disabled', 'disabled').val('');14 $('#pin_no').attr('disabled', 'disabled').val('');15 }else if(role == 'staff'){16 $('#account_no').attr('disabled', 'disabled').val('');17 $('#bank_name').attr('disabled', 'disabled').val('');18 $('#branch_name').attr('disabled', 'disabled').val('');19 $('#pin_no').attr('disabled', 'disabled').val('');20 }21});2223$('#b_role').on('change', function(){24 var role = $(this).val();2526 if(role == 'tenant'){27 // alert('working');28 $('.skill_name').hide();29 $('#occupation').removeAttr('disabled').val('');30 $('#user_role').attr('readonly', 'readonly').val('72');31 }else if(role == 'land_lord'){32 $('.skill_name').hide();33 $('#occupation').attr('disabled', 'disabled').val('');34 $('#user_role').attr('readonly', 'readonly').val('68');35 }else if(role == 'contractor'){36 $('.skill_name').show();37 $('#occupation').attr('disabled', 'disabled').val('');38 $('#user_role').attr('readonly', 'readonly').val('69');39 }else if(role == 'property_manager'){40 $('.skill_name').hide();41 $('#occupation').attr('disabled', 'disabled').val('');42 $('#user_role').attr('readonly', 'readonly').val('66');43 }else if (role == 'supplier'){44 $('.skill_name').hide();45 $('#occupation').attr('disabled', 'disabled').val('');46 $('#user_role').attr('disabled', 'disabled').val('');47 }else if(role == 'staff'){48 $('.skill_name').hide();49 $('#occupation').attr('disabled','disabled').val('');50 // $('#user_role').attr('readonly', 'readonly').val('72');51 }5253});5455$('#b_role').on('change', function() {56 var role = $(this).val();57 if(role == 'contractor' || role== 'supplier'){58 $('.surname').text('Title').val('');59 $('.id_passport').text('Business No.').val('');60 $('.gender').hide();61 $('.firstname').hide();62 $('.middlename').hide();63 }else if('land_lord' || 'property_manager' || 'tenant'){64 $('.surname').text('Surname').val('');65 $('.id_passport').text('Id/Passport').val('');66 $('.gender').show();67 $('.firstname').show();68 $('.middlename').show();69 }70});717273$('#bank_name').on('change', function(){74 var bank_id = $(this).val();75 var data = { 'bank_id': bank_id };7677 if(bank_id != ''){78 $.ajax({79 url: '?num=722',80 type: 'POST',81 data: data,82 dataType: 'json',83 success: function(data){84 var branches = '<option value="">--Choose Branch--</option>';85 for(var i = 0; i < data.length; i++){86 branches += '<option value="'+data[i].branch_id+'">'+data[i].branch_name+'</option>';87 }88 $('#branch_name').html(branches);89 }90 });91 }92});9394// start form wizard validation95var FormWizard = function () {9697 var form1 = $('#form_sample_1');98 return {99 //main function to initiate the module100 init: function () {101 if (!jQuery().bootstrapWizard) {102 return;103 }104105 // default form wizard106 $('#form_wizard_1').bootstrapWizard({107 'nextSelector': '.button-next',108 'previousSelector': '.button-previous',109 onTabClick: function (tab, navigation, index) {110 alert('on tab click disabled');111 return false;112 },113 onNext: function (tab, navigation, index) {114 // validate115 var valid = Masterfile.validateMyWizard();116 if(!valid){117 return false;118 }119120 var total = navigation.find('li').length;121 var current = index + 1;122123 // validate address details124 if(current == 3){125 var valid2 = Masterfile2.validateMyWizard2();126 if(!valid2){127 return false;128 }129 }130131 // set wizard title132 $('.step-title', $('#form_wizard_1')).text('Step ' + (index + 1) + ' of ' + total);133 // set done steps134 jQuery('li', $('#form_wizard_1')).removeClass("done");135 var li_list = navigation.find('li');136 for (var i = 0; i < index; i++) {137 jQuery(li_list[i]).addClass("done");138 }139140 if (current == 1) {141 $('#form_wizard_1').find('.button-previous').hide();142 } else {143 $('#form_wizard_1').find('.button-previous').show();144 }145146 if (current >= total) {147 $('#form_wizard_1').find('.button-next').hide();148 $('#form_wizard_1').find('.button-submit').show();149 } else {150 $('#form_wizard_1').find('.button-next').show();151 $('#form_wizard_1').find('.button-submit').hide();152 }153 App.scrollTo($('.page-title'));154 },155 onPrevious: function (tab, navigation, index) {156 var total = navigation.find('li').length;157 var current = index + 1;158 // set wizard title159 $('.step-title', $('#form_wizard_1')).text('Step ' + (index + 1) + ' of ' + total);160 // set done steps161 jQuery('li', $('#form_wizard_1')).removeClass("done");162 var li_list = navigation.find('li');163 for (var i = 0; i < index; i++) {164 jQuery(li_list[i]).addClass("done");165 }166167 if (current == 1) {168 $('#form_wizard_1').find('.button-previous').hide();169 } else {170 $('#form_wizard_1').find('.button-previous').show();171 }172173 if (current >= total) {174 $('#form_wizard_1').find('.button-next').hide();175 $('#form_wizard_1').find('.button-submit').show();176 } else {177 $('#form_wizard_1').find('.button-next').show();178 $('#form_wizard_1').find('.button-submit').hide();179 }180181 App.scrollTo($('.page-title'));182 },183 onTabShow: function (tab, navigation, index) {184 var total = navigation.find('li').length;185 var current = index + 1;186 var $percent = (current / total) * 100;187 $('#form_wizard_1').find('.bar').css({188 width: $percent + '%'189 });190 }191 });192193 $('#form_wizard_1').find('.button-previous').hide();194 $('#form_wizard_1 .button-submit').click(function () {195 //alert('Finished! Hope you like it :)');196 }).hide();197 }198 };199}();200201//on tab next validations202var Masterfile = {203 validateMyWizard: function(){204 if($('#b_role').val() == ''){205 alert('You must provide a Business Role!');206 $('#b_role').focus();207 return false;208 }209210 var b_role = $('#b_role').val();211 switch(b_role){212 case 'tenant':213 // validation214 if($('#surname').val() == ''){215 alert('You Must Provide Surname!');216 $('#surname').focus();217 return false;218 }else if($('#firstname').val() == ''){219 alert('You Must Provide First Name!');220 $('#firstname').focus();221 return false;222 }else if($('#email').val() == ''){223 alert('You Must Provide Email!');224 $('#email').focus();225 return false;226 }else if($('#id_passport').val() == ''){227 alert('You Must Provide Id/Passport!');228 $('#id_passport').focus();229 return false;230 }else if($('#gender').val() == ''){231 alert('You Must Provide Gender!');232 $('#gender').focus();233 return false;234 }else if($('#occupation').val() == ''){235 alert('You Must Provide Tenant Occupation!');236 $('#occupation').focus();237 return false;238 }else if($('#customer_type_id').val() == ''){239 alert('You Must Provide Masterfile Type!');240 $('#customer_type_id').focus();241 return false;242 }else{243 return true;244 }245 break;246247 case 'land_lord':248 if($('#surname').val() == ''){249 alert('You Must Provide Surname!');250 $('#surname').focus();251 return false;252 }else if($('#firstname').val() == ''){253 alert('You Must Provide First Name!');254 $('#firstname').focus();255 return false;256 }else if($('#email').val() == ''){257 alert('You Must Provide Email!');258 $('#email').focus();259 return false;260 }else if($('#id_passport').val() == ''){261 alert('You Must Provide Id/Passport!');262 $('#id_passport').focus();263 return false;264 }else if($('#gender').val() == ''){265 alert('You Must Provide Gender!');266 $('#gender').focus();267 return false;268 }else if($('#customer_type_id').val() == ''){269 alert('You Must Provide Masterfile Type!');270 $('#customer_type_id').focus();271 return false;272 }else{273 return true;274 }275 break;276277 case 'supplier':278 if($('#surname').val() == ''){279 alert('You Must Provide the Title!');280 $('#surname').focus();281 return false;282 }else if($('#email').val() == ''){283 alert('You Must Provide Email!');284 $('#email').focus();285 return false;286 }else if($('#id_passport').val() == ''){287 alert('You Must Provide business Number!');288 $('#id_passport').focus();289 return false;290 }else if($('#customer_type_id').val() == ''){291 alert('You Must Provide Masterfile Type!');292 $('#customer_type_id').focus();293 return false;294 }else{295 return true;296 }297 break;298 case 'contractor':299 if($('#surname').val() == ''){300 alert('You Must Provide the Title!');301 $('#surname').focus();302 return false;303 }else if($('#email').val() == ''){304 alert('You Must Provide Email!');305 $('#email').focus();306 return false;307 }else if($('#id_passport').val() == ''){308 alert('You Must Provide business Number!');309 $('#id_passport').focus();310 return false;311 }else if($('#customer_type_id').val() == ''){312 alert('You Must Provide Masterfile Type!');313 $('#customer_type_id').focus();314 return false;315 }else if($('#skill_id').val() == ''){316 alert('You Must Provide Core Activity for the Contractor!');317 $('#skill_id').focus();318 return false;319 }else{320 return true;321 }322 break;323324 case 'property_manager':325 if($('#surname').val() == ''){326 alert('You Must Provide Surname of th Property Manager!');327 $('#surname').focus();328 return false;329 }else if($('#firstname').val() == ''){330 alert('You Must Provide First Name!');331 $('#firstname').focus();332 return false;333 }else if($('#email').val() == ''){334 alert('You Must Provide Email!');335 $('#email').focus();336 return false;337 }else if($('#id_passport').val() == ''){338 alert('You Must Provide Id/Passport!');339 $('#id_passport').focus();340 return false;341 }else if($('#gender').val() == ''){342 alert('You Must Provide Gender!');343 $('#gender').focus();344 return false;345 }else if($('#customer_type_id').val() == ''){346 alert('You Must Provide Masterfile Type!');347 $('#customer_type_id').focus();348 return false;349 }else{350 return true;351 }352 break;353 case 'staff':354 // validation355 if($('#surname').val() == ''){356 alert('You Must Provide Surname!');357 $('#surname').focus();358 return false;359 }else if($('#firstname').val() == ''){360 alert('You Must Provide First Name!');361 $('#firstname').focus();362 return false;363 }else if($('#email').val() == ''){364 alert('You Must Provide Email!');365 $('#email').focus();366 return false;367 }else if($('#id_passport').val() == ''){368 alert('You Must Provide Id/Passport!');369 $('#id_passport').focus();370 return false;371 }else if($('#gender').val() == ''){372 alert('You Must Provide Gender!');373 $('#gender').focus();374 return false;375 }else if($('#customer_type_id').val() == ''){376 alert('You Must Provide Masterfile Type!');377 $('#customer_type_id').focus();378 return false;379 }else{380 return true;381 }382 break;383 }384 },385}386387// masterfile address details validation388var Masterfile2 = {389 validateMyWizard2: function(){390 if($('#select2_sample79').val() == ''){391 alert('You must provide County Name!');392 $('#select2_sample79').focus();393 return false;394 }else if($('#town').val() == ''){395 alert('You must provide Town/City for the selected County!');396 $('#town').focus();397 return false;398 }else if($('#phone').val() == ''){399 alert('You must provide Provide Phone Number!');400 $('#phone').focus();401 return false;402 }else if($('#box').val() == ''){403 alert('You must provide Box Number!');404 $('#box').focus();405 return false;406 }else if($('#postal_code').val() == ''){407 alert('You must provide Postal Code!');408 $('#postal_code').focus();409 return false;410 }else if($('#address_type_id').val() == ''){411 alert('You must provide Address Type!');412 $('#address_type_id').focus();413 return false;414 }else{415 return true;416 }417 }418}419 ...

Full Screen

Full Screen

moduleProviderPlugIns.js

Source:moduleProviderPlugIns.js Github

copy

Full Screen

...6 identifierLoadWasCalledWith = moduleIdentifier;7 originalModuleLoad(moduleIdentifier, onModuleLoaded);8 };9 module.declare([], function () {10 module.provide(["demos/math"], function () {11 strictEqual(identifierLoadWasCalledWith, "demos/math", "The overriden version of module.load was called with the same module identifier as was passed to the un-overriden module.provide.");12 module.constructor.prototype.load = originalModuleLoad;13 start();14 });15 });16});17test("Overriden provide: is called to provide the unmemoized dependencies when declaring the main module", function () {18 var idsOfModulesProvideIsCalledOn = [];19 var dependenciesProvideWasCalledWith = [];20 var originalModuleProvide = module.constructor.prototype.provide;21 module.constructor.prototype.provide = function (dependencies, onAllProvided) {22 idsOfModulesProvideIsCalledOn.push(this.id);23 dependenciesProvideWasCalledWith = dependenciesProvideWasCalledWith.concat(dependencies);24 onAllProvided();...

Full Screen

Full Screen

provide.controller.maintain.js

Source:provide.controller.maintain.js Github

copy

Full Screen

1define(['apps/system3/production/production.controller',2 'apps/system3/production/specialty/specialty.service',3 'apps/system3/production/provide/provide.service'], function (app) {4 app.controller('production.controller.provide.maintain', function ($scope, maintainParams, $uibModalInstance) {5 $scope.windowProvide = maintainParams.provideInfo;6 if (maintainParams.task) {7 $scope.taskID = maintainParams.task.ID;8 }9 $scope.receiveUsers = [];10 $scope.volumeFiles = [];11 $scope.currentVolume = {};12 // 新建提资13 $scope.newProvide = function (provide) {14 $scope.readOnly = false;15 $scope.provideInfo = {16 Engineering: provide.Engineering,17 EngineeringID: provide.Engineering.ID,18 SendSpecialtyID: provide.Specialty.SpecialtyID,19 ReceiveUserIDs: "",20 DocName: "",21 DocContent: "",22 AttachIDs: [],23 VolumeFiles: []24 };25 $scope.flowData = {26 EngineeringID: provide.Engineering.ID,27 SpecialtyID: provide.Specialty.SpecialtyID28 };29 // 新增加载专业的卷册文件30 $scope.loadVolumeFiles();31 }32 // 编辑提资33 $scope.maintainProvide = function (provide, task) {34 $scope.readOnly = !$scope.taskID;35 $scope.provideInfo = provide;36 if (!$scope.readOnly) {37 if (provide.ReceiveUserIDs.length > 0) {38 var str = ',' + provide.ReceiveUserIDs + ',';39 angular.forEach($rootScope.user_item, function (user) {40 if (str.indexOf(',' + user.ID + ',') >= 0) {41 $scope.receiveUsers.push({42 ID: user.ID,43 Name: user.Name,44 Dept: user.Dept,45 PhotoImg: user.PhotoImg46 });47 }48 });49 }50 // 新增加载专业的卷册文件51 $scope.loadVolumeFiles();52 }53 }54 // 获取卷册文件55 $scope.loadVolumeFiles = function () {56 console.log(111)57 //$scope.providePanel.block();58 specialtyService.getFiles($scope.provideInfo.EngineeringID, $scope.provideInfo.SendSpecialtyID).then(function (data) {59 $scope.volumeFiles = data;60 $scope.currentVolume = data[0];61 //$scope.providePanel.unblock();62 });63 }64 // 选择卷册65 $scope.volChanged = function (v) {66 $scope.currentVolume = v;67 }68 // 全选卷册文件69 $scope.selectAll = function (vol) {70 angular.forEach(vol.Files, function (f) {71 f.selected = vol.selected;72 });73 }74 // 获取选中卷册文件的数量75 $scope.getSelectedFileCount = function (files) {76 var count = 0;77 angular.forEach(files, function (f) {78 if (f.selected) {79 count++;80 }81 });82 return count;83 }84 // 保存85 $scope.save = function (flow) {86 $scope.providePanel.block();87 if ($scope.provideInfo.ID > 0) {88 // 编辑89 provideService.update($scope.provideInfo).then(function () {90 flow.callBack(function () {91 $scope.providePanel.unblock();92 if ($scope.afterSave) {93 $scope.afterSave();94 } else {95 $scope.loadSource();96 }97 });98 });99 } else {100 // 新增101 $scope.provideInfo.ApproveUser = flow.taskInfo.user;102 provideService.create($scope.provideInfo).then(function () {103 // 通知附件预览控件更新附件列表104 if ($scope.attachChangedCB) {105 $scope.attachChangedCB();106 }107 flow.callBack(function () {108 $scope.providePanel.unblock();109 if ($scope.afterSave) {110 $scope.afterSave();111 } else {112 $scope.loadSource();113 }114 });115 });116 }117 return true;118 }119 $scope.$watchCollection("receiveUsers", function (newval, oldval) {120 if (newval && $scope.provideInfo) {121 if (newval.length == 0) {122 $scope.provideInfo.ReceiveUserIDs = undefined;123 } else {124 var ids = [];125 angular.forEach(newval, function (user) {126 ids.push(user.ID);127 })128 $scope.provideInfo.ReceiveUserIDs = ids.join(',');129 }130 }131 });132 $scope.$watch("volumeFiles", function (newval, oldval) {133 if (newval && $scope.provideInfo) {134 $scope.provideInfo.VolumeFiles = [];135 angular.forEach(newval, function (vol) {136 angular.forEach(vol.Files, function (f) {137 if (f.selected) {138 $scope.provideInfo.VolumeFiles.push(f.ID);139 }140 });141 });142 }143 }, true);144 $scope.$watch("currentProvide", function (newval, oldval) {145 if (newval) {146 if (newval.ID > 0) {147 $scope.maintainProvide(newval);148 } else {149 $scope.newProvide(newval);150 }151 }152 });153 $scope.$on("newProvide", function (e, data) {154 $scope.newProvide(data);155 })156 // 附件上传完成后回调157 $scope.attachUploaded = function (id, attachChangedCB) {158 // 新建的模式下,先保存上传的附件ID,当信息被保存后,在保存该附件ID159 $scope.provideInfo.AttachIDs.push(id);160 $scope.attachChangedCB = attachChangedCB;161 };162 // 变更信息163 if ($scope.windowProvide) {164 if ($scope.windowProvide.ID > 0) {165 $scope.maintainProvide($scope.windowProvide)166 } else {167 $scope.newProvide($scope.windowProvide)168 }169 }170 171 172 // 关闭编辑模式173 $scope.closeModal = function () {174 $uibModalInstance.dismiss('cancel');175 }176 });...

Full Screen

Full Screen

recursiveProvision.js

Source:recursiveProvision.js Github

copy

Full Screen

1newTestSet("Recursive provision");2asyncModuleTest("Can provide a module that specifies its dependency via a relative path", function (require, exports, module) {3 module.provide(["demos/area"], function onModulesProvided() {4 ok(true, "Callback called");5 var area = require("demos/area");6 strictEqual(area.rectangle(2, 3), 6, "Area of a rectangle successfully computed using two modules in collaboration (require, then use later)");7 strictEqual(area.square(3), 9, "Area of a square successfully computed using two modules in collaboration (require and pick a property immediately)");8 start();9 });10});11asyncModuleTest("Can provide two modules (at the same time) that both require the same module", function (require, exports, module) {12 module.provide(["demos/area", "demos/perimeter"], function onModulesProvided() {13 ok(true, "Callback called");14 var area = require("demos/area");15 var perimeter = require("demos/perimeter");16 strictEqual(area.rectangle(2, 3), 6, "Area of a rectangle successfully computed using two modules in collaboration (require, then use later)");17 strictEqual(area.square(3), 9, "Area of a square successfully computed using two modules in collaboration (require and pick a property immediately)");18 strictEqual(perimeter.rectangle(2, 3), 10, "Perimeter of a rectangle successfully computed using two modules in collaboration (require, then use later)");19 strictEqual(perimeter.square(3), 12, "Perimeter of a square successfully computed using two modules in collaboration (require and pick a property immediately)");20 start();21 });22});23asyncModuleTest("Can provide two modules (one after the other) that both require the same module", function (require, exports, module) {24 var numberOfProvidesSoFar = 0;25 module.provide(["demos/area"], function () {26 ok(true, "area provide callback called");27 var area = require("demos/area");28 strictEqual(area.rectangle(2, 3), 6, "Area of a rectangle successfully computed using two modules in collaboration (require, then use later)");29 strictEqual(area.square(3), 9, "Area of a square successfully computed using two modules in collaboration (require and pick a property immediately)");30 if (++numberOfProvidesSoFar === 2) {31 start();32 }33 });34 module.provide(["demos/perimeter"], function () {35 ok(true, "perimeter provide callback called");36 var perimeter = require("demos/perimeter");37 strictEqual(perimeter.rectangle(2, 3), 10, "Perimeter of a rectangle successfully computed using two modules in collaboration (require, then use later)");38 strictEqual(perimeter.square(3), 12, "Perimeter of a square successfully computed using two modules in collaboration (require and pick a property immediately)");39 if (++numberOfProvidesSoFar === 2) {40 start();41 }42 });43});44asyncModuleTest("Can provide the same module twice in a row, for the simple case of a module with no dependencies", function (require, exports, module) {45 var numberOfProvidesSoFar = 0;46 function assertMathExports(math) {47 strictEqual(typeof math, "object", "math module has been exported.");48 strictEqual(typeof math.add, "function", "math's add function has been exported");49 strictEqual(typeof math.multiply, "function", "math's multiply function has been exported");50 }51 module.provide(["demos/math"], function () {52 ++numberOfProvidesSoFar;53 ok(true, "first math provide callback called");54 assertMathExports(require("demos/math"));55 if (numberOfProvidesSoFar === 2) {56 start();57 }58 });59 module.provide(["demos/math"], function () {60 ++numberOfProvidesSoFar;61 ok(true, "second math provide callback called");62 assertMathExports(require("demos/math"));63 if (numberOfProvidesSoFar === 2) {64 start();65 }66 });67});68asyncModuleTest("Can provide the same module twice in a row, for the case of a module with dependencies", function (require, exports, module) {69 var numberOfProvidesSoFar = 0;70 function assertAreaExports(area) {71 strictEqual(typeof area, "object", "Area modules has been exported");72 strictEqual(typeof area.rectangle, "function", "Area's add function has been exported");73 strictEqual(typeof area.square, "function", "Area's square function has been exported");74 }75 module.provide(["demos/area"], function () {76 ++numberOfProvidesSoFar;77 ok(true, "first area provide callback called");78 assertAreaExports(require("demos/area"));79 if (numberOfProvidesSoFar === 2) {80 start();81 }82 });83 module.provide(["demos/area"], function () {84 ++numberOfProvidesSoFar;85 ok(true, "second area provide callback called");86 assertAreaExports(require("demos/area"));87 if (numberOfProvidesSoFar === 2) {88 start();89 }90 });91});92asyncTest("If the main module depends on a memoized module that depends on un-memoized modules, the un-memoized modules are provided", function () {93 require.memoize("memoized", ["demos/math"], function (require, exports, module) {94 var math = require("demos/math");95 exports.increment = function (x) {96 return math.add(x, 1);97 };98 });99 module.declare(["memoized"], function (require, exports, module) {100 ok(true, "Main module factory function was called");101 strictEqual(require.isMemoized("demos/math"), true, "The math module is now memoized, even though we didn't do so explicitly");102 var memoized = require("memoized");103 var five = memoized.increment(4);104 strictEqual(five, 5, "The explicitly-memoized module correctly used the unmemoized module to increment 4 and return 5");105 start();106 });107});108asyncModuleTest("Providing a memoized module that depends on un-memoized modules results in the un-memoized modules being provided", function (require, exports, module) {109 require.memoize("memoized", ["demos/math"], function (require, exports, module) {110 var math = require("demos/math");111 exports.increment = function (x) {112 return math.add(x, 1);113 };114 });115 module.provide(["memoized"], function () {116 ok(true, "Provide callback was called");117 strictEqual(require.isMemoized("demos/math"), true, "The math module is now memoized, even though we didn't do so explicitly");118 var memoized = require("memoized");119 var five = memoized.increment(4);120 strictEqual(five, 5, "The explicitly-memoized module correctly used the unmemoized module to increment 4 and return 5");121 start();122 });123});124asyncModuleTest("Providing a diamond configuration does not provide a module twice", function (require, exports, module) {125 // Use the plug-in system to record calls to provide126 var dependenciesProvideWasCalledWith = [];127 var originalModuleProvide = module.constructor.prototype.provide;128 var delay = 50;129 module.constructor.prototype.provide = function (dependencies, onAllProvided) {130 dependenciesProvideWasCalledWith = dependenciesProvideWasCalledWith.concat(dependencies);131 originalModuleProvide.call(this, dependencies, function () {132 setTimeout(onAllProvided, delay);133 delay += 50;134 });135 };136 function endsWith(string, substring) {137 return string.indexOf(substring, string.length - substring.length) !== -1;138 }139 module.provide(["demos/diamond/top"], function () {140 var bottomInstances = dependenciesProvideWasCalledWith.filter(function (dependency) { return endsWith(dependency, "bottom"); });141 strictEqual(bottomInstances.length, 1, "The bottom module in the diamond was only provided once");142 module.constructor.prototype.provide = originalModuleProvide;143 start();144 });...

Full Screen

Full Screen

moduleNamespace.js

Source:moduleNamespace.js Github

copy

Full Screen

...9 start();10 });11});12asyncModuleTest("declare: infers dependencies if only a factory function is given", function () {13 module.provide(["demos/squares"], function () {14 var squares = require("demos/squares");15 strictEqual(squares.area(3), 9, "demos/area dependency was inferred and works");16 strictEqual(squares.perimeter(3), 12, "demos/perimeter dependency was inferred and works");17 strictEqual(require.isMemoized(require.id("demos/diamond/bottom")), false, "Commented-out demos/diamond/bottom dependency was not memoized");18 start();19 });20});21asyncTest("declare: dependency inference does not infer the same dependency twice", function () {22 var dependenciesProvideWasCalledWith = [];23 var originalModuleProvide = module.constructor.prototype.provide;24 module.constructor.prototype.provide = function (dependencies, onAllProvided) {25 dependenciesProvideWasCalledWith = dependenciesProvideWasCalledWith.concat(dependencies);26 originalModuleProvide.call(this, dependencies, onAllProvided);27 };28 module.declare(["demos/circles"], function () {29 deepEqual(dependenciesProvideWasCalledWith, ["demos/circles", "demos/math"], "module.provide was called only once for the demos/math dependency");30 module.constructor.prototype.provide = originalModuleProvide;31 start();32 });33});34asyncModuleTest("load: when called twice in a row for the same module, both callbacks fire", function (require, exports, module) {35 var numberOfLoadsSoFar = 0;36 module.load("demos/math", function onLoad1() {37 ok(true, "First callback");38 ++numberOfLoadsSoFar;39 if (numberOfLoadsSoFar === 2) {40 start();41 }42 });43 module.load("demos/math", function onLoad2() {44 ok(true, "Second callback");45 ++numberOfLoadsSoFar;46 if (numberOfLoadsSoFar === 2) {47 start();48 }49 });50});51asyncModuleTest("load: when called twice in a row for the same nonextant module, both callbacks fire", function (require, exports, module) {52 var numberOfLoadsSoFar = 0;53 module.load("asdf", function onLoad1() {54 ok(true, "First callback");55 ++numberOfLoadsSoFar;56 if (numberOfLoadsSoFar === 2) {57 start();58 }59 });60 module.load("asdf", function onLoad2() {61 ok(true, "Second callback");62 ++numberOfLoadsSoFar;63 if (numberOfLoadsSoFar === 2) {64 start();65 }66 });67});68asyncModuleTest("load: does not memoize the loaded module", function (require, exports, module) {69 module.load("demos/math", function onModuleLoaded() {70 strictEqual(require.isMemoized("demos/math"), false, "The module was not memoized");71 start();72 });73});74asyncModuleTest("provide: passing an empty dependency array still results in the callback being called", function (require, exports, module) {75 module.provide([], function onModulesProvided() {76 ok(true, "Callback was called");77 start();78 });79});80asyncModuleTest("provide: when passing multiple dependencies, all of them are memoized by the time the callback is called", function (require, exports, module) {81 module.provide(["demos/area", "demos/perimeter"], function onModulesProvided() {82 strictEqual(require.isMemoized("demos/area"), true, "First dependency is memoized");83 strictEqual(require.isMemoized("demos/perimeter"), true, "Second dependency is memoized");84 start();85 });86});87asyncModuleTest("provide: understands relative identifiers", function (require, exports, module) {88 module.provide(["demos/../demos/math"], function onModulesProvided() {89 strictEqual(require.isMemoized("demos/math"), true, "It figured out demos/../demos");90 start();91 });92});93asyncModuleTest("provide: still calls the callback even if one of the modules in the dependencies array doesn't exist", function (require, exports, module) {94 module.provide(["asdf", "demos/math"], function onModulesProvided() {95 ok(true, "Callback still got called");96 strictEqual(require.isMemoized("demos/math"), true, "The extant module is memoized");97 strictEqual(require.isMemoized("asdf"), false, "The nonextant module is not memoized");98 start();99 });100});101asyncModuleTest("provide: two calls in a row for a nonextant module still results in both callbacks being called", function (require, exports, module) {102 var numberOfLoadsSoFar = 0;103 module.provide(["asdf"], function onProvided1() {104 ok(true, "First callback");105 ++numberOfLoadsSoFar;106 if (numberOfLoadsSoFar === 2) {107 start();108 }109 });110 module.provide(["asdf"], function onProvided2() {111 ok(true, "Second callback");112 ++numberOfLoadsSoFar;113 if (numberOfLoadsSoFar === 2) {114 start();115 }116 });117});118asyncModuleTest("provide: providing an extant module then a nonextant module does not mistakenly memoize the nonextant module using leftovers from the extant one", function (require, exports, module) {119 module.provide(["demos/math"], function () {120 ok(true, "Callback for extant module reached");121 module.provide(["asdf"], function () {122 ok(true, "Callback for nonextant module reached");123 strictEqual(require.isMemoized("demos/math"), true, "The extant module is memoized");124 strictEqual(require.isMemoized("asdf"), false, "The nonextant module is not memoized");125 start();126 });127 });128});129// See http://groups.google.com/group/commonjs/browse_thread/thread/50d4565bd07e03cb130asyncModuleTest("provide: does not modify module.dependencies", function (require, exports, module) {131 module.provide(["demos/math"], function onModulesProvided() {132 deepEqual(module.dependencies, [], "The dependencies array is still empty.");133 start();134 });135});136// See http://groups.google.com/group/commonjs/browse_thread/thread/50d4565bd07e03cb137asyncModuleTest("provide: does not make labels available to require", function (require, exports, module) {138 module.provide([{ math: "demos/math" }], function onModulesProvided() {139 raises(function () {140 require("math");141 }, "Trying to require using the label throws an error");142 start();143 });144});145asyncModuleTest("eventually: causes the function to be called within a second", function (require, exports, module) {146 var wasCalled = false;147 var gaveUpAlready = false;148 function callMeEventually() {149 if (!gaveUpAlready) {150 wasCalled = true;151 ok(true, "The function was called, eventually");152 start();...

Full Screen

Full Screen

circularDependencies.js

Source:circularDependencies.js Github

copy

Full Screen

1newTestSet("Circular dependencies");2asyncModuleTest("Can provide a module that depends on a module that depends on the original module", function (require, exports, module) {3 module.provide(["demos/circular/circularA"], function onModulesProvided() {4 ok(true, "module.provide callback called");5 var circularA = require("demos/circular/circularA");6 strictEqual(typeof circularA, "object", "circularA module has been exported");7 strictEqual(typeof circularA.getValue, "function", "circularA's getValue function has been exported");8 strictEqual(typeof circularA.getValueFromB, "function", "circularA's getValueFromB function has been exported");9 strictEqual(circularA.getValueFromB(), "b", "circularA's getValueFromB function returns the correct value");10 start();11 });12});13asyncModuleTest("Can provide two mutually-dependent modules in the same module.provide call", function (require, exports, module) {14 module.provide(["demos/circular/circularA", "demos/circular/circularB"], function onModulesProvided() {15 ok(true, "module.provide callback called");16 var circularA = require("demos/circular/circularA");17 strictEqual(typeof circularA, "object", "circularA module has been exported");18 strictEqual(typeof circularA.getValue, "function", "circularA's getValue function has been exported");19 strictEqual(typeof circularA.getValueFromB, "function", "circularA's getValueFromB function has been exported");20 strictEqual(circularA.getValueFromB(), "b", "circularA's getValueFromB function returns the correct value");21 var circularB = require("demos/circular/circularB");22 strictEqual(typeof circularB, "object", "circularB module has been exported");23 strictEqual(typeof circularB.getValue, "function", "circularB's getValue function has been exported");24 strictEqual(typeof circularB.getValueFromA, "function", "circularB's getValueFromA function has been exported");25 strictEqual(circularB.getValueFromA(), "a", "circularB's getValueFromA function returns the correct value");26 start();27 });28});29asyncModuleTest("Can provide the modules in a two-module circle in parallel, via two module.provide calls", function (require, exports, module) {30 var callbacksCalled = 0;31 var desiredCallbacksCalled = 2;32 function onCallback() {33 if (++callbacksCalled === desiredCallbacksCalled) {34 start();35 }36 }37 module.provide(["demos/circular/circularA"], function onAProvided() {38 ok(true, "module.provide callback called for circularA");39 var circularA = require("demos/circular/circularA");40 strictEqual(typeof circularA, "object", "circularA module has been exported");41 strictEqual(typeof circularA.getValue, "function", "circularA's getValue function has been exported");42 strictEqual(typeof circularA.getValueFromB, "function", "circularA's getValueFromB function has been exported");43 strictEqual(circularA.getValueFromB(), "b", "circularA's getValueFromB function returns the correct value");44 onCallback();45 });46 module.provide(["demos/circular/circularB"], function onBProvided() {47 ok(true, "module.provide callback called for circularB");48 var circularB = require("demos/circular/circularB");49 strictEqual(typeof circularB, "object", "circularB module has been exported");50 strictEqual(typeof circularB.getValue, "function", "circularB's getValue function has been exported");51 strictEqual(typeof circularB.getValueFromA, "function", "circularB's getValueFromA function has been exported");52 strictEqual(circularB.getValueFromA(), "a", "circularB's getValueFromA function returns the correct value");53 onCallback();54 });55});56asyncModuleTest("Can provide a module that depends on a module that depends on the original module, while also depending on a nonextant module", function (require, exports, module) {57 module.provide(["demos/circular/circularAndNonextantA"], function onModulesProvided() {58 ok(true, "module.provide callback called");59 require("demos/circular/circularAndNonextantA");60 ok(true, "module was initialized");61 start();62 });63});64asyncModuleTest("Can provide a module in a three-module dependency circle", function (require, exports, module) {65 module.provide(["demos/circular/circular1"], function onModulesProvided() {66 ok(true, "module.provide callback called");67 var circular1 = require("demos/circular/circular1");68 strictEqual(typeof circular1, "object", "circular1 module has been exported");69 strictEqual(typeof circular1.getValue, "function", "circular1's getValue function has been exported");70 strictEqual(typeof circular1.getValueFrom2, "function", "circular1's getValueFrom2 function has been exported");71 strictEqual(circular1.getValueFrom2(), "2", "circular1's getValueFrom2 function returns the correct value");72 start();73 });74});75asyncModuleTest("Can provide all three modules in a three-module dependency circle in the same module.provide call", function (require, exports, module) {76 module.provide(["demos/circular/circular1", "demos/circular/circular3", "demos/circular/circular2"], function onModulesProvided() {77 ok(true, "module.provide callback called");78 require("demos/circular/circular1");79 ok(true, "circular1 module initialized");80 require("demos/circular/circular2");81 ok(true, "circular2 module initialized");82 require("demos/circular/circular3");83 ok(true, "circular3 module initialized");84 start();85 });86});87asyncModuleTest("Can provide the modules in a three-module dependency circle in parallel, via three module.provide calls", function (require, exports, module) {88 var callbacksCalled = 0;89 var desiredCallbacksCalled = 3;90 function onCallback() {91 if (++callbacksCalled === desiredCallbacksCalled) {92 start();93 }94 }95 module.provide(["demos/circular/circular1"], function on1Provided() {96 ok(true, "module.provide callback called for circular1");97 require("demos/circular/circular1");98 ok(true, "circular1 module initialized");99 onCallback();100 });101 module.provide(["demos/circular/circular2"], function on1Provided() {102 ok(true, "module.provide callback called for circular2");103 require("demos/circular/circular2");104 ok(true, "circular2 module initialized");105 onCallback();106 });107 module.provide(["demos/circular/circular3"], function on1Provided() {108 ok(true, "module.provide callback called for circular3");109 require("demos/circular/circular3");110 ok(true, "circular3 module initialized");111 onCallback();112 });...

Full Screen

Full Screen

inject.js

Source:inject.js Github

copy

Full Screen

1/* @flow */2import { hasOwn } from 'shared/util'3import { warn, hasSymbol } from '../util/index'4import { defineReactive, toggleObserving } from '../observer/index'5export function initProvide (vm: Component) {6 const provide = vm.$options.provide7 if (provide) {8 vm._provided = typeof provide === 'function'9 ? provide.call(vm)10 : provide11 }12}13export function initInjections (vm: Component) {14 const result = resolveInject(vm.$options.inject, vm)15 if (result) {16 toggleObserving(false)17 Object.keys(result).forEach(key => {18 /* istanbul ignore else */19 if (process.env.NODE_ENV !== 'production') {20 defineReactive(vm, key, result[key], () => {21 warn(22 `Avoid mutating an injected value directly since the changes will be ` +23 `overwritten whenever the provided component re-renders. ` +24 `injection being mutated: "${key}"`,25 vm26 )27 })28 } else {29 defineReactive(vm, key, result[key])30 }31 })32 toggleObserving(true)33 }34}35export function resolveInject (inject: any, vm: Component): ?Object {36 if (inject) {37 // inject is :any because flow is not smart enough to figure out cached38 const result = Object.create(null)39 const keys = hasSymbol40 ? Reflect.ownKeys(inject)41 : Object.keys(inject)42 for (let i = 0; i < keys.length; i++) {43 const key = keys[i]44 // #6574 in case the inject object is observed...45 if (key === '__ob__') continue46 const provideKey = inject[key].from47 let source = vm48 while (source) {49 if (source._provided && hasOwn(source._provided, provideKey)) {50 result[key] = source._provided[provideKey]51 break52 }53 source = source.$parent54 }55 if (!source) {56 if ('default' in inject[key]) {57 const provideDefault = inject[key].default58 result[key] = typeof provideDefault === 'function'59 ? provideDefault.call(vm)60 : provideDefault61 } else if (process.env.NODE_ENV !== 'production') {62 warn(`Injection "${key}" not found`, vm)63 }64 }65 }66 return result67 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('TestComponent', () => {2 let component: TestComponent;3 let fixture: ComponentFixture<TestComponent>;4 let mockService: MockService;5 beforeEach(async(() => {6 TestBed.configureTestingModule({7 {8 useFactory: () => mockService = new MockService()9 }10 })11 .compileComponents();12 }));13 beforeEach(() => {14 fixture = TestBed.createComponent(TestComponent);15 component = fixture.componentInstance;16 fixture.detectChanges();17 });18 it('should call service', () => {19 component.doSomething();20 expect(mockService.doSomething).toHaveBeenCalled();21 });22});23describe('AppComponent', () => {24 let component: AppComponent;25 let fixture: ComponentFixture<AppComponent>;26 let mockService: MockService;27 beforeEach(async(() => {28 TestBed.configureTestingModule({29 {30 useFactory: () => mockService = new MockService()31 }32 })33 .compileComponents();34 }));35 beforeEach(() => {36 fixture = TestBed.createComponent(AppComponent);37 component = fixture.componentInstance;38 fixture.detectChanges();39 });40 it('should call service', () => {41 component.doSomething();42 expect(mockService.doSomething).toHaveBeenCalled();43 });44});45describe('AppComponent', () => {46 let component: AppComponent;47 let fixture: ComponentFixture<AppComponent>;48 let mockService: MockService;49 beforeEach(async(() => {50 TestBed.configureTestingModule({51 {52 useFactory: () => mockService = new MockService()53 }54 })55 .compileComponents();56 }));57 beforeEach(() => {58 fixture = TestBed.createComponent(AppComponent);59 component = fixture.componentInstance;60 fixture.detectChanges();61 });62 it('should call service', () => {63 component.doSomething();64 expect(mockService.doSomething).toHaveBeenCalled();65 });66});67describe('AppComponent', () => {68 let component: AppComponent;69 let fixture: ComponentFixture<AppComponent>;70 let mockService: MockService;71 beforeEach(async(() =>

Full Screen

Using AI Code Generation

copy

Full Screen

1import {provide} from '@angular/core';2import {TestBed} from '@angular/core/testing';3import {MockBackend} from '@angular/http/testing';4import {BaseRequestOptions, Http} from '@angular/http';5import {App} from './app';6describe('App', () => {7 beforeEach(() => {8 TestBed.configureTestingModule({9 provide(Http, {10 useFactory: (backend, defaultOptions) => {11 return new Http(backend, defaultOptions);12 },13 })14 });15 });16 it('should have http', inject([App], (app) => {17 expect(!!app.http).toEqual(true);18 }));19});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('TestComponent', () => {2 beforeEach(() => {3 TestBed.configureTestingModule({4 {5 useFactory: () => ({6 test: () => 'test',7 }),8 },9 });10 });11 it('should be created', () => {12 const fixture = TestBed.createComponent(TestComponent);13 const component = fixture.componentInstance;14 expect(component).toBeTruthy();15 });16 it('should call test', () => {17 const fixture = TestBed.createComponent(TestComponent);18 const component = fixture.componentInstance;19 const testService = TestBed.inject(TestService);20 const spy = spyOn(testService, 'test').and.callThrough();21 component.test();22 expect(spy).toHaveBeenCalled();23 });24});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Mocking services', () => {2 beforeEach(() => {3 TestBed.configureTestingModule({4 { provide: DataService, useClass: MockDataService },5 });6 });7 it('should get data', () => {8 const service: DataService = TestBed.get(DataService);9 expect(service.getData()).toBe('mock');10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Testing ng-mocks provide method', function () {2 beforeEach(function () {3 ngMocks.provide({4 useValue: {5 get: function () {6 return "mock service";7 }8 }9 });10 });11 it('should return mock service', function () {12 var service = ngMocks.inject('myService');13 expect(service.get()).toEqual("mock service");14 });15});16describe('Testing ng-mocks provide method', function () {17 beforeEach(function () {18 ngMocks.provide({19 useValue: {20 get: function () {21 return "mock service";22 }23 }24 });25 });26 it('should return mock service', function () {27 var service = ngMocks.inject('myService');28 expect(service.get()).toEqual("mock service");29 });30});31describe('Testing ng-mocks provide method', function () {32 beforeEach(function () {33 ngMocks.provide({34 useValue: {35 get: function () {36 return "mock service";37 }38 }39 });40 });41 it('should return mock service', function () {42 var service = ngMocks.inject('myService');43 expect(service.get()).toEqual("mock service");44 });45});46describe('Testing ng-mocks provide method', function () {47 beforeEach(function () {

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('TestComponent', () => {2 beforeEach(() => {3 TestBed.configureTestingModule({4 {5 useFactory: () => ({6 test: () => 'test',7 }),8 },9 });10 });11 it('should be created', () => {12 const fixture = TestBed.createComponent(TestComponent);13 const component = fixture.componentInstance;14 expect(component).toBeTruthy();15 });16 it('should call test', () => {17 const fixture = TestBed.createComponent(TestComponent);18 const component = fixture.componentInstance;19 const testService = TestBed.inject(TestService);20 const spy = spyOn(testService, 'test').and.callThrough();21 component.test();22 expect(spy).toHaveBeenCalled();23 });24});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Mocking services', () => {2 beforeEach(() => {3 TestBed.configureTestingModule({4 { provide: DataService, useClass: MockDataService },5 });6 });7 it('should get data', () => {8 const service: DataService = TestBed.get(DataService);9 expect(service.getData()).toBe('mock');10 });11});

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Testing ng-mocks provide method', function () {2 beforeEach(function () {3 ngMocks.provide({4 useValue: {5 get: function () {6 return "mock service";7 }8 }9 });10 });11 it('should return mock service', function () {12 var service = ngMocks.inject('myService');13 expect(service.get()).toEqual("mock service");14 });15});16describe('Testing ng-mocks provide method', function () {17 beforeEach(function () {18 ngMocks.provide({19 useValue: {20 get: function () {21 return "mock service";22 }23 }24 });25 });26 it('should return mock service', function () {27 var service = ngMocks.inject('myService');28 expect(service.get()).toEqual("mock service");29 });30});31describe('Testing ng-mocks provide method', function () {32 beforeEach(function () {33 ngMocks.provide({34 useValue: {35 get: function () {36 return "mock service";37 }38 }39 });40 });41 it('should return mock service', function () {42 var service = ngMocks.inject('myService');43 expect(service.get()).toEqual("mock service");44 });45});46describe('Testing ng-mocks provide method', function () {47 beforeEach(function () {

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 ng-mocks 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