Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #541 #542

Merged
merged 1 commit into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/shared/Initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default {
const initial = this.state.get('current', 'props');
const struct = utils.pathToStruct(path);
// try to get props from separated objects
const $try = prop => _.get(initial[prop], struct);
const $try = prop => initial[prop] && initial[prop][struct];

const props = {
$value: _.get(initial['values'], path),
Expand Down
59 changes: 43 additions & 16 deletions tests/fixes.values.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ describe('$481 Field values checks', () => {
});

describe('separated has correct definition', () => {
it('', () => {
it('', () => {
expect($.$492.$('club.name').value).to.be.equal('')
expect($.$492.$('club.city').value).to.be.equal('')
expect($.$492.values())
Expand All @@ -292,7 +292,7 @@ describe('separated has correct definition', () => {
});

describe('set null value', () => {
it('', () => {
it('', () => {
expect($.$495.$('club.name').value).to.be.equal('JJSC')
expect($.$495.$('club.city').value).to.be.equal('Taipei')
$.$495.$('club').set(null)
Expand All @@ -307,7 +307,7 @@ describe('set null value', () => {
});

describe('falsy fallback', () => {
it('', () => {
it('', () => {
expect($.$505.$('club.name').value).to.be.equal('JJSC')
expect($.$505.$('club.city').value).to.be.equal('Taipei')
expect($.$505.$('club').has('area')).to.be.equal(false)
Expand All @@ -316,21 +316,21 @@ describe('falsy fallback', () => {
});

describe('null date', () => {
it('', () => {
it('', () => {
expect($.$507.$('people.0.birthday').value).to.be.equal(null)
expect($.$507.$('people').add().$('birthday').value).to.be.equal(null)
})
});

describe('update with input', () => {
it('', () => {
it('', () => {
expect($.$514.$('priority').value).to.be.equal(1)
expect($.$514.$('itineraryItems.0.hotel.starRating').value).to.be.equal(5)
})
});

describe('new form with nested array values', () => {
it('', () => {
it('', () => {
const fields = [
'purpose',
'trip.itineraryItems[].hotel.name',
Expand Down Expand Up @@ -363,7 +363,7 @@ describe('new form with nested array values', () => {
});

describe('update to nested array items', () => {
it('', () => {
it('', () => {
const fields = [
'bulletin',
'bulletin.jobs',
Expand Down Expand Up @@ -417,15 +417,15 @@ describe('#523', () => {
name: "nestedB",
label: "nestedB"
}]
}];
}];
const $523 = new Form({fields}, {name: 'Form 523'})
expect($523.isDirty).to.be.false
})
});

describe('update nested nested array items', () => {
it('', () => {
it('', () => {
const fields = [
'pricing',
'pricing.value[]',
Expand All @@ -448,7 +448,7 @@ describe('update nested nested array items', () => {
};
const $526 = new Form({fields, values}, {name: 'Form 526'})
console.debug('pricing.value.0.initial', $526.$('pricing.value.0').initial)
console.debug('pricing.value.0.prices.initial', $526.$('pricing.value.0.prices').initial)
console.debug('pricing.value.0.prices.initial', $526.$('pricing.value.0.prices').initial)
$526.update({
pricing: {
value: [
Expand Down Expand Up @@ -476,7 +476,7 @@ describe('update nested nested array items', () => {
});

describe('falsy fallback for array items', () => {
it('', () => {
it('', () => {
const fields = [
'purpose',
'trip.itineraryItems[].hotel.name',
Expand All @@ -489,16 +489,16 @@ describe('falsy fallback for array items', () => {
itineraryItems: [{
hotel: {
name: 'Shangri-La Hotel',
starRating: '5.0',
favorite: true
starRating: '5.0',
favorite: true
},
}, {
hotel: null,
}, {
hotel: {
name: 'Trump Hotel',
starRating: '5.0',
favorite: false
starRating: '5.0',
favorite: false
},
}]
}
Expand All @@ -511,3 +511,30 @@ describe('falsy fallback for array items', () => {
expect($527.select('trip.itineraryItems.0.hotel.favorite', null, false)).to.be.undefined
})
});

describe('output goes wrong', () => {
it.only('', () => {
const fields = [
'customer',
'customer.name',
'customerid'
];
const labels = {
'customer': 'Customer',
'customer.name': 'name',
};
const output = {
customer: c => c ? c.id : c
};
const values = {
customer: {
id: 'c-001',
name: 'Allen'
}
}

const $541 = new Form({fields, labels, output, values}, {name: 'Form 541', options:{fallback: false}});
expect(typeof $541.$('customer.name').$output).to.be.equal('function')
$541.values();
})
});