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 bug in ArrayInput when the attribute's definition is null #345

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Fix bug on models default folder opening, see [this issue](https://github.com/ditrit/leto-modelizer/issues/303).
* Fix Sonar new bugs/code smell due to quality profil change, see [this issue](https://github.com/ditrit/leto-modelizer/issues/322).
* Fix bug on using default file name from plugin instead of the file name specified by the user, when adding a component after creating a diagram from scratch.
* Fix Array attributes to allow missing definition, see [this issue](https://github.com/ditrit/leto-modelizer/issues/344).

### Removed

Expand Down
2 changes: 1 addition & 1 deletion src/components/inputs/ArrayInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const props = defineProps({
});

const arrayInput = ref(null);
const options = ref(props.attribute.definition.rules.values);
const options = ref(props.attribute.definition?.rules.values || null);
const localValue = ref(props.attribute.value);

watch(() => arrayInput.value, () => {
Expand Down
117 changes: 90 additions & 27 deletions tests/unit/components/inputs/ArrayInput.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,45 +8,108 @@ import { ComponentAttributeDefinition } from 'leto-modelizer-plugin-core';
installQuasarPlugin();

describe('Test component: ArrayInput', () => {
let wrapper;

beforeEach(() => {
wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global: {
stubs: {
qSelect: true,
},
plugins: [
createI18n({
locale: 'en-US',
allowComposition: true,
messages: i18nConfiguration,
}),
],
},
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
});
const global = {
stubs: {
qSelect: true,
},
plugins: [
createI18n({
locale: 'en-US',
allowComposition: true,
messages: i18nConfiguration,
}),
],
};

describe('Test variables initialization', () => {
describe('Test prop: attribute', () => {
it('should be an object containing value', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.attribute.value).toEqual(['test']);
});
});

describe('Test variable: localValue', () => {
it('should match attribute.value', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.localValue).toEqual(['test']);
});
});

describe('Test variable: options', () => {
it('should not be null when the attribute has a definition and rules with values', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition({
rules: {
values: ['value1', 'value2', 'value3'],
},
}),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toEqual(['value1', 'value2', 'value3']);
});

it('should be null when the attribute has a definition with no rules', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: new ComponentAttributeDefinition(),
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toBeNull();
});

it('should be null and not raise an error when the attribute has no definition', () => {
const wrapper = shallowMount(ArrayInput, {
props: {
attribute: {
value: ['test'],
definition: null,
},
},
global,
});
wrapper.vm.arrayInput = {
validate: jest.fn(() => Promise.resolve(true)),
};
expect(wrapper.vm.options).toBeNull();
});
});
});
});