Skip to content
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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "Yet another Vue treeview component.",
"author": "Gregg Rapoza <grapoza@gmail.com>",
"license": "MIT",
"version": "1.3.0",
"version": "1.3.1",
"browser": "index.js",
"repository": {
"url": "https://github.com/grapoza/vue-tree",
Expand Down
6 changes: 3 additions & 3 deletions src/components/TreeViewNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
return this.model.children.length > 0 && this.model.expandable;
},
childrenPropName() {
return this.childrenPropNames.find(pn => Array.isArray(this.model[pn]));
return this.childrenPropNames.find(pn => Array.isArray(this.model[pn])) || 'children';
},
customClasses() {
return (this.model.customizations || {}).classes || {};
Expand Down Expand Up @@ -326,8 +326,8 @@
this.$_treeViewNode_assignDefaultProps(this.modelDefaults, this.model);

// Set expected properties if not provided
if (!Array.isArray(this.model.children)) {
this.$set(this.model, 'children', []);
if (!Array.isArray(this.model[this.childrenPropName])) {
this.$set(this.model, this.childrenPropName, []);
}
if (typeof this.model.expandable !== 'boolean') {
this.$set(this.model, 'expandable', true);
Expand Down
40 changes: 29 additions & 11 deletions tests/unit/TreeViewNode.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -719,20 +719,38 @@ describe('TreeViewNode.vue', () => {

describe('when childrenPropNames is specified', () => {

beforeEach(() => {
let defaultProps = getDefaultPropsData();
wrapper = createWrapper(Object.assign(defaultProps, {
childrenPropNames: ['nope', 'children'],
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
}));
});
describe('and a valid-children model property is specified', () => {

beforeEach(() => {
let defaultProps = getDefaultPropsData();
wrapper = createWrapper(Object.assign(defaultProps, {
childrenPropNames: ['nope', 'children'],
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
}));
});

it('has a childrenPropName matching the first-avilable valid-children model property', () => {
expect(wrapper.vm.childrenPropName).to.equal('children');
});

it('has a childrenPropName matching the first-avilable valid-children model property', () => {
expect(wrapper.vm.childrenPropName).to.equal('children');
it('has a children list of the first-avilable model[childrenPropName] property', () => {
expect(wrapper.vm.model.children.length).to.equal(2);
});
});

it('has a children list of the first-avilable model[childrenPropName] property', () => {
expect(wrapper.vm.model.children.length).to.equal(2);
describe('and a valid-children model property is not specified', () => {

beforeEach(() => {
let defaultProps = getDefaultPropsData();
wrapper = createWrapper(Object.assign(defaultProps, {
childrenPropNames: ['nope', 'steve'],
initialModel: generateNodes(['sf', ['s', 's']], defaultProps.radioGroupValues)[0]
}));
});

it('has a childrenPropName of "children"', () => {
expect(wrapper.vm.childrenPropName).to.equal('children');
});
});
});
});